ADVERTISEMENT
Google AdSense Slot (headerLeaderboard)

Set your Publisher ID in src/config/ads.ts to display live ads.

Machine Learning with Python Tutorial• 6 min read

The Machine Learning Lifecycle & Scikit-Learn

Data ingestion, EDA, feature matrix X, target vector y, and the Estimator API

Machine learning algorithms build mathematical models from sample training data to make predictions or decisions without being explicitly programmed with rigid deterministic rules.

The Scikit-Learn Estimator API

Feature Matrix X: A 2D array of shape (n_samples, n_features) holding numeric predictors.

Target Vector y: A 1D array of shape (n_samples,) containing the ground truth labels or continuous values.

The Consistent API: All Scikit-Learn models implement model.fit(X, y) to train and model.predict(X_new) to make inference predictions.

Scikit-Learn Minimal Model Workflow
from sklearn.linear_model import LinearRegression
import numpy as np

# Feature matrix X: 2D array of hours studied
X = np.array([[1.0], [2.0], [3.0], [4.0], [5.0]])

# Target vector y: 1D array of exam scores
y = np.array([55, 63, 72, 85, 94])

# 1. Instantiate model
model = LinearRegression()

# 2. Train model (Estimator API)
model.fit(X, y)

# 3. Predict for a student who studied 6 hours
prediction = model.predict([[6.0]])
print(f"Predicted score for 6 hours: {prediction[0]:.1f}")
All Scikit-Learn algorithms share this consistent fit/predict interface.
ADVERTISEMENT
Google AdSense Slot (inContentBanner)

Set your Publisher ID in src/config/ads.ts to display live ads.

Test Yourself With Exercise

+15 XP

Which method in Scikit-Learn is universally used to train an estimator model on data?