|
|
|
@ -15,29 +15,38 @@ df = pd.read_csv('区县400v入模数据.csv',encoding='gbk',index_col='dtdate')
|
|
|
|
|
df.index = pd.to_datetime(df.index)
|
|
|
|
|
print(df.head())
|
|
|
|
|
|
|
|
|
|
# org_name = df['org_name'].values[0]
|
|
|
|
|
org_name = ' 国网温岭市供电公司 '
|
|
|
|
|
data = df[df['org_name']==org_name]
|
|
|
|
|
data = data.loc[normal(data['0.4kv及以下']).index]
|
|
|
|
|
print(data)
|
|
|
|
|
X = data.drop(columns=['city_name','org_name','0.4kv及以下'])
|
|
|
|
|
x = X.loc['2022-1':'2023-7']
|
|
|
|
|
x_eval = X.loc['2023-8']
|
|
|
|
|
y = data['0.4kv及以下'].loc['2022-1':'2023-7']
|
|
|
|
|
y_eval = data['0.4kv及以下'].loc['2023-8']
|
|
|
|
|
plt.plot(range(len(y)),y)
|
|
|
|
|
plt.show()
|
|
|
|
|
|
|
|
|
|
x_train,x_test,y_train,y_test = train_test_split(x,y,test_size=0.3,random_state=42)
|
|
|
|
|
|
|
|
|
|
model = xgb.XGBRegressor(max_depth=6,learning_rate=0.05,n_estimators=150)
|
|
|
|
|
model.fit(x_train,y_train)
|
|
|
|
|
|
|
|
|
|
pred = model.predict(x_test)
|
|
|
|
|
print(r2_score(pred,y_test))
|
|
|
|
|
|
|
|
|
|
predict = model.predict(x_eval)
|
|
|
|
|
result = pd.DataFrame({'real':y_eval,'pred':predict},index=y_eval.index)
|
|
|
|
|
print(result)
|
|
|
|
|
print((result['real'][-3:]-result['pred'][-3:]).sum()/result['real'].sum())
|
|
|
|
|
|
|
|
|
|
list_org = []
|
|
|
|
|
list_fl = []
|
|
|
|
|
list_sc = []
|
|
|
|
|
for org_name in df['org_name'].drop_duplicates():
|
|
|
|
|
data = df[df['org_name']==org_name]
|
|
|
|
|
if org_name.strip()[-4:] != '供电公司':
|
|
|
|
|
continue
|
|
|
|
|
data = data.loc[normal(data['0.4kv及以下']).index]
|
|
|
|
|
X = data.drop(columns=['city_name','org_name','0.4kv及以下'])
|
|
|
|
|
x = X.loc['2022-1':'2023-7'][:-3]
|
|
|
|
|
x_eval = X.loc['2023-7']
|
|
|
|
|
y = data['0.4kv及以下'].loc['2022-1':'2023-7'][:-3]
|
|
|
|
|
y_eval = data['0.4kv及以下'].loc['2023-7']
|
|
|
|
|
# plt.plot(range(len(y)),y)
|
|
|
|
|
# plt.show()
|
|
|
|
|
|
|
|
|
|
x_train,x_test,y_train,y_test = train_test_split(x,y,test_size=0.3,random_state=42)
|
|
|
|
|
|
|
|
|
|
model = xgb.XGBRegressor(max_depth=6,learning_rate=0.05,n_estimators=150)
|
|
|
|
|
model.fit(x_train,y_train)
|
|
|
|
|
|
|
|
|
|
pred = model.predict(x_test)
|
|
|
|
|
# print(org_name)
|
|
|
|
|
list_org.append(org_name)
|
|
|
|
|
# print(r2_score(pred,y_test))
|
|
|
|
|
list_sc.append(r2_score(pred,y_test))
|
|
|
|
|
predict = model.predict(x_eval)
|
|
|
|
|
result = pd.DataFrame({'real':y_eval,'pred':predict},index=y_eval.index)
|
|
|
|
|
# print(result)
|
|
|
|
|
# print((result['real'][-3:]-result['pred'][-3:]).sum()/result['real'].sum())
|
|
|
|
|
list_fl.append((result['real'][-3:]-result['pred'][-3:]).sum()/result['real'].sum())
|
|
|
|
|
|
|
|
|
|
df = pd.DataFrame({'org':list_org,'sc':list_sc,'goal':list_fl})
|
|
|
|
|
print(df)
|
|
|
|
|
print(df['goal'].value_counts(bins=[-0.05,-0.01,-0.005,0, 0.005, 0.01, 0.02,0.05],sort=False))
|