fromSklearnImportDatasets fromSklearn.linear_modelImportlinearregression#to import data from the Boston rate provided by SklearnLoaded_data =Datasets.load_boston () x_data=Loaded_data.datay_data=Loaded_data.targetmodel= Linearregression ()#model with linear regression yoModel.fit (x_data,y_data)#first show the previous 4Print(Model.predict (X_data[:4,:]))Print(Y_data[:4])
Sklearn also allows us to create some data ourselves
X, y = datasets.make_regression (n_samples=100,n_features=1,n_targets=1,noise=1)# There are 100 samples, one of the characteristics, one for the target variable, to play the drawing.
Import Matplotlib.pyplot as Plt # draw a scatter plot of x, y plt.scatter (x, y) plt.show ()
# make noise bigger, more discrete, such as noise=10 . X, y = datasets.make_regression (n_samples=100,n_features=1,n_targets=1,noise=10) plt.scatter (x, y) plt.show ()
Sklearn's Datasets Database