Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use python to forecast sales volume

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces "how to use python to forecast sales volume". In daily operation, I believe many people have doubts about how to use python to forecast sales volume. The editor consulted all kinds of data and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "how to use python to forecast sales volume". Next, please follow the editor to study!

Case review

Sales of rice balls decline

One-year historical sales data of existing ice cream shops

The data include daily sales, temperature and what day of the week (question: how do you use these data to predict ice cream sales? )

Simulation experiment and analysis

Store the data in csv format and import it into python. And draw a scatter chart to observe the relationship between temperature and sales volume.

Import pandas as pd

Icecream = pd.read_csv ("icecream.csv")

Import matplotlib.pyplot as plt

Import pylab

Plt.rcParams ['font.sans-serif'] = [' SimHei']

Plt.scatter (icecream.iloc [:, 1], icecream.iloc [:, 0])

Plt.xlabel ("temperature")

Plt.ylabel ("sales volume")

Pylab.show ()

The correlation coefficient between them was calculated.

Icecream.iloc [:, 0:2] .corr ()

The result is:

Sales volume, temperature, sales volume 1.0000000.844211, temperature 0.8442111.000000

The correlation coefficient between sales volume and air temperature is 0.84. Combined with the scatter plot, it is considered that there is a correlation between them. The following is to use the method of regression analysis to predict ice cream sales by temperature.

From sklearn.linear_model import LinearRegression

Model = LinearRegression ()

Feature_cols = ['temperature']

X = icecream [feature _ cols]

Y = icecream. Sales volume

Model.fit (XBI y)

Plt.scatter (icecream. Temperature, icecream. Sales)

Plt.plot (icecream. Temperature, model.predict (X), color='blue')

Plt.xlabel ('temperature')

Plt.ylabel ('sales volume')

Plt.show ()

Print ("intercept and slope:", model.intercept_,model.coef_)

Intercept and slope: 57.1673282152 [5.21607823]

Therefore, the line function in the scatter graph is y=5.2X+57.2. Therefore, when the temperature is 25 degrees, the projected sales are 5.2-25-57.2-187.52, about 188.

A few small concepts

Regression analysis: a simple way to predict data. In this case, the sales volume is the response variable, also known as the dependent variable, and the temperature is the explanatory variable, also known as the independent variable. Although there are many factors that affect sales besides temperature, we need to simplify and formulate the reality in regression analysis, a process called modeling. In this case, modeling with only one explanatory variable is called univariate linear regression, and if the response variable is affected by multiple explanatory variables at the same time, it is called multivariate linear regression.

At this point, the study on "how to use python to forecast sales volume" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report