输出预测结果

main
鸽子 1 year ago
parent 709ee960a5
commit b6beaf3554

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

@ -47,7 +47,7 @@ data = data.loc[normal(data['售电量']).index]
data['season'] = data.index.map(season) data['season'] = data.index.map(season)
df_eval = data.loc['2023-10'] df_eval = data.loc['2023-11']
# df_train = data.loc['2021-1':'2023-8'] # df_train = data.loc['2021-1':'2023-8']
df_train = data[450:-1] df_train = data[450:-1]
# df_train = data.loc['2022-4':'2023-9'][:-3] # df_train = data.loc['2022-4':'2023-9'][:-3]
@ -71,7 +71,7 @@ print(abs(y_test - y_pred).mean() / y_test.mean())
eval_pred = model.predict(X_eval) eval_pred = model.predict(X_eval)
result_eval = pd.DataFrame({'eval': df_eval['售电量'], 'pred': eval_pred}, index=df_eval['售电量'].index) result_eval = pd.DataFrame({'eval': df_eval['售电量'], 'pred': eval_pred}, index=df_eval['售电量'].index)
print(result_eval) print(result_eval['eval'])
goal = (result_eval['eval'][-3:].sum() - result_eval['pred'][-3:].sum()) / result_eval['eval'].sum() goal = (result_eval['eval'][-3:].sum() - result_eval['pred'][-3:].sum()) / result_eval['eval'].sum()
print(goal) print(goal)
@ -85,10 +85,14 @@ print(goal2)
import numpy as np import numpy as np
X_eval = np.array([ X_eval = np.array([
[21,10,10,0,0], [17.2, 5.7, 10, 0, 0],
[21, 11, 10, 0, 0], [21.2, 4.3, 10, 0, 0],
[20, 8, 10, 0, 0], [11.5, 6.6, 10, 0, 0]
[20, 8, 10, 0, 0],
[17, 10, 10, 0, 0]
]) ])
print(model.predict(X_eval)) print(model.predict(X_eval))
result = model.predict(X_eval)
result = pd.DataFrame(result,index=['2023-11-28','2023-11-29','2023-11-30'])
result = pd.concat((result_eval['eval'],result))
result.index = result.index.map(lambda x:str(x)[:10])
print(result)

@ -41,7 +41,7 @@ data = data.loc[normal(data['售电量']).index]
data['season'] = data.index.map(season) data['season'] = data.index.map(season)
# data = data.loc[:'2023-9'] # data = data.loc[:'2023-9']
df_eval = data.loc['2023-10'] df_eval = data.loc['2023-11']
df_train = data[500:-1] df_train = data[500:-1]
# df_train = data[500:][:-3] # df_train = data[500:][:-3]
@ -85,10 +85,13 @@ model.save_model('taizhou.bin')
import numpy as np import numpy as np
X_eval = np.array([ X_eval = np.array([
[19,11,10,1,0], [18.8, 6.2, 10, 0, 0],
[21, 7, 10, 0, 0], [21.7, 6.5, 10, 0, 0],
[19, 5, 10, 0, 0], [14.3, 8.4, 10, 0, 0]
[17, 8, 10, 0, 0],
[16, 7, 10, 0, 0]
]) ])
print(model.predict(X_eval)) print(model.predict(X_eval))
result = model.predict(X_eval)
result = pd.DataFrame(result,index=['2023-11-28','2023-11-29','2023-11-30'])
result = pd.concat((result_eval['eval'],result))
result.index = result.index.map(lambda x:str(x)[:10])
print(result)

@ -44,7 +44,7 @@ data = data.loc[normal(data['售电量']).index]
# print(list0,list1,list2) # print(list0,list1,list2)
data['season'] = data.index.map(season) data['season'] = data.index.map(season)
# data = data.loc[:'2023-9'] # data = data.loc[:'2023-9']
df_eval = data.loc['2023-10'] df_eval = data.loc['2023-11']
df_train = data.iloc[450:-1] df_train = data.iloc[450:-1]
# df_train = data[450:][:-3] # df_train = data[450:][:-3]
print(df_train) print(df_train)
@ -89,10 +89,13 @@ loaded_model.load_model('jiaxing.bin')
import numpy as np import numpy as np
X_eval = np.array([ X_eval = np.array([
[17, 9, 10, 0, 1], [14.5, 7.7, 10, 0, 1],
[16, 3, 10, 0, 1], [18.2, 7.8, 10, 0, 1],
[15, 3, 10, 0, 1], [11.9, 6.6, 10, 0, 1]
[15, 7, 10, 0, 1],
[14, 5, 10, 0, 1]
]) ])
print(model.predict(X_eval)) print(model.predict(X_eval))
result = model.predict(X_eval)
result = pd.DataFrame(result,index=['2023-11-28','2023-11-29','2023-11-30'])
result = pd.concat((result_eval['eval'],result))
result.index = result.index.map(lambda x:str(x)[:10])
print(result)

