C.W.K.
Stream
Lesson 01 of 10 · published

What Machine Learning Actually Is

~32 min · foundation, machine-learning, framing

Level 0Scout
0 XP0/48 lessons0/11 achievements
0/120 XP to next level120 XP to go0% complete

The four-piece contract

Machine learning is not a magic box that turns data into answers. It is a contract among four pieces: a target you want to predict, the features you are allowed to use at prediction time, the data that pairs the two for training, and the metric that decides whether the model helped. Break any one piece and the model only looks smart on the notebook screen.

What learning means in code

A learning algorithm changes parameters so a loss on training examples decreases. The hope is that the same parameters also produce good predictions on examples the model has never seen. That hope is not automatic. It depends on the examples being representative, the target being well-defined, and the features being legal at prediction time.

What it looks like in production

In production, the model is one box in a much larger pipeline: feature extraction, scoring, threshold, decision, logging, monitoring, and feedback. The model card belongs in the same repo as the deploy script. If the team cannot point at the artifact and the metric on the same page, the project is not really ML yet.

Common failure

Treating the validation score as proof of intelligence. A 0.97 ROC-AUC on a notebook split tells you nothing if the features included post-event information or if the production data drifted away from the training distribution.

Code

Write the learning contract before importing sklearn·python
contract = {
    "target": "will_churn_within_30_days",
    "prediction_time": "end of each calendar day",
    "legal_features": [
        "plan_tier",
        "tenure_days",
        "tickets_last_30d",
        "logins_last_7d",
    ],
    "metric": "PR-AUC, with recall >= 0.70 on high-risk users",
    "baseline": "current rules-based churn flag",
    "action_if_positive": "send retention offer next morning",
}
assert contract["baseline"], "every ML project needs a baseline to beat"
A minimal first model that respects the contract·python
from sklearn.linear_model import LogisticRegression
from sklearn.model_selection import train_test_split
from sklearn.metrics import average_precision_score

X = customers[contract["legal_features"]]
y = customers[contract["target"]]

X_tr, X_te, y_tr, y_te = train_test_split(
    X, y, test_size=0.2, stratify=y, random_state=7
)
model = LogisticRegression(max_iter=200).fit(X_tr, y_tr)
pr_auc = average_precision_score(y_te, model.predict_proba(X_te)[:, 1])
print(f"baseline beat? PR-AUC={pr_auc:.3f}")

External links

Exercise

Pick one prediction problem at work or in a hobby project. Write the four-piece contract (target, features-at-prediction-time, dataset, metric) plus the baseline you would have to beat. If you cannot name a baseline, ML is the wrong tool right now.

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.