第五届工业互联网大数据:配件需求29th方案与代码

背景

大数据可能过时了,所以这个延续5年的比赛也换了名字,但我还是习惯叫工业大数据。之前文章介绍过,我做了风力预测赛道但排不进排行榜。这里介绍一下队友在配件预测赛道的方案,方案很简单,不到50行代码,取得决赛29th的成绩。其实,我也做了一点,入手了一个LGB模型,但是效果一直没有超过全0,尴尬的放弃了。
任务是预测未来三个月的配件需求,评价指标类似MAPE,所以准确预测小目标才是关键。
代码地址:https://github.com/hongyingyue/Data-science-demos
方案

##第1个月

第1个月使用VAR模型。由于零件中有很多的销量非常稀疏,增加一个后处理,将48个月均销量小于1的零件销量直接调整为0。

import pandas as pd
import numpy as np

from statsmodels.tsa.vector_ar.var_model import VAR
from sklearn.linear_model import LinearRegression
from statsmodels.tsa.deterministic import DeterministicProcess

# VAR
v_model = VAR(ts_df)
v_model_fit = v_model.fit(3)
lag_order = v_model_fit.k_ar

# forecast for the 1st month
y_fore1 = v_model_fit.forecast(ts_df.values[-lag_order:], 1)
y_fore1[y_fore1 < 0] = 0

第2/3个月

第2-3月使用线性回归模型,这里的特征是超出我预料的。只使用了月份还有月份的平方作为特征,直接用线性模型预测结果。

# LR model
y = ts_df.copy()

# Create trend features
dp = DeterministicProcess(
    index=y.index,  # dates from the training data
    constant=True,  # the intercept
    order=2,        # quadratic trend
    drop=True,      # drop terms to avoid collinearity
)
X = dp.in_sample()  # features for the training data
X_fore = dp.out_of_sample(steps=3)

X['mon']=X.index.month
X_fore.set_index([pd.to_datetime(['2020-7-1','2020-8-1','2020-9-1'])],inplace=True)
X_fore['mon']=X_fore.index.month

# Fit trend model
model = LinearRegression(fit_intercept=False)
model.fit(X, y)

y_fore_l = pd.DataFrame(
    model.predict(X_fore),
    index=X_fore.index,
    columns=y.columns,
)
y_fore_l[y_fore_l<0] = 0

以上就是吊打我方案的全部代码了,非常简单高效。数据量比较小,评价指标不是很合理,就要根据数据和指标多做些针对性的调整了,希望下一届能取的好成绩。
我是YueTan,谢谢关注。

Guess you like

Origin blog.csdn.net/weixin_38812492/article/details/121880148