from sklearn import datasets # In[4]: mydata = datasets.load_boston() # In[5]: x = mydata.data # In[7]: y = mydata.target # In[8]: from sklearn.model_selection import train_test_split # In[10]: x_train,x_test,y_train,y_test = train_test_split(x,y,test_size=0.3) # In[11]: from sklearn.linear_model import LinearRegression,Ridge,Lasso # In[12]: lr = LinearRegression() # In[13]: ld = Ridge() # In[14]: ls = Lasso() # In[15]: models = [lr,ld,ls] # In[16]: names =['lr','ld','ls'] # In[19]: scores = [] for model,name in zip(models,names): model.fit(x_train,y_train) score = model.score(x_test,y_test) print('%s zhunquexingwei:%.5f'%(name,score)) # In[20]: print(scores)