ML Fundamentals: lesson 5 of 7
ML Fundamentals
Training, Inference, and the Machine Learning Workflow
Understand what happens during model training, what inference means, and why machine learning is iterative.
Concept
Lesson 4 used fit() and predict(). These methods represent two different phases. Training uses known feature rows and targets to learn model parameters. Inference uses a trained model and new feature rows to produce an output when the real target is unknown.
Training Versus Inference
For house prices, training receives X_train and known y_train prices. model.fit(X_train, y_train) adjusts the model to capture a relationship in those examples. At inference time, a new house has size and bedrooms but no known sale price yet: new_X -> trained model -> prediction. predict() applies learned parameters; it does not continue training.
For churn, training uses past customer features and known churn outcomes. A future prediction uses current customer features because future churn has not happened yet. This is why target information is available during supervised training but must not be supplied at prediction time.
The Workflow
- Define the decision and target.
- Collect and understand the relevant data.
- Select valid features and split data.
- Prepare features consistently.
- Choose a baseline or model.
- Train, evaluate, and investigate errors.
- Iterate on the problem, data, or model.
- Use the chosen model for inference.
The workflow is not “train once, done.” A weak result may reveal a poor target definition, missing data, a feature problem, or an unsuitable model. Later modules teach preprocessing, baselines, evaluation, and error analysis in depth.
Operational Example: Churn Risk
During training, a subscription company uses historical customers with tenure, contract type, monthly charges, and support calls. It also knows whether each customer later churned. The model learns a relationship between those historical inputs and outcomes.
During inference, the company sends current features for an active customer. It does not send the future churn outcome, because that is exactly what is unknown. The output might be a churn probability or class that supports a retention decision. Calling predict() does not update the model from that customer; updating requires a separate training process with appropriately labeled data.
Training-Time and Prediction-Time Consistency
Any preparation applied during training must be applied the same way to new rows. If training converts categories or scales a numeric feature, inference cannot silently use a different representation. The target is never an inference input, and a production prediction does not normally retrain the model for every row.
A Simple Baseline
A baseline is a simple reference prediction or model that gives a team something to beat, such as always predicting the most common class. It is introduced here as a comparison point; later lessons explain how to choose and evaluate baselines carefully.
Failure Signals
Common Mistakes
- Thinking
predict()learns from new rows. - Judging a model only by training performance.
- Preparing new data differently from training data.
- Including an outcome or future information in prediction features.
- Assuming successful code creates a useful decision system.
Best Practices
Document the target time, available features, transformation steps, and intended decision. Keep training and inference separate in your mental model, then validate the model on examples it did not train on.
Interview Perspective
Question: What is the difference between training and inference? Answer: training learns parameters from examples with known targets; inference applies those learned parameters to new features with unknown outcomes. Follow-up: why must preprocessing be consistent?
Practice Questions
- In a churn model, what belongs in training but is unavailable during future inference?
- Why is calling
predict()not additional training? - List two reasons an ML workflow may need another iteration.
Quick Quiz
- Which method represents training in scikit-learn? Answer:
fit(). - Is y normally available for a future prediction? Answer: no.
- Is ML workflow one-pass? Answer: no.
Key Takeaway
Key Takeaways
Training learns from X and y; inference applies the learned model to new X. Useful ML requires an iterative workflow and consistent data handling across both phases.
Next Lesson
Next, learn why unseen data is the real test of a model.
Finish this lesson on your terms
Mark it complete when you have worked through the material and are ready to move on.