September 2019
Intermediate to advanced
420 pages
10h 29m
English
Now let's create a LinearRegression model that we will then train on the training set:
In [19]: linreg = linear_model.LinearRegression()
In the preceding command, we want to split the data into training and test sets. We are free to make the split as we see fit, but usually it is a good idea to reserve between 10 percent and 30 percent for testing. Here, we choose 10 percent, using the test_size argument:
In [20]: X_train, X_test, y_train, y_test = train_test_split(... boston.data, boston.target, test_size=0.1,... random_state=42... )
In scikit-learn, the train function is called fit but otherwise behaves exactly the same as in OpenCV:
In [21]: linreg.fit(X_train, y_train)Out[21]: LinearRegression(copy_X=True, fit_intercept=True, ...
Read now
Unlock full access