一、财政收入影响因素分析
描述性统计结果:
import numpy as np
import pandas as pd
inputfile='C:/Users/86133/Documents/WeChat Files/wxid_ou51tgtht1bz22/FileStorage/File/2023-02/data.csv'
data=pd.read_csv(inputfile)
description=[data.min(),data.max(),data.mean(),data.std()]
description=pd.DataFrame(description,index=['Min','Max','Mean','STD']).T
print('3115描述性统计结果:\n',np.round(description,2))
相关系数矩阵:
相关系数描述及输出数据维度:
import numpy as np
import pandas as pd
from sklearn.linear_model import Lasso
inputfile='C:/Users/86133/Documents/WeChat Files/wxid_ou51tgtht1bz22/FileStorage/File/2023-02/data.csv'
data=pd.read_csv(inputfile)
lasso=Lasso(1000)
lasso.fit(data.iloc[:,0:13],data['y'])
print('3115相关系数为',np.round(lasso.coef_,5))
print('3115相关系数非零个数为:',np.sum(lasso.coef_!=0))
mask=lasso.coef_!=0
print('3115相关系数是否为零:',mask)
outputfile='C:/Users/86133/Desktop/new_reg_data.csv'
mask=np.append(mask,True)
print(mask)
new_reg_data=data.iloc[:,mask]
new_reg_data.to_csv(outputfile)
print('3115输出数据的维度:',new_reg_data.shape)
相关性热力图:
二、财政收入的预测
财政收入的灰色预测GM11 :
import sys
sys.path.append('../code') # 设置路径
import numpy as np
import pandas as pd
from GM11 import GM11 # 引入自编的灰色预测函数
inputfile1 = 'C:/Users/86133/Desktop/new_reg_data.csv' # 输入的数据文件
inputfile2 = 'C:/Users/86133/Documents/WeChat Files/wxid_ou51tgtht1bz22/FileStorage/File/2023-02/data.csv' # 输入的数据文件
new_reg_data = pd.read_csv(inputfile1) # 读取经过特征选择后的数据
data = pd.read_csv(inputfile2) # 读取总的数据
new_reg_data.index = range(1994, 2014)
new_reg_data.loc[2014] = None
new_reg_data.loc[2015] = None
l = ['x1', 'x3', 'x4', 'x5', 'x6', 'x7', 'x8', 'x13']
for i in l:
f = GM11(new_reg_data.loc[range(1994, 2014),i].to_numpy())[0]
new_reg_data.loc[2014,i] = f(len(new_reg_data)-1) # 2014年预测结果
new_reg_data.loc[2015,i] = f(len(new_reg_data)) # 2015年预测结果
new_reg_data[i] = new_reg_data[i].round(2) # 保留两位小数
outputfile = 'C:/Users/86133/Desktop/new_reg_data_GM11.xlsx' # 灰色预测后保存的路径
y = list(data['y'].values) # 提取财政收入列,合并至新数据框中
y.extend([np.nan,np.nan])
new_reg_data['y'] = y
new_reg_data.to_excel(outputfile) # 结果输出
print('3115预测结果为:\n',new_reg_data.loc[2014:2015,:]) # 预测结果展示
真实值与预测值:
财政收入的GM21 灰色预测2016:
#导入所有需要的库
import numpy as np
import pandas as pd
from sklearn.linear_model import Lasso
from sklearn.svm import LinearSVR
#查看数据
inputfile='C:/Users/86133/Documents/WeChat Files/wxid_ou51tgtht1bz22/FileStorage/File/2023-02/data.csv'
data=pd.read_csv(inputfile)
真实值与预测值:
标签:86133,因素,预测,财政收入,import,new,csv,data,reg From: https://www.cnblogs.com/pythonzy/p/17181741.html