Train Your First Machine Learning Model in Python
Build, evaluate and interpret a regression model on a small engineering dataset.
Estimated completion: 35 min

Objective
Train a baseline regression model and evaluate it honestly with a held-out test set.
Required knowledge
- Basic Python syntax
Software and tools
- Python 3.11
- scikit-learn
- pandas
Files and resources
- Sample CSV dataset
- Notebook template
Step-by-step instructions
- 1
Load and inspect the data
Read the CSV with pandas and check dtypes, missing values and obvious outliers before modelling.
- 2
Split the data
Hold out 20% of the data for testing before doing anything else, so preprocessing choices cannot leak information.
- 3
Fit a baseline
Start with linear regression. A baseline tells you whether a complex model is actually earning its complexity.
- 4
Try a stronger model
Fit a random forest and compare cross-validated error against the baseline.
- 5
Evaluate and interpret
Report MAE and RMSE, plot residuals against predictions and inspect feature importances.
Expected result
A model with documented test error and a residual plot showing no obvious structure.
Troubleshooting
| Problem | How to fix it |
|---|---|
| Test error much worse than training error | Reduce model complexity or gather more data; you are overfitting. |
| Suspiciously perfect scores | Check for target leakage in your features. |
Final checklist
- Test set held out first
- Baseline compared
- Residuals inspected
- Metrics reported with units