1 from sklearn.datasets import load_boston2 boston = load_boston()3 boston.keys()
print(boston.DESCR)
boston.targetimport pandas as pddf = pd.DataFrame(boston.data)df
from sklearn.linear_model import LinearRegressionLineR = LinearRegression()LineR.fit(x.reshape(-1,1),y)LineR.coef_LineR.intercept_import matplotlib.pyplot as pltx=boston.data[:,5]y=boston.targetplt.figure(figsize=(10,6))plt.scatter(x,y)plt.plot(x,9.1*x-34,'r')plt.show()
import matplotlib.pyplot as pltx = boston.data[:,12].reshape(-1,1)y = boston.targetplt.figure(figsize=(10,6))plt.scatter(x,y)from sklearn.linear_model import LinearRegressionlineR=LinearRegression()lineR.fit(x,y)y_pred = lineR.predict(x)plt.plot(x,y_pred)plt.show()
from sklearn.preprocessing import PolynomialFeaturespoly = PolynomialFeatures(degree = 2)x_poly = poly.fit_transform(x)lrp = LinearRegression()lrp.fit(x_poly,y)y_poly_pred = lrp.predict(x_poly)plt.scatter(x,y)plt.scatter(x,y_pred)plt.scatter(x,y_poly_pred)plt.show()