ols_regressor.cross_validate
Module Contents
Functions
|
Perform cross-validated Ordinary Least Squares (OLS) regression. |
- ols_regressor.cross_validate.cross_validate(model, X, y, cv=5, random_state=None)[source]
Perform cross-validated Ordinary Least Squares (OLS) regression.
- Parameters:
model (object) – Name of the model to run cross_validate with (it will be OLS in this case)
X (array-like matrix of shape (n_examples, n_features)) – Dataset that will be used as the feature values to train the model.
y (array-like matrix of shape (n_examples, n_targets)) – Dataset that will be used as the target values to train the model.
cv (int, optional) – Number of cross-validation folds. Default is 5.
random_state (int or None, optional) – Seed for reproducibility. Default is None.
- Returns:
scores – A dictionary containing arrays for train and test scores, fit and score times. ‘train_score’, ‘test_score’, ‘fit_time’, ‘score_time’.
- Return type:
dict
Example
from sklearn.linear_model import LinearRegression X = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]]) y = np.array([13, 14, 15, 16]) model = LinearRegression() scores = cross_validate(model, X, y, cv=5) print(scores) {‘train_score’: […], ‘test_score’: […], ‘fit_time’: […], ‘score_time’: […]}