补充9月数据

main
鸽子 1 year ago
parent 43352734c5
commit bf4803a140

@ -37,8 +37,8 @@ def normal(nd):
data = pd.read_excel(r'C:\python-project\pytorch3\入模数据\杭州数据.xlsx',index_col='dtdate')
data.index = pd.to_datetime(data.index,format='%Y-%m-%d')
data = data.loc[normal(data['售电量']).index]
plt.plot(range(len(data['售电量']['2021':'2022'])),data['售电量']['2021':'2022'])
plt.show()
# plt.plot(range(len(data['售电量']['2021':'2022'])),data['售电量']['2021':'2022'])
# plt.show()
# print(hf_season(data.loc['2021']['售电量']))
@ -47,8 +47,8 @@ data['month'] = data['month'].astype('int')
data['season'] = data.index.map(season)
print(data.head(50))
df_eval = data.loc['2023-7']
df_train = data.loc['2021-1':'2023-6']
df_eval = data.loc['2022-9':'2023-9']
df_train = data.loc['2021-1':'2022-8']
# df_train = df[500:850]
print(len(df_eval),len(df_train),len(data))
@ -73,7 +73,7 @@ print(y.describe())
# best_i = {}
# for i in range(400):
x_train,x_test,y_train,y_test = train_test_split(X,y,test_size=0.15,random_state=42)
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)
@ -96,6 +96,8 @@ goal2 = (result_eval['eval'][-23:].sum()-result_eval['pred'][-23:].sum())/result
print('goal2:',goal2)
print(result_eval)
print('r2:',r2_score(y_test,y_pred))
# result_eval.to_csv('asda.csv',encoding='gbk')
# if abs(goal) < best_goal:
# best_goal = abs(goal)
# best_i['best_i'] = i

@ -38,6 +38,30 @@ def normal(nd):
low = nd.describe()['25%'] - 1.5*(nd.describe()['75%']-nd.describe()['25%'])
return nd[(nd<high)&(nd>low)]
# def get_data():
file_dir = r'C:\Users\鸽子\Desktop\浙江各地市分电压日电量数据'
dataset_x = []
for excel in os.listdir(file_dir):
data = pd.read_excel(os.path.join(file_dir,excel), sheet_name=0,index_col=' stat_date ')
data.columns = data.columns.map(lambda x: x.strip())
data.index = pd.to_datetime(data.index,format='%Y%m%d')
data.sort_index(inplace=True)
data = data.loc['2021-01':'2023-08']
data.drop(columns=[i for i in data.columns if (data[i] == 0).sum() / len(data) >= 0.5], inplace=True) # 去除0值列
print('len(data):', len(data))
list_app = []
for level in data.columns:
df = data[level]
df = df[df.values != 0] # 去除0值行
df = normal(df)
df = df.astype('float32').values # 转换数据类型
dataset_x create_dataset(df,DAYS_FOR_TRAIN)
def run(file_dir,excel):
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
@ -53,8 +77,8 @@ def run(file_dir,excel):
data.drop(columns=[i for i in data.columns if (data[i] == 0).sum() / len(data) >= 0.5], inplace=True) # 去除0值列
print('len(data):', len(data))
list_app = []
for industry in data.columns:
df = data[industry]
for level in data.columns:
df = data[level]
df = df[df.values != 0] # 去除0值行
df = normal(df)
df = df.astype('float32').values # 转换数据类型
@ -124,14 +148,6 @@ def run(file_dir,excel):
pred = model(x.reshape(-1,1,DAYS_FOR_TRAIN)).view(-1).detach().numpy()
# for i in range(3):
# next_1_8 = x[1:]
# next_9 = model(x.reshape(-1,1,DAYS_FOR_TRAIN))
# # print(next_9,next_1_8)
# x = torch.concatenate((next_1_8, next_9.view(-1)))
# result_list.append(next_9.view(-1).item())
# 反归一化
pred = pred * (max_value - min_value) + min_value
df = df * (max_value - min_value) + min_value
@ -155,11 +171,6 @@ def run(file_dir,excel):
# f.write(f'{excel[:2]}{industry}:{round(target, 5)}\n')
if __name__ == '__main__':
file_dir = r'C:\Users\user\Desktop\浙江各地市分电压日电量数据'
file_dir = r'C:\Users\鸽子\Desktop\浙江各地市分电压日电量数据'
run(file_dir,'杭州.xlsx')
# p = Pool(4)
# for excel in os.listdir(file_dir):
# p.apply_async(func=run,args=(file_dir,excel))
# p.close()
# p.join()
Loading…
Cancel
Save