scikit-learn-stubs

raw JSON →
0.0.3 verified Fri May 01 auth: no python

Type stubs for scikit-learn, providing static type information for type checkers like mypy and pyright. Current version 0.0.3, updated 2025; low release cadence. Maintained by Microsoft via the python-type-stubs repository, forked by hoel-bagard.

pip install scikit-learn-stubs
error Cannot find implementation or library stub for module 'sklearn'
cause The stubs package is not installed or not compatible with the installed scikit-learn version.
fix
Run: pip install scikit-learn-stubs
error Module 'sklearn.linear_model' has no attribute 'LogisticRegression'
cause Outdated stub files missing some estimators; or incorrect scikit-learn version.
fix
Upgrade scikit-learn and stubs: pip install --upgrade scikit-learn scikit-learn-stubs
gotcha Stubs may not cover all scikit-learn modules or parameters, especially experimental ones. Use strict type checking cautiously.
fix Check the stub coverage in the repository before relying on types for rarely used estimators.
deprecated The original Microsoft python-type-stubs repository is archived. This fork may become outdated relative to new scikit-learn releases.
fix Consider using the official scikit-learn type stubs from scikit-learn itself (if available in future) or contribute to this fork.
breaking Version 0.0.x is pre-1.0. Breaking changes in stub types may occur between minor versions.
fix Pin exact version in requirements: scikit-learn-stubs==0.0.3

Basic scikit-learn usage with type stubs enabled. The stubs are automatically discovered by mypy/pyright when installed.

from sklearn.linear_model import LogisticRegression
import numpy as np

# Example usage with type hints (stubs enable type checking)
model: LogisticRegression = LogisticRegression()
X = np.array([[0, 0], [1, 1]])
y = np.array([0, 1])
model.fit(X, y)
print(model.predict([[0.5, 0.5]]))