[PYTHON] Data analysis planning collection processing and judgment (Part 1)

So far, I have written about practical methods of statistics, but if you acquire statistics and econometrics, can you predict the future one after another by data analysis and make a lot of money by investing in stocks and the like? No, then statisticians and economists should be devoted to investing in research and getting rich by this time.

Random Walker on Wall Street says that many professional fund managers have not beaten the investment method of buying the entire listed stock at random. Scientific empirical data is written. The unpredictability of the future is very difficult to predict because of the complex mix of factors.

For example, medical statistics can be used to find out the correlation between a certain nutrition or lifestyle and a certain disease. So does this allow you to accurately predict when you will die of illness? Of course not. Data analysis cannot accurately predict when you will die.

That is, causal insights are very important.

For example, if you are a person in charge of purchasing and sales, what are the points of products that are likely to lead to sales, if you are a sales person, what are the decisive factors that lead to contracts, and if you are a human resource, to develop human resources that will lead to your company's profits What is the key, it is important to clarify these points from the analysis of data.

And it is not a superman who calls himself a data scientist or a person like a witch who appears dashingly and solves the problem and leaves, but it is a problem due to steady daily efforts and some statistical analysis on the front line. It is a clue to discover and solve.

For example, when it becomes clear that a particular product is selling at a certain time of the season, computer analysis can only conclude that we should purchase more of that product. However, if you are a person who has been involved in stores and products, the "something" behind it, for example, the customer must actually be looking for ~ ~, and so on. Ultimately, human insight and judgment are needed, which is very important.

Data analysis target and analysis plan

This time, let's take a case as an example and consider the flow of actually analyzing data and making use of it.

I made a gacha emulator with Flask in previously, but this time the subject is also a social game. Social games are familiar and convenient as materials because they can be accessed by everyone and can actually collect real data.

Of course, it doesn't matter if it's actually store sales, salesperson performance, or social network statements.

The outline is as follows.

The procedure for analysis is as follows.

  1. Clarify the purpose
  2. Collect data
  3. Organize and process data
  4. Grasp trends
  5. Use as a basis for judgment

Clarify the purpose

Why do you analyze this event? Before we can analyze the data, we first need to clarify the purpose.

Ranking is an effective way to fuel billing in social games. For example, let's say you have 10,000 more points to get the desired reward. You only need to pay 1,000 yen for 10 items. Therefore, we charge 1,000 yen, but rivals naturally think in the same way and charge 1,000 yen. This will increase the border score, so the ranking will not increase after all.

It's supposed to be a little more, a little more, but it is a mechanism that you will be charged a large amount of money by repeating it.

This kind of incites gambling spirit that makes you want to charge jerky Event charge Border of the ranking that will eventually land in order to avoid the bottomless swamp Predict your score to some extent and invest as much money as you need to earn the final score, regardless of your current ranking. The purpose of this analysis is to estimate this score as accurately as possible.

Collect data

In any case, we have to collect data, but in data analysis, this collection process is often a heavy burden.

Here is some sample data.

1.png

This is data that collects only the final score of the event for about half a year, that is, from July last year to January this year.

The border score fluctuates a little every month, but basically the top reward = 100th place = rank A, the top reward = 700 to 800th place = rank G, and the bottom reward = 2000 to 2200th place = rank O. The table is separated by a black line. The rank is for convenience, which is assigned as A, B, C from the top of the ranking at the author's discretion. Since the order of dividing borders is different every month, think of it as the rank from the top.

In addition, the month-on-month rate is a ratio that indicates how much the score that became the border that divides the ranking has increased from the previous month. This can be calculated by dividing the current month by the previous month.

Organize and process data

Even just collecting data in this way is quite a burden. However, some collection processes can be automated.

However, there is still a need for a process to organize the data, even after it has been collected in a database, for example through sensors or automated tools. Since this is a phase of processing by human hands, it cannot be fully automated.

First, visualize and see the overall trend. For the time being, visualizing data is a basic process in the basics. As for the method, this is the basis of pandas, so I don't think it needs to be explained anymore.

df = pd.read_csv("data.csv", index_col=0) #Read the data
lines = df.interpolate(method="linear") #Fill in the missing data
plt.figure()
lines.plot() #Plot the line chart

image.png

The X-axis is the border of the ranking, so the higher it goes to the left. The Y axis is the score. Each line represents the month, but as you can see at a glance from the original data, the required score is increasing every month. Inflation, especially in the most recent January and November, is amazing.

As people spend more and more money and become stronger, naturally the scores they earn will also inflate more and more every month. I think this kind of phenomenon can be seen in most social games. The phenomenon has been visualized again.

In the above example, the missing values were linearly interpolated. pandas.DataFrame.interpolate allows you to interpolate and fill in missing values on a variety of criteria. It's one of the powerful features of pandas.

Continue to the second part.

Recommended Posts

Data analysis planning collection processing and judgment (Part 1)
Data analysis planning collection processing and judgment (Part 2)
Data analysis parts collection
Organizing basic procedures for data analysis and statistical processing (4)
Organizing basic procedures for data analysis and statistical processing (2)
Wrap analysis part1 (data preparation)
Japanese analysis processing using Janome part1
Multidimensional data analysis library xarray Part 2
Try processing images and webcams Part 3 ~ Mosaic processing ~
Starbucks Twitter Data Location Visualization and Analysis
Beautiful graph drawing with python -seaborn makes data analysis and visualization easier Part 1
Practice of creating a data analysis platform with BigQuery and Cloud DataFlow (data processing)
Exam Mathematics Part 1 (Question setting and data generation)
Recipe collection comparing versions 1 and 2 of TensorFlow (Part 1)
Get a large amount of Starbucks Twitter data with python and try data analysis Part 1
Data analysis Titanic 2
Data analysis python
Data analysis Titanic 1
Data analysis Titanic 3
Analysis of financial data by pandas and its visualization (2)
Full-width and half-width processing of CSV data in Python
Analysis of financial data by pandas and its visualization (1)
Story of image analysis of PDF file and data extraction
Analysis of measurement data ②-Histogram and fitting, lmfit recommendation-
Data processing methods for mechanical engineers and non-computer engineers (Introduction 2)
Overview of natural language processing and its data preprocessing
Data processing methods for mechanical engineers and non-computer engineers (Introduction 1)
Easy analysis and sharing with re: dash, an open source data visualization tool Part 1-Installation