import numpy as np import pandas as pd import matplotlib.pyplot as plt
data=pd.read_csv('./data/data.csv') data #%% x=data.iloc[:,0:-1] y=data.iloc[:,-1]
#使用Lasso预测 from sklearn import linear_model from sklearn import model_selection reg=linear_model.Lasso(alpha=0.1) x1=np.linspace(0,1,20) reg.fit(x,y) #训练 y_pre=reg.predict(x) #预测 #对比图 plt.figure() p1=plt.plot(x1,y,color='green',linewidth='1.0',linestyle='--',label='true') p2=plt.plot(x1,y_pre,color='red',linewidth='1.6',label='predict') plt.legend() plt.title("吕莹2020310143049") plt.show()
''' 使用支持向量机回归i预测 ''' from sklearn.svm import SVC from sklearn.svm import LinearSVR clf=LinearSVR(C=3) #训练 clf.fit(x,y) #预测 y_pre1=clf.predict(x) #对比 plt.figure() p1=plt.plot(x1,y,color='green',linewidth='1.0',linestyle='--',label='true') p2=plt.plot(x1,y_pre1,color='red',linewidth='1.6',label='predict') plt.legend() plt.title("吕莹2020310143049") plt.show()
#线性回归 from sklearn.linear_model import LinearRegression model=LinearRegression() model.fit(x,y) y_pre2=model.predict(x) #对比图 plt.figure() p1=plt.plot(x1,y,color='green',linewidth='1.0',linestyle='--',label='true') p2=plt.plot(x1,y_pre2,color='red',linewidth='1.6',label='predict') plt.legend() plt.title("吕莹2020310143049") plt.show()
标签:linewidth,2016,plt,plot,财政收入,import,2014,model,x1 From: https://www.cnblogs.com/cyszd/p/17181588.html