模型调整

main
鸽子 1 year ago
parent 4a24ea47fe
commit 08f1129750

@ -45,16 +45,12 @@ data = data.loc[normal(data['售电量']).index]
data['season'] = data.index.map(season)
print(data.head())
df_eval = data.loc['2023-9']
# df_train = data.loc['2021-1':'2023-8']
df_train = data[500:850]
print(len(df_eval),len(df_train),len(data))
df_train = df_train[['tem_max','tem_min','holiday','24ST','售电量','season']]
df_train = data[450:900]
df_train = df_train[['tem_max','tem_min','holiday','24ST','售电量','season']]
X = df_train[['tem_max','tem_min','holiday','24ST','season']]
X_eval = df_eval[['tem_max','tem_min','holiday','24ST','season']]
@ -63,11 +59,9 @@ y = df_train['售电量']
# best_i = {}
# for i in range(200):
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.fit(x_train,y_train)
y_pred = model.predict(x_test)
result_test = pd.DataFrame({'test':y_test,'pred':y_pred},index=y_test.index)
@ -91,7 +85,7 @@ print(goal2)
# with open(r'C:\Users\user\Desktop\9月各地市日电量预测结果\偏差率.txt','a',encoding='utf-8') as f:
# f.write(f'丽水月末3天偏差率{goal},9号-月底偏差率:{goal2}')
# # 保存模型
model.save_model('lishui.bin')
# model.save_model('lishui.bin')
import numpy as np
loaded_model = xgb.XGBRegressor()
loaded_model.load_model('lishui.bin')