@ -45,10 +45,10 @@ data = data.loc[normal(data['售电量']).index]
data['season'] = data.index.map(season) data['season'] = data.index.map(season)
df_eval = data.loc['2023-10'] df_eval = data.loc['2023-11']
# df_train = data.loc['2022-01':'2023-09'][:-3] # df_train = data.loc['2022-01':'2023-09'][:-3]
df_train = data.loc['2022-01':'2023-10'][:-1] df_train = data.loc['2022-01':'2023-11']
df_train = df_train[['tem_max', 'tem_min', 'holiday', '24ST', '售电量', 'season']] df_train = df_train[['tem_max', 'tem_min', 'holiday', '24ST', '售电量', 'season']]
@ -78,22 +78,21 @@ print(goal)
goal2 = (result_eval['eval'][-23:].sum() - result_eval['pred'][-23:].sum()) / result_eval['eval'].sum() goal2 = (result_eval['eval'][-23:].sum() - result_eval['pred'][-23:].sum()) / result_eval['eval'].sum()
print(goal2) print(goal2)
print(result_eval) print(result_eval)
# if abs(goal) < best_goal :
# best_goal = abs(goal)
# best_i['best_i'] = i
# x = goal2
#
# print(best_i,best_goal,x)
# 保存模型 # 保存模型
# model.save_model('ningbo.bin') # model.save_model('ningbo.bin')
import numpy as np import numpy as np
X_eval = np.array([ X_eval = np.array([
[20, 10, 10, 0, 1],
[19, 12, 10, 0, 1], [16.5, 6.8, 10, 0, 1],
[18, 9, 10, 0, 1], [21.7, 6.8, 10, 0, 1],
[21, 9, 10, 0, 1], [13, 8.8, 10, 0, 1]
[14, 9, 10, 0, 1]
]) ])
print(model.predict(X_eval)) print(model.predict(X_eval))
result = model.predict(X_eval)
result = pd.DataFrame(result,index=['2023-11-28','2023-11-29','2023-11-30'])
result = pd.concat((result_eval['eval'],result))
result.index = result.index.map(lambda x:str(x)[:10])
print(result)

@ -58,7 +58,7 @@ data['season'] = data.index.map(season)
# data = data.loc[:'2023-9'] # data = data.loc[:'2023-9']
df_train = data[500:-1] df_train = data[500:-1]
# df_train = data[500:][:-3] # df_train = data[500:][:-3]
df_eval = data.loc['2023-10'] df_eval = data.loc['2023-11']
print(df_train) print(df_train)
X = df_train[['tem_max', 'tem_min', '24ST', 'holiday', 'season']] X = df_train[['tem_max', 'tem_min', '24ST', 'holiday', 'season']]
@ -115,10 +115,13 @@ model.save_model('hangzhou.bin')
loaded_model = xgb.XGBRegressor() loaded_model = xgb.XGBRegressor()
loaded_model.load_model('hangzhou.bin') loaded_model.load_model('hangzhou.bin')
X_eval = np.array([ X_eval = np.array([
[18, 9, 10, 0, 0], [17.2, 5.7, 10, 0, 0],
[20, 7, 10, 0, 0], [21.2, 4.3, 10, 0, 0],
[17, 4, 10, 0, 0], [11.5, 6.6, 10, 0, 0]
[15, 8, 10, 0, 0],
[12, 7, 10, 0, 0]
]) ])
print(model.predict(X_eval)) print(model.predict(X_eval))
result = model.predict(X_eval)
result = pd.DataFrame(result,index=['2023-11-28','2023-11-29','2023-11-30'])
result = pd.concat((result_eval['eval'],result))
result.index = result.index.map(lambda x:str(x)[:10])
print(result)

