Model Evaluation with Accuracy and Score Methods
What you'll learn: How to quickly evaluate your trained model's performance using scikit-learn's built-in .score() method and understand what metric it uses automatically.
The Quick Way to Check Model Performance
After fitting a model in scikit-learn, you need to know: how well does it work? The .score() method gives you an instant performance measurement with a single line of code.
Think of .score() as your model's report card—it takes your test data (features and true labels) and returns a number telling you how well your model performed. But here's the key: what that number means depends on whether you're doing classification or regression.
Classification vs Regression: Different Default Metrics
When you call .score() on a classifier (like the models you've been fitting), it returns accuracy—the percentage of predictions that were correct. If you predict 85 out of 100 labels correctly, you get a score of 0.85.
# After fitting a classifier
accuracy = model.score(X_test, y_test)
# Returns: fraction of correct predictions (0.0 to 1.0)
When you call .score() on a regressor (predicting continuous numbers), it returns the R² score (coefficient of determination)—a measure of how well your predictions match the actual values, where 1.0 is perfect and values can even be negative for very poor models.
# After fitting a regressor
r2_score = model.score(X_test, y_test)
# Returns: R² score (1.0 is perfect, can be negative)
Why This Matters
The .score() method is your first-line evaluation tool—quick, simple, and built-in. It's perfect for rapid iteration and comparing models during development.
Key Takeaway: Use .score() for quick model evaluation; it automatically returns accuracy for classifiers and R² for regressors, giving you an instant performance measurement without importing additional metrics.