@ -26,18 +26,18 @@ data = pd.read_excel(os.path.join(parent_dir,'入模数据/台州.xlsx'),index_c
data.index = pd.to_datetime(data.index,format='%Y-%m-%d')
data = data.loc[normal(data['售电量']).index]
list2 = []
list0 = []
list1 = []
for i in ('01','02','03','04','05','06','07','08','09','10','11','12'):
month_index = data.index.strftime('%Y-%m-%d').str[5:7] == f'{i}'
if data.loc[month_index]['售电量'].mean() >= data['售电量'].describe()['75%']:
list2.append(i)
elif data.loc[month_index]['售电量'].mean() <= data['售电量'].describe()['25%']:
list0.append(i)
else:
list1.append(i)
print(list0,list1,list2)
# list2 = []
# list0 = []
# list1 = []
# for i in ('01','02','03','04','05','06','07','08','09','10','11','12'):
# month_index = data.index.strftime('%Y-%m-%d').str[5:7] == f'{i}'
# if data.loc[month_index]['售电量'].mean() >= data['售电量'].describe()['75%']:
# list2.append(i)
# elif data.loc[month_index]['售电量'].mean() <= data['售电量'].describe()['25%']:
# list0.append(i)
# else:
# list1.append(i)
# print(list0,list1,list2)
data['season'] = data.index.map(season)
@ -50,11 +50,11 @@ df_train = df_train[['tem_max','tem_min','holiday','24ST','售电量','season']]
X = df_train[['tem_max','tem_min','holiday','24ST','season']]
X_eval = df_eval[['tem_max','tem_min','holiday','24ST','season']]
y = df_train['售电量']
best_goal = 1
best_i = {}
# best_goal = 1
# best_i = {}
# for i in range(400):
x_train,x_test,y_train,y_test = train_test_split(X,y,test_size=0.2,random_state=163)
x_train,x_test,y_train,y_test = train_test_split(X,y,test_size=0.2,random_state=158)
model = xgb.XGBRegressor(max_depth=6, learning_rate=0.05, n_estimators=150)
model.fit(x_train,y_train)
@ -78,7 +78,7 @@ print(goal2)
# print(best_i,best_goal)
# 保存模型
model.save_model('taizhou.bin')
# model.save_model('taizhou.bin')
import numpy as np
loaded_model = xgb.XGBRegressor()
loaded_model.load_model('taizhou.bin')

@ -42,9 +42,8 @@ data = data.loc[normal(data['售电量']).index]
data['season'] = data.index.map(season)
df_eval = data.loc['2023-08']
df_train = data.iloc[500:850]
df_train = data.iloc[450:900]
# df_train = data.loc['2021-01':'2023-07']
print(len(df_eval),len(df_train),len(data))
@ -59,7 +58,7 @@ y = df_train['售电量']
# best_i = {}
# for i in range(400):
x_train,x_test,y_train,y_test = train_test_split(X,y,test_size=0.1,random_state=42)
x_train,x_test,y_train,y_test = train_test_split(X,y,test_size=0.1,random_state=158)
model = xgb.XGBRegressor(max_depth=6, learning_rate=0.05, n_estimators=150)
model.fit(x_train,y_train)
@ -84,7 +83,7 @@ print(result_eval)
# print(best_i,best_goal,x)
# 保存模型
model.save_model('jiaxing.bin')
# model.save_model('jiaxing.bin')
loaded_model = xgb.XGBRegressor()
loaded_model.load_model('jiaxing.bin')
import numpy as np

@ -41,9 +41,9 @@ data = data.loc[normal(data['售电量']).index]
data['season'] = data.index.map(season)
df_eval = data.loc['2023-09']
df_train = data.loc['2021-01':'2023-08']
# df_train = data[400:850]
print(len(df_eval),len(df_train))
# df_train = data.loc['2021-01':'2023-08']
df_train = data[450:900]
df_train = df_train[['tem_max','tem_min','holiday','24ST','售电量','season']]
@ -55,7 +55,7 @@ y = df_train['售电量']
# best_i = {}
# for i in range(400):
x_train,x_test,y_train,y_test = train_test_split(X,y,test_size=0.1,random_state=18)
x_train,x_test,y_train,y_test = train_test_split(X,y,test_size=0.1,random_state=142)
model = xgb.XGBRegressor(max_depth=6, learning_rate=0.05, n_estimators=150)
model.fit(x_train,y_train)
y_pred = model.predict(x_test)
@ -80,7 +80,7 @@ print(goal2)
# print(best_i,best_goal,x)
# 保存模型
model.save_model('ningbo.bin')
# model.save_model('ningbo.bin')
import numpy as np
loaded_model = xgb.XGBRegressor()
loaded_model.load_model('ningbo.bin')

@ -50,12 +50,11 @@ data = data.loc[normal(data['售电量']).index]
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']
X = df_train[['tem_max','tem_min','24ST','holiday','season']]
X_eval = df_eval[['tem_max','tem_min','24ST','holiday','season']]
y = df_train['售电量']
@ -64,10 +63,9 @@ y = df_train['售电量']
# best_i = {}
# 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.fit(x_train,y_train)
y_pred = model.predict(x_test)
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:
# # 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']]
# 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')
loaded_model = xgb.XGBRegressor()
loaded_model.load_model('hangzhou.bin')
X_eval = np.array([[24.19,15.30,23,1,0],

@ -44,8 +44,8 @@ data['season'] = data.index.map(season)
df_eval = data.loc['2023-9']
# df_train = df[(df.index.str[:7]!='2023-08')&(df.index.str[:7]!='2023-09')]
df_train = data[400:850]
# df_train = data.loc['2021-1':'2023-8']
df_train = data[450:900]
df_train = df_train[['tem_max','tem_min','holiday','24ST','售电量','season']]
@ -84,7 +84,7 @@ print(goal2)
# x = goal2
# print(best_i,best_goal,x)
# 保存模型
model.save_model('wenzhou.bin')
# model.save_model('wenzhou.bin')
loaded_model = xgb.XGBRegressor()

@ -45,7 +45,8 @@ data = data.loc[normal(data['售电量']).index]
data['season'] = data.index.map(season)
df_eval = data.loc['2023-9']
df_train = data.loc['2021-1':'2023-8']
# df_train = data.loc['2022-6':'2023-8']
df_train = data[450:900]
df_train = df_train[['tem_max','tem_min','holiday','24ST','售电量','season']]
@ -53,7 +54,7 @@ X = df_train[['tem_max','tem_min','holiday','24ST','season']]
X_eval = df_eval[['tem_max','tem_min','holiday','24ST','season']]
y = df_train['售电量']
x_train,x_test,y_train,y_test = train_test_split(X,y,test_size=0.1,random_state=42)
x_train,x_test,y_train,y_test = train_test_split(X,y,test_size=0.1,random_state=158)
model = xgb.XGBRegressor(max_depth=6, learning_rate=0.05, n_estimators=150)
model.fit(x_train,y_train)
@ -73,7 +74,7 @@ goal2 = (result_eval['eval'][-23:].sum()-result_eval['pred'][-23:].sum())/result
print(goal2)
# 保存模型
model.save_model('huzhou.bin')
# model.save_model('huzhou.bin')
loaded_model = xgb.XGBRegressor()
loaded_model.load_model('huzhou.bin')
import numpy as np

@ -43,8 +43,8 @@ data = data.loc[normal(data['售电量']).index]
data['season'] = data.index.map(season)
df_eval = data.loc['2023-9']
df_train = data.loc['2021-1':'2023-8']
# df_train = df[400:850]
# df_train = data.loc['2021-1':'2023-8']
df_train = data[450:900]
print(len(df_eval),len(df_train),len(data))
@ -86,7 +86,7 @@ print(goal2)
# print(best_i,best_goal,x)
# 保存模型
model.save_model('shaoxing.bin')
# model.save_model('shaoxing.bin')
loaded_model = xgb.XGBRegressor()
loaded_model.load_model('shaoxing.bin')
import numpy as np

@ -43,7 +43,7 @@ data = data.loc[normal(data['售电量']).index]
data['season'] = data.index.map(season)
df_eval = data.loc['2023-9']
# df_train = data.loc['2021-1':'2023-8']
df_train = data.iloc[500:850]
df_train = data.iloc[450:900]
df_train = df_train[['tem_max','tem_min','holiday','24ST','售电量','season']]
X = df_train[['tem_max','tem_min','holiday','24ST','season']]
@ -72,7 +72,7 @@ goal2 = (result_eval['eval'][-23:].sum()-result_eval['pred'][-23:].sum())/result
print(goal2)
model.save_model('zhoushan.bin')
# model.save_model('zhoushan.bin')
loaded_model = xgb.XGBRegressor()
loaded_model.load_model('zhoushan.bin')
import numpy as np

@ -68,7 +68,7 @@ goal2 = (result_eval['eval'][-23:].sum()-result_eval['pred'][-23:].sum())/result
print(goal2)
# 保存模型
model.save_model('quzhou.bin')
# model.save_model('quzhou.bin')
loaded_model = xgb.XGBRegressor()
loaded_model.load_model('quzhou.bin')
import numpy as np

@ -56,7 +56,7 @@ y = df_train['售电量']
# best_i = {}
# for i in range(400):
x_train,x_test,y_train,y_test = train_test_split(X,y,test_size=0.1,random_state=42)
x_train,x_test,y_train,y_test = train_test_split(X,y,test_size=0.1,random_state=100)
model = xgb.XGBRegressor(max_depth=6, learning_rate=0.05, n_estimators=150)
model.fit(x_train,y_train)
@ -80,7 +80,7 @@ print(goal2)
# x = goal2
# # 保存模型
model.save_model('jinhua.bin')
# model.save_model('jinhua.bin')
loaded_model = xgb.XGBRegressor()
loaded_model.load_model('jinhua.bin')
import numpy as np

Loading…
Cancel
Save