intermediate30 min
Supervised Learning
Classification and regression — train your first model with scikit-learn
Classification: Predicting Categories
Classification assigns data points to discrete categories. Common algorithms: Logistic Regression, Decision Trees, Random Forest, SVM.
Building a Classifier with scikit-learn
Output
Run your code to see output here
Precision, Recall, and F1-Score
| Metric | What It Measures |
|---|---|
| Precision | Of all predicted positives, how many were actually positive? |
| Recall | Of all actual positives, how many did we find? |
| F1-Score | Harmonic mean of precision and recall — balances both |
| Accuracy | Overall correct predictions / total predictions |
Regression: Predicting Numbers
Regression predicts continuous values. Common algorithms: Linear Regression, Ridge, Lasso, Random Forest Regressor.
Output
Run your code to see output here
Overfitting vs Underfitting
- Overfitting: Model memorizes training data but fails on new data (high variance)
- Underfitting: Model is too simple to capture patterns (high bias)
- The goal: Find the sweet spot — good generalization to unseen data
Check Your Understanding
If a model has 99% accuracy on training data but only 70% on test data, it's likely:
Exercise
Using the pattern above, train a LogisticRegression model on the same iris dataset and print the accuracy score.
Python will load on first run