diff --git a/.idea/misc.xml b/.idea/misc.xml index 695b918..3141537 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,4 +1,4 @@ - + \ No newline at end of file diff --git a/.idea/pytorch2.iml b/.idea/pytorch2.iml index 5cfdc49..719cec4 100644 --- a/.idea/pytorch2.iml +++ b/.idea/pytorch2.iml @@ -2,7 +2,7 @@ - + \ No newline at end of file diff --git a/浙江电压等级电量/区县分压/xgb_区县.py b/浙江电压等级电量/区县分压/xgb_区县.py new file mode 100644 index 0000000..22ca596 --- /dev/null +++ b/浙江电压等级电量/区县分压/xgb_区县.py @@ -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()) + diff --git a/浙江电压等级电量/区县分压/区县400v数据处理.py b/浙江电压等级电量/区县分压/区县400v数据处理.py new file mode 100644 index 0000000..d28ae18 --- /dev/null +++ b/浙江电压等级电量/区县分压/区县400v数据处理.py @@ -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) \ No newline at end of file diff --git a/浙江电压等级电量/区县分压.py b/浙江电压等级电量/区县分压/区县分压.py similarity index 100% rename from 浙江电压等级电量/区县分压.py rename to 浙江电压等级电量/区县分压/区县分压.py