|
|
@ -50,12 +50,11 @@ data = data.loc[normal(data['售电量']).index]
|
|
|
|
data['season'] = data.index.map(season)
|
|
|
|
data['season'] = data.index.map(season)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# df_train = df[500:850]
|
|
|
|
df_train = data[500:850]
|
|
|
|
|
|
|
|
|
|
|
|
df_train = data.loc['2021-01':'2023-08']
|
|
|
|
# df_train = data.loc['2021-01':'2023-08']
|
|
|
|
df_eval = data.loc['2023-9']
|
|
|
|
df_eval = data.loc['2023-9']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
X = df_train[['tem_max','tem_min','24ST','holiday','season']]
|
|
|
|
X = df_train[['tem_max','tem_min','24ST','holiday','season']]
|
|
|
|
X_eval = df_eval[['tem_max','tem_min','24ST','holiday','season']]
|
|
|
|
X_eval = df_eval[['tem_max','tem_min','24ST','holiday','season']]
|
|
|
|
y = df_train['售电量']
|
|
|
|
y = df_train['售电量']
|
|
|
@ -64,10 +63,9 @@ y = df_train['售电量']
|
|
|
|
# best_i = {}
|
|
|
|
# best_i = {}
|
|
|
|
# for i in range(400):
|
|
|
|
# for i in range(400):
|
|
|
|
|
|
|
|
|
|
|
|
x_train,x_test,y_train,y_test = train_test_split(X,y,test_size=0.2,random_state=142)
|
|
|
|
x_train,x_test,y_train,y_test = train_test_split(X,y,test_size=0.2,random_state=42)
|
|
|
|
model = xgb.XGBRegressor(max_depth=6, learning_rate=0.05, n_estimators=150)
|
|
|
|
model = xgb.XGBRegressor(max_depth=6, learning_rate=0.05, n_estimators=150)
|
|
|
|
model.fit(x_train,y_train)
|
|
|
|
model.fit(x_train,y_train)
|
|
|
|
|
|
|
|
|
|
|
|
y_pred = model.predict(x_test)
|
|
|
|
y_pred = model.predict(x_test)
|
|
|
|
result_test = pd.DataFrame({'test':y_test,'pred':y_pred},index=y_test.index)
|
|
|
|
result_test = pd.DataFrame({'test':y_test,'pred':y_pred},index=y_test.index)
|
|
|
|
|
|
|
|
|
|
|
@ -98,7 +96,7 @@ print('r2:',r2_score(y_test,y_pred))
|
|
|
|
# # with open(r'C:\Users\user\Desktop\9月各地市日电量预测结果\偏差率.txt','a',encoding='utf-8') as f:
|
|
|
|
# # with open(r'C:\Users\user\Desktop\9月各地市日电量预测结果\偏差率.txt','a',encoding='utf-8') as f:
|
|
|
|
# # f.write(f'杭州月末3天偏差率:{round(goal,5)},9号-月底偏差率:{round(goal2,5)}\n')
|
|
|
|
# # f.write(f'杭州月末3天偏差率:{round(goal,5)},9号-月底偏差率:{round(goal2,5)}\n')
|
|
|
|
# 保存模型
|
|
|
|
# 保存模型
|
|
|
|
model.save_model('hangzhou.bin')
|
|
|
|
# model.save_model('hangzhou.bin')
|
|
|
|
|
|
|
|
|
|
|
|
# X_eval = df_eval[['tem_max','tem_min','24ST','holiday','season']]
|
|
|
|
# X_eval = df_eval[['tem_max','tem_min','24ST','holiday','season']]
|
|
|
|
# df_eval = pd.read_excel(r'C:\Users\user\Desktop\浙江气象1027.xlsx')
|
|
|
|
# df_eval = pd.read_excel(r'C:\Users\user\Desktop\浙江气象1027.xlsx')
|
|
|
@ -108,8 +106,6 @@ model.save_model('hangzhou.bin')
|
|
|
|
# df_hangzhou = df_eval[df_eval['city_name']=='金华市'].sort_values(by='dtdate')
|
|
|
|
# df_hangzhou = df_eval[df_eval['city_name']=='金华市'].sort_values(by='dtdate')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
loaded_model = xgb.XGBRegressor()
|
|
|
|
loaded_model = xgb.XGBRegressor()
|
|
|
|
loaded_model.load_model('hangzhou.bin')
|
|
|
|
loaded_model.load_model('hangzhou.bin')
|
|
|
|
X_eval = np.array([[24.19,15.30,23,1,0],
|
|
|
|
X_eval = np.array([[24.19,15.30,23,1,0],
|
|
|
|