首页 > 其他分享 >财政收入影响因素分析及预测

财政收入影响因素分析及预测

时间:2023-03-05 23:12:27浏览次数:33  
标签:因素 plt 预测 train 财政收入 import new data reg

import numpy as np

import pandas as pd

inputfile = 'D:/anaconda/python-work/Three/data(1).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('描述性统计结果:\n',np.round(description, 2))  # 保留两位小数
corr=data.corr(method='pearson')#计算相关系数矩阵
print('相关系数矩阵为:\n',np.round(corr,2))#保留两位小数
import matplotlib.pyplot as plt
import seaborn as sns
plt.subplots(figsize=(10,10))#设置画面大小
sns.heatmap(corr,annot=True,vmax=1,square=True,cmap="Blues")
plt.rcParams['font.sans-serif'] = ['SimHei'] 
plt.title('相关性热力图')
plt.show()
plt.close

 

 

 

 

 

 

import sys
sys.path.append('../code')  # 设置路径
import numpy as np
import pandas as pd
from GM11 import GM11  # 引入自编的灰色预测函数

inputfile1 = 'D:/anaconda/python-work/Three/new_reg_data.csv'  # 输入的数据文件
inputfile2 = 'D:/anaconda/python-work/Three/data(1).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].values)[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 = 'D:/anaconda/python-work/Three/new_reg_data_GM11.xls'  # 灰色预测后保存的路径
y = list(data['y'].values)  # 提取财政收入列,合并至新数据框中
y.extend([np.nan,np.nan])
new_reg_data['y'] = y
new_reg_data.to_excel(outputfile)  # 结果输出
print('预测结果为:\n',new_reg_data.loc[2014:2015,:])  # 预测结果展示

 

 

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from sklearn.svm import LinearSVR

inputfile = "D:/anaconda/python-work/Three/new_reg_data_GM11.xls"  # 灰色预测后保存的路径
data = pd.read_excel(inputfile)  # 读取数据
feature = ['x1', 'x3', 'x4', 'x5', 'x6', 'x7', 'x8', 'x13']  # 属性所在列

data.index = range(1994, 2016)
data_train = data.loc[range(1994, 2014)].copy()  # 取2014年前的数据建模
data_mean = data_train.mean()
data_std = data_train.std()
data_train = (data_train - data_mean)/data_std  # 数据标准化
x_train = data_train[feature].to_numpy()  # 属性数据
y_train = data_train['y'].to_numpy()  # 标签数据

linearsvr = LinearSVR()  # 调用LinearSVR()函数
linearsvr.fit(x_train,y_train)
x = ((data[feature] - data_mean[feature])/data_std[feature]).to_numpy()  # 预测,并还原结果。
data['y_pred'] = linearsvr.predict(x) * data_std['y'] + data_mean['y']
outputfile ="D:/anaconda/python-work/Three/new_reg_data_GM11_revenue.xls"  # SVR预测后保存的结果
data.to_excel(outputfile)

print('真实值与预测值分别为:\n',data[['y','y_pred']])

fig = data[['y','y_pred']].plot(subplots = True, style=['b-o','r-*'])  # 画出预测结果图
plt.rcParams['font.sans-serif'] = ['SimHei'] # 添加这条可以让图形显示中文
plt.title('3036')
plt.show()

 

 

 

标签:因素,plt,预测,train,财政收入,import,new,data,reg
From: https://www.cnblogs.com/lzw2019114243036/p/17182144.html

相关文章

  • 财政收入影响因数分析及预测
    1.描述性统计分析#对各属性进行描述性统计分析defstatisticAnalysis():inputfile='../data/data.csv'#输出的数据文件data=pd.read_csv(inputfile)......
  • 财政预测
    #预测财政收入,2014、2015(y)神经网络,用到data_1importosimportnumpyasnpimportpandasaspdfromsklearn.linear_modelimportLassoLarsfromsklearn.linear_m......
  • 财政收入影响因素分析及预测
    一、财政收入影响因素分析描述性统计结果: importnumpyasnpimportpandasaspdinputfile='C:/Users/86133/Documents/WeChatFiles/wxid_ou51tgtht1bz22/FileStorag......
  • 预测财政
    #预测财政收入,2014、2015(y)神经网络,用到data_1importosimportnumpyasnpimportpandasaspdfromsklearn.linear_modelimportLassoLarsfromsklearn.linear_m......
  • 灰色预测(财政收入影响因素分析及预测)
    #-*-coding:utf-8-*-defGM11(x0):#自定义灰色预测函数importnumpyasnpx1=x0.cumsum()#1-AGO序列z1=(x1[:len(x1)-1]+x1[1:])/2.0#紧邻均值(ME......
  • 财政收入影响因素分析及预测
    importnumpyasnpimportpandasaspdinputfile='D:\data.csv'data=pd.read_csv(inputfile)#描述性统计分析#依次计算最小值、最大值、均值、标准差description=......
  • 财政收入影响因素分析及预测
    #描述性统计分析和相关系数矩阵importpandasaspdimportnumpyasnpinputfile='D:\大三下\大数据实验课\demo\data.csv'#输入数据的文件data=pd.read_csv(inputfil......
  • 灰色预测模型
    importmatplotlib.pyplotaspltimportpandasaspdimportnumpyasnpfromsklearn.linear_modelimportLassodata=pd.read_csv('./data/data.csv')lasso=Lasso(10......
  • 财政预测
    importnumpyasnpimportpandasaspdinputfile='E:\python数据分析\data.csv'#输入的数据文件data=pd.read_csv(inputfile)#读取数据#相关性分析corr......
  • 财政预测
    importnumpyasnpimportpandasaspdplt.rcParams['font.sans-serif']=['SimHei']#解决中文显示问题plt.rcParams['axes.unicode_minus']=False#解决中......