Machine Learning Basics
What machine learning is: supervised and unsupervised learning, classification versus regression, features and targets, and the fit/predict workflow.
4 questions
JuniorTheoryCommonHow do you decide whether a task is classification or regression?
How do you decide whether a task is classification or regression?
By the target, not the model: a target that is a category, even one stored as 0, 1, 2, makes it classification, and a continuous number such as a price makes it regression. Logistic regression is a classifier despite its name.
Common mistakes
- ✗Calling logistic regression a regression model because of its name — it outputs a class probability and predicts a class label, so it solves classification.
- ✗Treating class ids stored as numbers (0, 1, 2) as a regression target — they only name categories, so their order and the gaps between them mean nothing.
Follow-up questions
- →Which task type is predicting a star rating from 1 to 5, and what changes with each choice?
- →Why can a regression model's output still be turned into a class with a threshold?
JuniorTheoryCommonTo learn if a client will repay, a bank has income, age, debt and repaid — what role does each play?
To learn if a client will repay, a bank has income, age, debt and repaid — what role does each play?
income, age and debt are features, the inputs the model reads for every client; repaid is the target, the answer it learns from examples and predicts for new clients
Common mistakes
- ✗Thinking a yes/no column cannot be the target: whatever column the model learns to predict is the target, whether it holds numbers or categories.
- ✗Picking the target by its place in the table: the task decides it, so the column you need predicted for new rows is the target wherever it sits.
Follow-up questions
- →Why must a feature be known at prediction time, and what goes wrong with a column filled in only after the outcome?
- →Why are the features written as a two-dimensional table
Xand the target as a one-dimensionaly?
JuniorTheoryCommonWhat do fit and predict do, and what does a score on the training rows tell you?
What do fit and predict do, and what does a score on the training rows tell you?
fit(X_train, y_train) learns the model parameters from rows with a known target, and predict(X_new) applies them to rows without one. A high score on the training rows says little about how the model does on new data.
Common mistakes
- ✗Trusting a high training score — the model has already seen those rows and their targets, so only a score on held-out rows estimates quality on new data.
- ✗Expecting
predictto keep learning — it only applies the parametersfitstored, and the model changes only whenfitis called again.
Follow-up questions
- →Why must a scaler be fitted on the training rows only, and then only applied to the test rows?
- →What does
fit_predictreturn for a clustering model, and why is there no separatepredictstep?
JuniorTheoryCommonHow does supervised learning differ from unsupervised learning?
How does supervised learning differ from unsupervised learning?
Supervised learning trains on examples paired with a known target, such as a price or a spam label, and learns to predict it. Unsupervised learning gets no target and finds structure in the features alone, such as clusters.
Common mistakes
- ✗Thinking unsupervised means no human sets anything up — people still choose the features, the algorithm and settings such as the number of clusters; only the target is missing.
- ✗Expecting clustering to need labeled examples — it groups rows by feature similarity alone, and a label column, if one exists, is not used to fit it.
Follow-up questions
- →Where does semi-supervised learning sit between the two, and when is it worth using?
- →How would you judge a clustering result when there are no labels to compare against?