python预测
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='magenta',linewidth='1.6',linestyle='dotted',label='predict') plt.legend() plt.rcParams['font.sans-serif']=['SimHei'] plt.title("2019320143321魏沛然") 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='magenta',linewidth='1.6',linestyle='dotted',label='predict') plt.rcParams['font.sans-serif']=['SimHei'] plt.title("2019320143321魏沛然") plt.legend() 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='magenta',linewidth='1.6',linestyle='dotted',label='predict') plt.rcParams['font.sans-serif']=['SimHei'] plt.title("2019320143321魏沛然") plt.legend() plt.show()
 
 
                    
                     
                    
                 
                    
                
 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号