|
|
|
@ -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()
|