scikit-learn
by scikit-learn
Python library for classic machine learning tasks like classification, regression and clustering.
- Stars
- 68,322 stars
- Forks
- 28k forks
- Last push
- today
- Activity
- Active
# Install with pip$ pip install -U scikit-learn# Or with conda$ conda install -c conda-forge scikit-learnCommands from the project's README. Run them after installing (see below).
Overview
Understand scikit-learn in 60 seconds
- What it does
- scikit-learn is the standard Python library for classic machine learning. It provides dozens of ready-made algorithms for classification, regression and clustering, plus tools for preprocessing data, building pipelines, choosing models and evaluating them, all with one consistent fit and predict API.
- The problem it solves
- Implementing and comparing machine learning algorithms from scratch is slow and error-prone. scikit-learn gives you well-tested estimators and utilities that work the same way, so you can try models quickly on tabular data.
- Why choose it
- Choose it for classic machine learning on structured data with excellent documentation. For deep learning, use a framework like PyTorch or Keras instead.
- Who should use it
- Data scientists working with tabular data
- Students learning machine learning
- Developers adding predictions to apps
- Researchers needing reliable baselines
- Setup difficulty
You'll need:
- Python 3.12+
- NumPy 1.26.0+, SciPy 1.11.4+, Narwhals 2.0.1+, joblib 1.4.0+, threadpoolctl 3.5.0+
- Matplotlib 3.8.0+ for plotting
How scikit-learn works
scikit-learn is built on SciPy and distributed under the BSD 3-Clause license. It started in 2007 as a Google Summer of Code project by David Cournapeau and is maintained by a community of volunteers with support from several organisations.
Every model is an estimator with a fit method; after fitting you call predict on new data. Preprocessors and transformers such as StandardScaler share the same API but use transform, and they can be chained with a final predictor in a pipeline. The library also covers model selection and evaluation.
Install it with pip or conda once NumPy and SciPy are available. Plotting functions need Matplotlib, and some examples need pandas, seaborn, scikit-image or Plotly. Full documentation, a FAQ and a map for choosing the right model are on scikit-learn.org.
Features
Key features
Dozens of algorithms
Classification, regression, clustering and more.
Consistent API
fit, predict and transform everywhere.
Preprocessing
Scaling, imputation and encoding.
Pipelines
Chain preprocessing and models together.
Model selection
Cross-validation and parameter search.
Evaluation
Metrics and plotting displays.
Strengths
- Industry standard for classic ML
- Outstanding documentation
- Stable, well-tested code
- BSD 3-Clause license
Limitations
- Not for deep learning or GPUs
- Requires a recent Python (3.12+)
- Best suited to data that fits in memory
Practical use cases
Predict customer churn
Train a classifier on tabular data.
Baseline models
Compare simple models before trying deep learning.
Data preprocessing
Scale and encode features in a pipeline.
Installation
Install scikit-learn
Commands come from scikit-learn's README and getting started guide. AIRepoHub hasn't run them yet. View source
Prerequisites
- Python 3.12+
- NumPy and SciPy
Supported systems
- Windows
- macOS
- Linux
- 1
Install
Shellpip install -U scikit-learn
- 1
Install from conda-forge
Shellconda install -c conda-forge scikit-learn
Configuration and API keys
| Setting | What it's for |
|---|
First run
- 1
Check the installation
Shellpython -c "import sklearn; print(sklearn.__version__)"
scikit-learn's documentation doesn't include sample output, so we don't show any. Expect the results in your terminal.
Your first project
Fit and predict with your first estimator
Train a random forest on tiny example data, following the getting started guide.
Before you start
- scikit-learn installed
- 1
Fit a classifier
Textfrom sklearn.ensemble import RandomForestClassifierclf = RandomForestClassifier(random_state=0)X = [[ 1, 2, 3], [11, 12, 13]]y = [0, 1]clf.fit(X, y) - 2
Predict on new data
Textclf.predict([[4, 5, 6], [14, 15, 16]]) - 3
Try a preprocessor
Textfrom sklearn.preprocessing import StandardScalerX = [[0, 15], [1, -10]]StandardScaler().fit(X).transform(X)
What to expect
The guide shows the prediction returning array([0, 1]) and the scaler returning standardised values.
Next steps
- Combine steps into a pipeline
- Evaluate with cross-validation
- Use the model selection map on scikit-learn.org
Costs and requirements
What it costs to run
- License
- BSD 3-Clause.Free
- Software
- Free and open source.Free
Troubleshooting
Common setup issues
Install fails
Make sure NumPy and SciPy are installed and Python is 3.12 or newer.
Plotting functions error
Install Matplotlib 3.8.0 or newer.
Want to check your install
Run the test suite with pytest sklearn from outside the source directory.
Alternatives
Similar AI repositories
markitdown
microsoft
Python tool from Microsoft that converts PDFs, Word, Excel, PowerPoint and other files into Markdown for use with AI.
transformers
huggingface
Hugging Face library for defining, running and training machine learning models for text, vision and audio.
langchain
langchain-ai
Framework for building LLM-powered applications and agents.
pytorch
pytorch
Python framework for building and training neural networks with tensors and GPU acceleration.