@ -46,9 +46,9 @@ data = data.loc[normal(data['售电量']).index]
data['season'] = data.index.map(season) data['season'] = data.index.map(season)
# data = data.loc[:'2023-8'] # data = data.loc[:'2023-8']
df_eval = data.loc['2023-10'] df_eval = data.loc['2023-11']
df_train = data[450:-1] df_train = data[450:]
# df_train = data[450:][:-3] # df_train = data[450:][:-3]
print(df_train) print(df_train)
@ -95,10 +95,13 @@ loaded_model.load_model('wenzhou.bin')
import numpy as np import numpy as np
X_eval = np.array([ X_eval = np.array([
[23, 11, 10, 0, 1], [19.8, 6.6, 10, 0, 1],
[21, 8, 10, 0, 1], [22, 6.1, 10, 0, 1],
[21, 8, 10, 0, 1], [18.5, 10.1, 10, 0, 1]
[21, 9, 10, 0, 1],
[17, 7, 10, 0, 1]
]) ])
print(model.predict(X_eval)) print(model.predict(X_eval))
result = model.predict(X_eval)
result = pd.DataFrame(result,index=['2023-11-28','2023-11-29','2023-11-30'])
result = pd.concat((result_eval['eval'],result))
result.index = result.index.map(lambda x:str(x)[:10])
print(result)

@ -47,7 +47,7 @@ data = data.loc[normal(data['售电量']).index]
data['season'] = data.index.map(season) data['season'] = data.index.map(season)
# data = data.loc[:'2023-9'] # data = data.loc[:'2023-9']
df_eval = data.loc['2023-10'] df_eval = data.loc['2023-11']
df_train = data[450:-1] df_train = data[450:-1]
# df_train = data[450:][:-3] # df_train = data[450:][:-3]
@ -83,10 +83,14 @@ loaded_model.load_model('huzhou.bin')
import numpy as np import numpy as np
X_eval = np.array([ X_eval = np.array([
[15, 8, 10, 0, 1],
[18, 9, 10, 0, 1], [14.9, 7.1, 10, 0, 1],
[15, 8, 10, 0, 1], [17.7, 6.6, 10, 0, 1],
[16, 8, 10, 0, 1], [10.3, 5.8, 10, 0, 1]
[12, 7, 10, 0, 1]
]) ])
print(model.predict(X_eval)) print(model.predict(X_eval))
result = model.predict(X_eval)
result = pd.DataFrame(result,index=['2023-11-28','2023-11-29','2023-11-30'])
result = pd.concat((result_eval['eval'],result))
result.index = result.index.map(lambda x:str(x)[:10])
print(result)

@ -47,7 +47,7 @@ data['season'] = data.index.map(season)
df_eval = data.loc['2023-11'] df_eval = data.loc['2023-11']
# data = data.loc[:'2023-8'] # data = data.loc[:'2023-8']
df_train = data[450:-1] df_train = data[450:]
# df_train = data[450:][:-3] # df_train = data[450:][:-3]
print(df_train) print(df_train)
@ -57,10 +57,6 @@ 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['售电量']
# 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.1, random_state=42) x_train, x_test, y_train, y_test = train_test_split(X, y, test_size=0.1, 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)
@ -79,11 +75,7 @@ print(goal)
goal2 = (result_eval['eval'][-23:].sum() - result_eval['pred'][-23:].sum()) / result_eval['eval'].sum() goal2 = (result_eval['eval'][-23:].sum() - result_eval['pred'][-23:].sum()) / result_eval['eval'].sum()
print(goal2) print(goal2)
# if abs(goal) < best_goal :
# best_goal = abs(goal)
# best_i['best_i'] = i
# x = goal2
# print(best_i,best_goal,x)
print(result_eval) print(result_eval)
# # 保存模型 # # 保存模型
# model.save_model('shaoxing.bin') # model.save_model('shaoxing.bin')
@ -92,10 +84,13 @@ print(result_eval)
import numpy as np import numpy as np
X_eval = np.array([ X_eval = np.array([
[16.2, 8.2, 10, 1, 0], [17.4, 6.6, 10, 0, 0],
[20, 6, 10, 0, 0], [21.2, 7, 10, 0, 0],
[19, 7, 10, 0, 0], [12.1, 7.3, 10, 0, 0]
[16, 8, 10, 0, 0],
[12, 7, 10, 0, 0]
]) ])
print(model.predict(X_eval)) print(model.predict(X_eval))
result = model.predict(X_eval)
result = pd.DataFrame(result,index=['2023-11-28','2023-11-29','2023-11-30'])
result = pd.concat((result_eval['eval'],result))
result.index = result.index.map(lambda x:str(x)[:10])
print(result)

