Skip to content
AIRepoHub

scikit-learn

by scikit-learn

Python library for classic machine learning tasks like classification, regression and clustering.

Developer ToolsPythonBSD-3-Clause license
Stars
68,322
stars
Forks
28k
forks
Last push
today
Activity
Active
scikit-learn: quick start
# Install with pip$ pip install -U scikit-learn# Or with conda$ conda install -c conda-forge scikit-learn

Commands 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

Based on official documentation

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. 1

    Install

    Shell
    pip install -U scikit-learn
  1. 1

    Install from conda-forge

    Shell
    conda install -c conda-forge scikit-learn

Configuration and API keys

SettingWhat it's for

First run

  1. 1

    Check the installation

    Shell
    python -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. 1

    Fit a classifier

    Text
    from sklearn.ensemble import RandomForestClassifierclf = RandomForestClassifier(random_state=0)X = [[ 1,  2,  3],     [11, 12, 13]]y = [0, 1]clf.fit(X, y)
  2. 2

    Predict on new data

    Text
    clf.predict([[4, 5, 6], [14, 15, 16]])
  3. 3

    Try a preprocessor

    Text
    from 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.

Source: README.rst

Plotting functions error

Install Matplotlib 3.8.0 or newer.

Source: README.rst

Want to check your install

Run the test suite with pytest sklearn from outside the source directory.

Source: README.rst

Alternatives

Similar AI repositories