Sklearn's DATASets directory has a lot of ready data, and useful, can be used to learn algorithmic models. For example: Boston house prices, diabetes, numbers, Iris flowers. You can also prepare your own data, such as data used to train linear regression models, which can be generated by functions.Copy the code

For example, click into the data of Housing price in Boston, you can see the total number of samples, attributes, label and other information.Copy the code

If the data is generated by yourself, enter the number of sample, feature, target and so on according to the form of function. Sklearn.datasets. Make_regression (n_samples=100, n_features=100, n_informative=10, n_targets=1, bias=0.0, Effective_rank =None, tail_strength=0.5, noise=0.0, shuffle=True, coef=False, [source] 2/ sklearn <1> import datasets from sklearn. Model_selection Import train_test_split # import LinearRegression from sklearn.linear_model import LinearRegression <2> Store attributes in data_x and category tags in data_y: Boston_data = datasets.load_boston() # load data_x = boston_data.data # feature data_y = boston_data.target # Category tag observe the dataset Print (data_x) print(data_y) divide the total data set into training set and test set, where test_size=0.3, that is, test set accounts for 30% of the total data:  x_train, x_test, y_train, Y_test = train_test_split(data_x,data_y,test_size=0.3) print(y_train) print(y_test) The LinearRegression() method is used to train the training data using the FIT () method. This step completes all the steps of the training. The following model is already the trained model. The data can be directly used to predict the test set. By comparing the predicted value with the real value, it can be seen that the simulated data is approximately correct, but there are some errors, so the prediction will not be completely correct. Model = LinearRegression() # class instantiation model.fit(x_train, Print (x_test) # print(x_test) # print(x_test) #Copy the code