Scikit-learn's genius is consistency: every model, transformer and pipeline shares the same handful of methods. Learn the interface once and every one of the hundreds of algorithms works the same way.
The core methods
| Method | Does |
|---|---|
fit(X, y) | Learn from data (train) |
predict(X) | Predict targets for new data |
transform(X) | Transform data (scalers, encoders) |
fit_transform(X) | Fit then transform in one step |
score(X, y) | Default performance metric |
predict_proba(X) | Class probabilities (classifiers) |
# X = features: a 2-D array/DataFrame, shape (n_samples, n_features)# y = target: a 1-D array/Series, shape (n_samples,)model.fit(X_train, y_train)model.score(X_test, y_test) # R² for regressors, accuracy for classifiers
Key takeaways
- 01Every scikit-learn object shares one interface: fit, predict/transform, score.
- 02X is 2-D features (n_samples × n_features); y is the 1-D target.
- 03fit_transform combines fitting and transforming; predict_proba gives class probabilities.
- 04Learn the API once and every algorithm works the same way.