@ -44,9 +44,9 @@ data = data.loc[normal(data['售电量']).index]
# print(list0,list1,list2) # print(list0,list1,list2)
data['season'] = data.index.map(season) data['season'] = data.index.map(season)
df_eval = data.loc['2023-10'] df_eval = data.loc['2023-11']
# data = data.loc[:'2023-8'] # data = data.loc[:'2023-8']
df_train = data.iloc[450:-1] df_train = data.iloc[450:]
# df_train = data.iloc[450:][:-3] # df_train = data.iloc[450:][:-3]
df_train = df_train[['tem_max', 'tem_min', 'holiday', '24ST', '售电量', 'season']] df_train = df_train[['tem_max', 'tem_min', 'holiday', '24ST', '售电量', 'season']]
@ -80,10 +80,13 @@ loaded_model.load_model('zhoushan.bin')
import numpy as np import numpy as np
X_eval = np.array([ X_eval = np.array([
[18, 11, 10, 0, 1], [14.7, 11.4, 10, 0, 1],
[17, 9, 10, 0, 1], [19.4, 11.8, 10, 0, 1],
[17, 8, 10, 0, 1], [14.9, 9.4, 10, 0, 1]
[18, 10, 10, 0, 1],
[14, 7, 10, 0, 1]
]) ])
print(model.predict(X_eval)) print(model.predict(X_eval))
result = model.predict(X_eval)
result = pd.DataFrame(result,index=['2023-11-28','2023-11-29','2023-11-30'])
result = pd.concat((result_eval['eval'],result))
result.index = result.index.map(lambda x:str(x)[:10])
print(result)

@ -41,8 +41,8 @@ data = data.loc[normal(data['售电量']).index]
data['season'] = data.index.map(season) data['season'] = data.index.map(season)
# data = data.loc[:'2023-8'] # data = data.loc[:'2023-8']
df_eval = data.loc['2023-10'] df_eval = data.loc['2023-11']
df_train = data.iloc[450:-1] df_train = data.iloc[450:]
# df_train = data.iloc[450:-3] # df_train = data.iloc[450:-3]
@ -74,14 +74,16 @@ loaded_model = xgb.XGBRegressor()
loaded_model.load_model('quzhou.bin') loaded_model.load_model('quzhou.bin')
import numpy as np import numpy as np
X_eval = np.array([ X_eval = np.array([
[19,10,10,0,1], [18.7, 7, 10, 0, 1],
[19, 7, 10, 0, 1], [20.2, 6.5, 10, 0, 1],
[18, 6, 10, 0, 1], [11.2, 8, 10, 0, 1]
[16, 7, 10, 0, 1],
[14, 10, 10, 0, 1]
]) ])
print(model.predict(X_eval)) print(model.predict(X_eval))
result = model.predict(X_eval)
result = pd.DataFrame(result,index=['2023-11-28','2023-11-29','2023-11-30'])
result = pd.concat((result_eval['eval'],result))
result.index = result.index.map(lambda x:str(x)[:10])
print(result)
# import torch # import torch

@ -41,11 +41,11 @@ data = data.loc[normal(data['售电量']).index]
# print(list0,list1,list2) # print(list0,list1,list2)
data['season'] = data.index.map(season) data['season'] = data.index.map(season)
data = data.loc[:'2023-9'] data = data.loc[:'2023-11']
df_eval = data.loc['2023-9'] df_eval = data.loc['2023-11']
# df_train = data.iloc[450:-1] # df_train = data.iloc[450:-1]
df_train = data.iloc[450:-3] df_train = data.iloc[450:]
print(df_train) print(df_train)
df_train = df_train[['tem_max','tem_min','holiday','24ST','售电量','season']] df_train = df_train[['tem_max','tem_min','holiday','24ST','售电量','season']]
@ -89,10 +89,13 @@ loaded_model = xgb.XGBRegressor()
loaded_model.load_model('jinhua.bin') loaded_model.load_model('jinhua.bin')
import numpy as np import numpy as np
X_eval = np.array([ X_eval = np.array([
[19,12,10,0,1], [19.5, 7.6, 10, 0, 1],
[20, 10, 10, 0, 1], [21.7, 6.8, 10, 0, 1],
[18, 5, 10, 0, 1], [11.6, 8.2, 10, 0, 1]
[17, 6, 10, 0, 1],
[14, 8, 10, 0, 1]
]) ])
print(model.predict(X_eval)) print(model.predict(X_eval))
result = model.predict(X_eval)
result = pd.DataFrame(result,index=['2023-11-28','2023-11-29','2023-11-30'])
result = pd.concat((result_eval['eval'],result))
result.index = result.index.map(lambda x:str(x)[:10])
print(result)

