
# Load libraries
from sklearn.datasets import make_regression
from sklearn.model_selection import cross_val_score
from sklearn.linear_model import LinearRegression
# Generate features matrix, target vector
features, target = make_regression(n_samples = 100,
                                     n_features = 3,
                                     n_informative = 3,
                                     n_targets = 1,
                                     noise = 50,
                                     coef = False,
                                     random_state = 1)

# Create a linear regression object
ols = LinearRegression()
# Cross-validate the linear regression using (negative) MSE
print(cross_val_score(ols, features, target, scoring='neg_mean_squared_error'))

# Cross-validate the linear regression using R-squared
print(cross_val_score(ols, features, target, scoring='r2'))














































