Evaluación de scores con cross_val_score — 2:45#

  • Ultima modificación: 2023-02-27 | YouTube

  • Evalua una medida de score usando cross-validation.

[1]:
import numpy as np
from sklearn import datasets, linear_model
from sklearn.model_selection import cross_val_score

diabetes = datasets.load_diabetes()
X = diabetes.data[:150]
y = diabetes.target[:150]

lasso = linear_model.Lasso()

cross_val_score(
    # -------------------------------------------------------------------------
    # The object to use to fit the data. Must implement fit()
    estimator=lasso,
    # -------------------------------------------------------------------------
    # The data to fit. Can be for example a list, or an array.
    X=X,
    # -------------------------------------------------------------------------
    # The target variable to try to predict in the case of supervised learning.
    y=y,
    # -------------------------------------------------------------------------
    # Group labels for the samples used while splitting the dataset into
    # train/test set. Only used in conjunction with a “Group” cv instance
    # (e.g., GroupKFold).
    groups=None,
    # -------------------------------------------------------------------------
    # Determines the cross-validation splitting strategy.
    cv=3,
    # -------------------------------------------------------------------------
    # The verbosity level.
    verbose=0,
    # -------------------------------------------------------------------------
    # Parameters to pass to the fit method of the estimator.
    fit_params=None,
    # -------------------------------------------------------------------------
    #
    error_score=np.nan,
)
[1]:
array([0.3315057 , 0.08022103, 0.03531816])