cross_validate and how it works, but now I am confused about what
cross_val_score actually does. Can anyone give me some example?
cross_val_score is a helper function on the estimator and the dataset.
Would explain it with an example:
>>> from sklearn.model_selection import cross_val_score >>> clf = svm.SVC(kernel='linear', C=1) >>> scores = cross_val_score(clf, iris.data, iris.target, cv=5) >>> scores array([ 0.96..., 1. ..., 0.96..., 0.96..., 1. ])
This example demonstrates how to estimate the accuracy of a linear kernel support vector machine on the iris dataset by splitting the data, fitting a model and computing the score 5 consecutive times (with different splits each time)
cross_validate function differs from
cross_val_score in two ways -
- It allows specifying multiple metrics for evaluation.
- It returns a dict containing training scores, fit-times and score-times in addition to the test score.
Note: When the cv argument is an integer,
cross_val_score uses the KFold or StratifiedKFold strategies by default, the latter being used if the estimator derives from ClassifierMixin
You can go through this link for better understanding
Different examples using
cross_val_score, you can go through about its different implementations.