Fit the first model

Learn scikit-learn’s small, repeatable interface.

10 minutes. Mission: train a first useful classifier.

Four verbs

from sklearn.tree import DecisionTreeClassifier

model = DecisionTreeClassifier(max_depth=3, random_state=42)
model.fit(X_train, y_train)
predictions = model.predict(X_valid)
probabilities = model.predict_proba(X_valid)[:, 1]

An estimator stores learned state during fit, then applies it during predict. Fixed random_state makes stochastic choices reproducible.[1]

Keep the first model boring

A shallow tree gives a fast sanity check. Confirm row counts, target direction, score above baseline, and plausible predictions before tuning. A sophisticated model cannot rescue the wrong target or leaked data.

Predict the failure: what happens if fit receives the validation rows too?

Check retrieval

Win: you can read and write the core estimator lifecycle from memory.

Primary source

Run the estimator example in scikit-learn’s Getting Started guide.