Features, targets, and estimator basics
scikit-learn 1.9.1
Identify what the model sees, what it should predict, and how scikit-learn fits estimators.
On this page
Define X and y
X is usually shaped as samples by features. y often contains one target per row. Regression predicts numerical values and classification predicts labels. Clustering groups rows without a labeled target.
import pandas as pd
homes = pd.DataFrame({"area_m2": [52, 64, 75], "bedrooms": [1, 2, 2], "price_k": [116, 153, 165]})
X = homes[["area_m2", "bedrooms"]]
y = homes["price_k"]
print(X.shape, y.shape)
Example output
(3, 2) (3,)
Fit, predict, and transform
fit learns from data. Predictive estimators use predict on new inputs. Transformers such as scalers learn parameters on training rows and apply them with transform. Keep features available at the moment a real prediction will be made.