scikit-learn

1.8.0 · active · verified Wed Mar 25

Standard Python machine learning library. Consistent fit/predict/transform API across estimators. Current version is 1.8.0 (Dec 2025). Requires Python >=3.11. Import name is sklearn (not scikit_learn). The sklearn PyPI package is deprecated — install with pip install scikit-learn.

Warnings

Install

Imports

Quickstart

Correct pattern: Pipeline + train/test split. Always use random_state for reproducibility.

from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
from sklearn.linear_model import LogisticRegression
from sklearn.pipeline import Pipeline
from sklearn.metrics import accuracy_score

X, y = load_iris(return_X_y=True)
X_train, X_test, y_train, y_test = train_test_split(
    X, y, test_size=0.2, random_state=42
)

pipe = Pipeline([
    ('scaler', StandardScaler()),
    ('clf', LogisticRegression(random_state=42))
])
pipe.fit(X_train, y_train)

print(accuracy_score(y_test, pipe.predict(X_test)))

view raw JSON →