Have labels --> Categories --> Classification || Regression
X = features / predictors / input evidence
y = target variable / outcome / labelIn Get Smart terms:
X = what we know about the recipe
y = what we want to decideExample:
X:
- ingredient_line_count
- primary_ingredient_count
- seasoning_count
- missing_quantity_count
- lookup_match_count
- has_servings
y:
- READY
- REVIEW_REQUIRED
fit and predict
model.fit(X_train, y_train)
y_pred = model.predict(X_test)
fit = learn from examples
predict = use what was learned on new examples
Tiny kitchen-machine version:
fit:
"Here are 100 recipe records. Learn what READY and REVIEW_REQUIRED tend to look like."
predict:
"Here are 20 new recipe records. Tell me which bucket each one belongs in."
Are fit and predict ever combined?
Sometimes, but not usually for basic classification.
You may see commands like:
model.fit_predict(X)
But that is more common in clustering or unsupervised learning, where there may be no y.
clusters = kmeans.fit_predict(X)Learn the clusters and assign each row to a cluster.
For our initial classification work, keep it boring and explicit:
model.fit(X_train, y_train)
predictions = model.predict(X_test)Boring is good here. Boring is where the floorboards stop wobbling.
Train/test split
training data = examples the model learns from
test data = examples held back to check whether it learned anything useful
So instead of letting the model study the answer key and then brag, we do this:
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(
X,
y,
test_size=0.2,
random_state=42
)
Use 80% of the data to train.
Use 20% to test.
Use random_state=42 so the split is repeatable.
Classification
Classification means the model predicts a category, not a number.
For Get Smart:
READY vs REVIEW_REQUIREDThat is classification.
Other examples:
primary ingredient vs seasoning
complete recipe vs partial recipe
soup vs pasta vs saladAccuracy
Accuracy asks:
What percentage did the model get right?Example:
20 test recipes
16 predicted correctly
accuracy = 16 / 20 = 0.80So accuracy is:
80%Good, but not the whole story.
Confusion matrix
The confusion matrix shows how the model was wrong.
For Get Smart:
|
Predicted READY |
Predicted REVIEW |
|
|---|---|---|
|
Actually READY |
correct |
annoying false alarm |
|
Actually REVIEW |
🛑 dangerous miss |
correct |
The most important bad case is:
Actually REVIEW, predicted READYBecause that means the system might pass a recipe forward when it should have stopped for human review.
That fits your whole Get Smart principle:
No confidence without traceability.
The simplest mental model
X = clues
y = answer
fit = learn clue patterns
predict = guess answers for new rows
train/test split = do not test on the same rows you learned from
classification = choose a category
accuracy = how often correct
confusion matrix = what kind of wrongFor your first real scikit-learn bite, the whole thing can be:
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import accuracy_score, confusion_matrix
X = recipe_features
y = recipe_labels
X_train, X_test, y_train, y_test = train_test_split(
X, y, test_size=0.2, random_state=42
)
model = LogisticRegression()
model.fit(X_train, y_train)
predictions = model.predict(X_test)
print(accuracy_score(y_test, predictions))
print(confusion_matrix(y_test, predictions))
That is the first little ML engine. Not glamorous. Very useful. Tiny tractor, not spaceship. 🚜