输出预测结果
parent
396f1f2758
commit
9112c8177e
@ -1,4 +1,4 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="ProjectRootManager" version="2" project-jdk-name="pytorch_gpu" project-jdk-type="Python SDK" />
|
<component name="ProjectRootManager" version="2" project-jdk-name="C:\anaconda\envs\pytorch" project-jdk-type="Python SDK" />
|
||||||
</project>
|
</project>
|
@ -0,0 +1,43 @@
|
|||||||
|
import pandas as pd
|
||||||
|
from sklearn.model_selection import train_test_split
|
||||||
|
import os
|
||||||
|
from sklearn.metrics import r2_score
|
||||||
|
import xgboost as xgb
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
pd.set_option('display.width',None)
|
||||||
|
|
||||||
|
def normal(s1):
|
||||||
|
high = s1.describe()['75%'] + 1.5*(s1.describe()['75%']-s1.describe()['25%'])
|
||||||
|
low = s1.describe()['25%'] - 1.5 * (s1.describe()['75%'] - s1.describe()['25%'])
|
||||||
|
return s1[(s1>=low)&(s1<=high)]
|
||||||
|
|
||||||
|
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())
|
||||||
|
|
@ -0,0 +1,24 @@
|
|||||||
|
import os
|
||||||
|
|
||||||
|
import pandas as pd
|
||||||
|
|
||||||
|
df = pd.read_csv(r'C:\Users\鸽子\Desktop\浙江各区县数据(2).csv')
|
||||||
|
df.columns = df.columns.map(lambda x:x.strip())
|
||||||
|
df['市'] = df['市'].str[:2]
|
||||||
|
df = df[['市','org_name','日期','0.4kv及以下']]
|
||||||
|
df['日期'] = pd.to_datetime(df['日期'])
|
||||||
|
print(df)
|
||||||
|
|
||||||
|
wd_file = 'C:\python-project\p1031\入模数据'
|
||||||
|
df_wd = pd.DataFrame({})
|
||||||
|
for city in os.listdir(wd_file):
|
||||||
|
data = pd.read_excel(os.path.join(wd_file,city)).drop(columns='售电量')
|
||||||
|
data['city_name'] = data['city_name'].str[:2]
|
||||||
|
df_wd = pd.concat([df_wd,data])
|
||||||
|
print(df_wd)
|
||||||
|
df_wd['dtdate'] = pd.to_datetime(df_wd['dtdate'])
|
||||||
|
df = pd.merge(df,df_wd,left_on=['日期','市'],right_on=['dtdate','city_name'])
|
||||||
|
df = df[['city_name','org_name','dtdate','tem_max','tem_min','holiday','24ST','0.4kv及以下']]
|
||||||
|
df['0.4kv及以下'] /= 10000
|
||||||
|
df.to_csv('区县400v入模数据.csv',index=False,encoding='GBK')
|
||||||
|
print(df)
|
Loading…
Reference in New Issue