from sklearn import datasets from sklearn.linear_model import LinearRegression #加载数据 loaded_data = datasets.load_boston() data_X = loaded_data.data data_Y = loaded_data.target #是否需要对数据进行拆分 #定义模型 model = LinearRegression() #训练 model.fit(data_X,data_Y) print(model.predict(data_X[:4,:])) print(data_Y[:4])
from sklearn import datasets import matplotlib.pyplot as plt X,Y = datasets.make_regression(n_samples=100,n_features=1,n_targets=1,noise=1) plt.scatter(X,Y) plt.show()