首页 > 其他分享 >预测模型利用

预测模型利用

时间:2023-03-06 11:24:29浏览次数:30  
标签:预测 模型 利用 train 2014 new csv data reg

import numpy as np
import pandas as pd
from sklearn.linear_model import Lasso

inputfile ='datayc.csv'
data = pd.read_csv(inputfile)
lasso = Lasso(1000)
lasso.fit(data.iloc[:,0:13],data['y'])
print('相关系数为:',np.round(lasso.coef_,5))
print('相关系数非零个数为:',np.sum(lasso.coef_ != 0))

mask = lasso.coef_ != 0

print('相关系数是否为零:',mask)

outputfile ='new_reg_data.csv'
mask = np.append(mask,True)
new_reg_data = data.iloc[:, mask]

new_reg_data.to_csv(outputfile)

print('输出数据的维度为:',new_reg_data.shape)

 

 找到相关系数不为零的数据

建立灰度预测模型

import numpy as np
import pandas as pd
from GM11 import GM11
inputfile1 = 'new_reg_data.csv'
inputfile2 = 'datayc.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
cols = ['x1','x3','x4','x5','x6','x7','x8','x13','y']
for i in cols:
f = GM11(new_reg_data.loc[range(1994,2014),i].values)[0]
new_reg_data.loc[2014,i] = f(len(new_reg_data)-1)
new_reg_data.loc[2015,i] = f(len(new_reg_data))
new_reg_data[i] = new_reg_data[i].round(2)
outputfile = '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 = "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 ="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('学号3119')
plt.show()

 

 

 

标签:预测,模型,利用,train,2014,new,csv,data,reg
From: https://www.cnblogs.com/panlongcong/p/17183080.html

相关文章

  • OSI七层模型的简介及每一层的数据单元
    一、OSI参考模型的基本概念OSI七层模型是OSI/RM的简称全程是“Open System Interconnect”的缩写,意为开放系统互联参考模型;参考模型是指不是必须该执行的标准,而是按照......
  • 财政收入影响因数分析及预测
    1.描述性统计分析#对各属性进行描述性统计分析defstatisticAnalysis():inputfile='../data/data.csv'#输出的数据文件data=pd.read_csv(inputfile)#......
  • 财政收入影响因素分析及预测
    importrandomimportpandasaspdimportnumpyasnpimportmatplotlib.pyplotasplt#计算欧拉距离defcalcDis(dataSet,centroids,k):clalist=[]fo......
  • 财政收入影响因素分析及预测
    importnumpyasnpimportpandasaspdinputfile='D:/anaconda/python-work/Three/data(1).csv'#输入的数据文件data=pd.read_csv(inputfile)#读取数据......
  • 财政收入影响因数分析及预测
    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......
  • 盒子模型的 内边框 padding border
    知识点一:边框影响盒子实际大小边框会额外增加盒子的实际大小,所以有两种解决方案,第一:测量盒子大小的时候,不加边框;第二:如果测量了边框,需要用width/height减去边框的大小,就是盒......
  • 预测财政
    #预测财政收入,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......