Machine Learning Basics: Build Your First Prediction Model

You build one model from the first lesson to the last: it reads a sample table of 7,043 phone company customers, published by IBM, and predicts who will leave. Each lesson adds one working step: split the data, train a first decision tree, measure it with more than accuracy, catch it memorising, cross-validate, add logistic regression, prepare text and blank values in a pipeline, try gradient boosting, test once and explain it. You need basic Python; the few pandas calls used are explained as they appear.

What this course covers

  1. Turn a Customer Table into a Prediction Question: Explain what a machine learning model learns from a table of past examples, and name the features, the label and the share of each answer in a table loaded with pandas.
  2. Hold Out Data the Model Never Sees: Split a table into training, validation and test parts that keep the same share of each answer and come out the same on every run, and explain what each part is for.
  3. Train a First Model: a Small Decision Tree: Train a small decision tree with fit and predict, read the questions it learned, and judge its accuracy against a baseline that always gives the most common answer.
  4. Measure What Accuracy Hides: Read a confusion matrix, compute precision and recall from it, and explain why accuracy alone flatters a model when one answer is rare.
  5. Spot Overfitting: Detect overfitting by comparing a model's score on its training rows with its score on validation rows as the model is allowed to grow, and name underfitting at the other end.
  6. Choose a Setting with Cross-Validation: Score a model with k-fold cross-validation, read the mean and spread of the fold scores, and use them to choose a setting without touching the test set.
  7. A Second Model: Logistic Regression: Train a logistic regression, explain how it turns a weighted sum of the features into a probability, and read the weights it learned and the probability it gives each row.
  8. Prepare Features: Text Categories and Blank Values: Turn text categories into numbers with one-hot encoding, find and fill missing values from the reason they are missing, and show what a model gains from the columns it could not use before.
  9. Scaling and Pipelines: Preparation That Stays Honest: Standardize features so that logistic regression trains properly, join preparation and model into one pipeline, and explain how that keeps held-out rows out of the preparation.
  10. Gradient Boosting: Does a Stronger Model Win?: Train a gradient boosting model, explain how it builds many small trees one after another, compare it fairly with the simpler models, and choose between models whose scores are close.
  11. The Final Test: One Honest Number: Refit the chosen model on every row that is not test data, measure it once on the test set, and judge whether the result agrees with what cross-validation promised.
  12. Explain the Model in Plain Words: Measure which features a trained model relies on with permutation importance, put the result in plain words, and say what such an explanation cannot claim.