Python 6.3Code walkthrough8 parts

The Estimator Pattern

Write a tiny model class with `fit` and `predict`, the shape every scikit-learn model has.

Loading your progress…Next: 7.1 Time and Space Complexity

In this lesson8 parts

  1. 01The shape every model has
  2. 02fit stores what the model learns
  3. 03The trailing underscore
  4. 04A model with a setting
  5. 05Changing k
  6. 06The same numbers as scikit-learn
  7. 07Where estimators mislead
  8. 08Recap, your challenge, and the module

Key terms

The words this lesson introduces, each in one line. The module’s glossary collects them all.

estimator
An object that learns from data in fit and answers in predict. Every scikit-learn model is one.
fit
The method that learns from examples. It stores what it learned in attributes ending in _, and returns self.
hyperparameter
A setting of a model chosen before training, not learned in fit: k in KNNRegressor(k=2).
predict
The method that gives answers for new inputs, using what fit learned.

Quiz 5 questions

Your first pick on each question is the one that counts, and a right one earns a coin. Getting one wrong here is how the lesson sticks.

Practice

Problems to solve in your own notebook. Each states the problem, not the steps: working out the steps is the exercise. Level A applies the lesson, B combines it with earlier ones, C stretches it.

The self-checking notebook for this lesson is Notebook 2 · The Estimator Pattern.

Common mistakes

What you will see when it goes wrong, why it happens, and the fix.

Where it’s used

Where this lesson’s ideas turn up in real work.