@ -166,7 +166,7 @@ max_value,min_value = 192751288.47,0.0
model.load_state_dict(torch.load('best_dy3.pth',map_location=torch.device('cpu'))) # cpu跑加上,map_location=torch.device('cpu') model.load_state_dict(torch.load('best_dy3.pth',map_location=torch.device('cpu'))) # cpu跑加上,map_location=torch.device('cpu')
# file_dir = r'./浙江各地市分电压日电量数据' # file_dir = r'./浙江各地市分电压日电量数据'
df = pd.read_excel(r'C:\Users\鸽子\Desktop\浙江电量20231127.xlsx',sheet_name=1) df = pd.read_excel(r'C:\Users\鸽子\Desktop\浙江电量20231129.xlsx',sheet_name=1)
df = df[df['county_name'].isnull()] df = df[df['county_name'].isnull()]
for city in df['city_name'].drop_duplicates(): for city in df['city_name'].drop_duplicates():
@ -182,8 +182,14 @@ for city in df['city_name'].drop_duplicates():
pred = pred * (max_value - min_value) + min_value pred = pred * (max_value - min_value) + min_value
result = pred.cpu().detach().numpy()[-3:] result = pred.cpu().detach().numpy()[-3:]
result_dict[level] = list(result) result_dict[level] = list(result)
df1 = pd.DataFrame(result_dict,index=['2023-11-28','2023-11-29','2023-11-30']) df1 = pd.DataFrame(result_dict,index=['2023-11-28','2023-11-29','2023-11-30'])
df1.to_excel(fr'C:\Users\鸽子\Desktop\11月分压电量预测28-30\{city} .xlsx') df1['city_name'] = city
df1 = df1[df_city.columns]
df1 = pd.concat((df_city.iloc[:27],df1))
with pd.ExcelWriter(r'C:\Users\鸽子\Desktop\市分压电量预测v1129.xlsx',mode='a',engine='openpyxl',if_sheet_exists='replace') as writer:
df1.to_excel(writer,sheet_name=f'{city[4:6]}')
print(result_dict) print(result_dict)
# 打印指标 # 打印指标

@ -164,7 +164,7 @@ model = model.eval()
# 测试 # 测试
# file_dir = './浙江各地市行业电量数据' # file_dir = './浙江各地市行业电量数据'
df = pd.read_excel(r'C:\Users\鸽子\Desktop\浙江电量20231127.xlsx',sheet_name=2) df = pd.read_excel(r'C:\Users\鸽子\Desktop\浙江电量20231129.xlsx',sheet_name=2)
for city in df['city_name'].drop_duplicates(): for city in df['city_name'].drop_duplicates():
df_city = df[df['city_name']==city].sort_values(by='stat_date').set_index('stat_date') df_city = df[df['city_name']==city].sort_values(by='stat_date').set_index('stat_date')
@ -183,7 +183,13 @@ for city in df['city_name'].drop_duplicates():
result = pred.cpu().detach().numpy()[-3:] result = pred.cpu().detach().numpy()[-3:]
result_dict[industry] = list(result) result_dict[industry] = list(result)
df1 = pd.DataFrame(result_dict,index=['2023-11-28','2023-11-29','2023-11-30']) df1 = pd.DataFrame(result_dict,index=['2023-11-28','2023-11-29','2023-11-30'])
df1.to_excel(fr'C:\Users\鸽子\Desktop\11月行业电量预测27-30\{city} .xlsx') df1['city_name'] = city
df1 = df1[df_city.columns]
df1 = pd.concat((df_city.iloc[:27], df1))
print(df_city)
print(df1)
with pd.ExcelWriter(r'C:\Users\鸽子\Desktop\行业电量预测v1129.xlsx',mode='a',engine='openpyxl',if_sheet_exists='replace') as writer:
df1.to_excel(writer,sheet_name=f'{city[4:6]}')
print(time.time()-t1) print(time.time()-t1)
print(result_dict) print(result_dict)

Loading…
Cancel
Save