A model is an object with a contract
Everything in scikit-learn is an estimator, and every estimator follows the same contract. You create it with its settings, called hyperparameters, for example the strength of a penalty. You call so that it learns from data. What it learned is stored in attributes whose names end with an underscore, such as the mean or the coefficients. Then you use it: a preprocessor offers , a model offers . The call is fit followed by transform. The table has one row per sample and one column per feature, and is the target. Because the contract is the same everywhere, you can swap a model for another and keep the rest of your code.
The golden rule is that may only see training data. The numbers a preprocessor learns, such as and , are then applied unchanged to validation and test data by . If you fitted the scaler on all days, the test days would have shaped the scaling, which is a quiet leak of the future. Settings such as make runs repeatable, and builds a fresh unfitted copy of an estimator, which is what cross-validation does for every fold. In the market-data labs of this skill, rows are stock-months and columns are features such as momentum and volatility.
- Settings in, numbers learned: hyperparameters go into the constructor, learned numbers end with an underscore.
- Fit on training only: transform and predict reuse the learned numbers on any data.
- Same contract everywhere: swapping a model for another keeps the rest of your code.
Lab · what's graded
- What the scaler learns: the mean10 pts
- What the scaler learns: the spread10 pts
- Transform a test value10 pts
- What the regression learns: the slope15 pts
- A prediction10 pts
- Which attributes are learned10 pts
- A safe workflow10 pts
- Match the vocabulary10 pts
- Why fit the scaler on training data only15 pts