Python exercise · about 5 minutes · free
Cross-Validation
One lucky test split can flatter a model. Cross-validation tests it on five different splits.
cross_val_score(model, X, y, cv=5) trains and scores 5 times, each time holding out a different fifth of the data. Report the mean and the spread.
Your quest: Run 5-fold cross-validation of
LogisticRegression(max_iter=1000) on the iris data. Set scores and mean_score.Try it now Runs in your browser. No sign-in needed. Ctrl+Enter to run.
Hint
scores = cross_val_score(LogisticRegression(max_iter=1000), X, y, cv=5); mean_score = scores.mean()Output appears here.