9951 explained code solutions for 126 technologies


python-scikit-learnHow to evaluate a score by cross validation based on cross_val_score()


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()

cvs = cross_val_score(lasso, X, y)ctrl + c
from sklearn import

import module from scikit-learn

datasets.load_diabetes

loads sample diabetes database

linear_model.Lasso

creates Lasso model

cross_val_score(

evaluates a score by cross-validation

lasso

model to use for cross-validation


Usage example

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()

cvs = cross_val_score(lasso, X, y)
print(cvs)
output
[0.29828675 0.2241492  0.15480127 0.25519733 0.17108715]