简体   繁体   English

使用 Python 预测销售数据

[英]Predicting Sales Data with Python

I have a data set I have made with random numbers containing the sales data for each sales representative for all previous months and I want to know if there is a way to predict what the sales would look like for each representative for the upcoming month.我有一个随机数组成的数据集,其中包含每个销售代表前几个月的销售数据,我想知道是否有办法预测每个代表下个月的销售情况。 I'm not sure if machine learning methods are something that can be used here.我不确定机器学习方法是否可以在这里使用。

I am mostly asking for the best way to solve this, not necessary a code but maybe a method that is best for these types of questions.我主要是在寻求解决这个问题的最佳方法,不需要代码,但也许是最适合这类问题的方法。 This is something I am interested in and would like to apply to a bigger data sets in the future.这是我感兴趣的东西,并希望将来应用于更大的数据集。

data = [[1 , 55, 12, 25, 42, 66, 89, 75, 32, 43, 15, 32, 45], 
        [2 , 35, 28, 43, 25, 54, 76, 92, 34, 12, 14, 35, 63],
        [3 ,13, 31, 15, 75, 4, 14, 54, 23, 15, 72, 12, 51],
        [4 ,42, 94, 22, 34, 32, 45, 31, 34, 65, 10, 15, 18],
        [5 ,7, 51, 29, 14, 92, 28, 64, 100, 69, 89, 4, 95],
        [6 , 34, 20, 59, 49, 94, 92, 45, 91, 28, 22, 43, 30],
        [7 , 50, 4, 5, 45, 62, 71, 87, 8, 74, 30, 3, 46],
        [8 , 12, 54, 35, 25, 52, 97, 67, 56, 62, 99, 83, 9],
        [9 , 50, 75, 92, 57, 45, 91, 83, 13, 31, 89, 33, 58],
        [10 , 5, 89, 90, 14, 72, 99, 51, 29, 91, 34, 25, 2]]

df = pd.DataFrame (data, columns = ['sales representative ID#',
        'January Sales Quantity',
        'Fabruary Sales Quantity',
        'March Sales Quantity',
        'April Sales Quantity',
        'May Sales Quantity' ,
        'June Sales Quantity',
        'July Sales Quantity',
        'August Sales Quantity',
        'September Sales Quantity',
        'October Sales Quantity',
        'November Sales Quantity',
        'December Sales Quantity'])

Your case with multiple sales representatives is more complex, because since they are responsible for the same product, there may be a complex correlation between their performance, besides seasonality, autocorrelation, etc. Your data is not even a pure time series — it rather belongs to the class of so called "panel" datasets.您的多个销售代表的情况更复杂,因为由于他们负责相同的产品,除了季节性、自相关等之外,他们的绩效之间可能存在复杂的相关性。您的数据甚至不是纯时间序列——而是属于到所谓的“面板”数据集的 class。 I've recently written a Python micro-package salesplansuccess , which deals with prediction of the current (or next) year's annual sales from historic monthly sales data.我最近写了一个salesplansuccess微包销售计划成功 ,它处理从历史月度销售数据预测当前(或明年)的年销售额。 But a major assumption for that model is a quarterly seasonality (more specifically a repeating drift from the 2nd to the 3rd month in each quarter), which is more characteristic for wholesalers.但是,model 的一个主要假设是季度季节性(更具体地说,是每个季度从第 2 个月到第 3 个月的重复漂移),这对于批发商来说更具特征。 The package is installed as usual with pip install salesplansuccess . package 照常pip install salesplansuccess You can modify its source code for it to better fit your needs.您可以修改其源代码以更好地满足您的需求。 The minimalistic use case is below:简约的用例如下:

import pandas as pd
from salesplansuccess.api import SalesPlanSuccess
myHistoricalData = pd.read_excel('myfile.xlsx')
myAnnualPlan = 1000
sps = SalesPlanSuccess(data=myHistoricalData, plan=myAnnualPlan)
sps.fit()
sps.simulate()
sps.plot()

For more detailed illustration of its use, you may want to refer to a Jupyter Notebook illustration file at its GitHub repository .有关其使用的更详细说明,您可能需要参考其 GitHub存储库中的 Jupyter Notebook 插图文件

Choose method of prediction and iterate over reps calculating their parameters.选择预测方法并迭代计算其参数的代表。 Here you have simple linear regression in python you can use.在这里,您可以使用 python 中的简单线性回归 With time you can add something smarter.随着时间的推移,您可以添加一些更智能的东西。

#!/usr/bin/python

data = [[1 , 55, 12, 25, 42, 66, 89, 75, 32, 43, 15, 32, 45], 
        (...)

months = []
for m in range(len(data[0])):
    months.append(m+1)

for rep in range(len(data)):
        linear_regression(months, data[rep])

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM