35 — Python Power Tools

scikit-learn Evaluation Suite#

Python✓ Mathematical
◆ The PatternThe Swiss army knife — classification_report, cross_val_score, learning_curve, and the metrics module

scikit-learn includes everything covered in this toolkit under one roof. The metrics module has every scorer, model_selection has every CV strategy, and inspection has permutation importance and partial dependence.

// The scikit-learn evaluation workflow
# Complete sklearn evaluation workflow
from sklearn.model_selection import (
    cross_val_score, learning_curve, GridSearchCV
)
from sklearn.metrics import (
    classification_report, confusion_matrix,
    roc_auc_score, mean_squared_error
)
from sklearn.inspection import permutation_importance

# 1. Cross-validated scores
scores = cross_val_score(model, X, y, cv=5, scoring='f1')

# 2. Full classification report
model.fit(X_train, y_train)
print(classification_report(y_test, model.predict(X_test)))

# 3. Learning curves
sizes, train_s, val_s = learning_curve(model, X, y, cv=5)

# 4. Feature importance
pi = permutation_importance(model, X_test, y_test, n_repeats=30)

# 5. Hyperparameter tuning
grid = GridSearchCV(model, param_grid, cv=5, scoring='f1')
grid.fit(X_train, y_train)
ModuleKey functionsThis toolkit topic
sklearn.metricsclassification_report, roc_auc_score, r2_scoreConfusion Matrix, Regression
sklearn.model_selectioncross_val_score, TimeSeriesSplit, learning_curveCV, Learning Curves
sklearn.inspectionpermutation_importance, PartialDependenceDisplayPermutation, PDP/ICE
sklearn.feature_selectionmutual_info_classif, SelectKBestInformation Gain
Tip: Always use Pipeline to chain preprocessing + model. This prevents data leakage in CV and makes deployment trivial.
← Previous
Funnel & Conversion Analysis
Open in the full reader, with the topic sidebar →