时序模型方案(ARIMA)
精度分析,以及结果
模型预测+精度分析(大家自己调整参数,order=(1 ,1,1))
from statsmodels.tsa.arima_model import ARIMA
# Fit model
model = ARIMA(y_train, order=(1 ,1,1))
model_fit = model.fit()
# Prediction with ARIMA
y_pred, se, conf = model_fit.forecast(len(y_valid))
# Calcuate metrics
score_mae = mean_absolute_error(y_valid, y_pred)
score_rmse = math.sqrt(mean_squared_error(y_valid, y_pred))
import numpy as np
from sklearn import metrics
def mape(y_true, y_pred):
return np.mean(np.abs((y_pred - y_true) / y_true))
y_true = np.array(y_valid)
y_pred = np.array(y_pred)
print('MSE:',metrics.mean_squared_error(y_true, y_pred))
print('RMSE:',np.sqrt(metrics.mean_squared_error(y_true, y_pred)))
print('MAE:',metrics.mean_absolute_error(y_true, y_pred))
print('MAPE:',mape(y_true, y_pred))
MAPE: 0.11979481880734648
机器学习模型(LGB,CAT)
CAT模型训练(参数自己调整)
X_train = x_train[:-400]
Y = y[:-400]
val_train = x_train[-400:]
val_Y = y[-400:]
catboost_model = CatBoostRegressor(
iterations=1000, learning_rate=0.01, depth=5,verbose = False
)
catboost_model2=catboost_model.fit(X_train,Y,verbose = False)
pred_val = catboost_model2.predict(val_train)
LGB
model_lgb = lgb.LGBMRegressor(
learning_rate=0.05,
max_depth=-1,
n_estimators=700,
boosting_type='gbdt',
random_state=2021,
objective='regression',
num_leaves = '257',
verbose=-1)
lgb_model = model_lgb.fit(X_train,Y)
pred_val_y = lgb_model.predict(val_train)
model_lgb = lgb.LGBMRegressor(
learning_rate=0.05,
max_depth=-1,
n_estimators=700,
boosting_type='gbdt',
random_state=2021,
objective='regression',
num_leaves = '257',
verbose=-1)
lgb_model = model_lgb.fit(X_train,Y)
pred_val_y = lgb_model.predict(val_train)
# coding=utf-8
import numpy as np
from sklearn import metrics
# MAPE需要自己实现
def mape(y_true, y_pred):
return np.mean(np.abs((y_pred - y_true) / y_true))
y_true = np.array(pred_val_y)
y_pred = np.array(val_Y)
print('MSE:',metrics.mean_squared_error(y_true, y_pred))
print('RMSE:',np.sqrt(metrics.mean_squared_error(y_true, y_pred)))
print('MAE:',metrics.mean_absolute_error(y_true, y_pred))
神经网络模型(LSTM)
略