scikit-learn
Machine learning library for Python with consistent fit-predict APIs, pipelines and model evaluation tools.
Official Documentation ↗scikit-learn 1.4+ / Python 3.9+. Check the official docs for the latest API surface.Installation
pip install scikit-learnMethods
No methods match this filter.
Overview
scikit-learn provides consistent, composable machine learning estimators that share fit, predict and transform methods, along with preprocessing, pipelines and evaluation utilities.
Core Methods
Split data, build estimators and pipelines, fit on training data, and evaluate with metrics or cross-validation. Grid and randomized search tune hyperparameters systematically.
Usage Notes
Encapsulate preprocessing in pipelines so transforms apply identically in training and inference. Scale features where algorithms are distance-based, and validate with cross-validation.
Common Pitfalls
Fitting preprocessing on the whole dataset leaks information and inflates scores. Some estimators assume scaled inputs and silently perform poorly otherwise. Choosing metrics inconsistent with the problem hides real quality differences.
FAQ
- How do I avoid data leakage?
- Fit transformers only on training data and apply them to test data, which pipelines handle automatically. Fitting a scaler on the full dataset leaks test statistics into training.
- What does random_state do?
- It seeds any randomness in the estimator or splitter so results are reproducible. Set it for experiments and cross-validation so comparisons are fair.
- What is cross-validation for?
- It estimates generalization by training and evaluating on multiple folds. Use it to tune hyperparameters and compare models instead of relying on a single split.
Report a problem with this API docOpens a pre-filled issue on GitHub.