Python machine learning libraries

Updated Nov 2026

Python machine learning libraries train models that make predictions from data. These libraries train the models behind forecasts, recommendations, fraud checks, and classification in apps.

Popularity

scikit-learn has the most installs, while TensorFlow has the most GitHub stars.

LibraryMonthly downloadsStarsLast releaseLicense
scikit-learn
214.2M
68.1KSep 2026BSD-3-Clause
PyTorch
59.7M
105.4KOct 2026NOASSERTION
XGBoost
32.7M
29.0KAug 2026Apache-2.0
LightGBM
23.6M
19.0KJul 2026MIT
JAX
12.6M
36.6KOct 2026Apache-2.0
TensorFlow
12.4M
201.6KMar 2026Apache-2.0
Keras
12.0M
64.4KJul 2026Apache-2.0
CatBoost
6.9M
9.2KFeb 2026Apache-2.0
Downloads: PyPI, last thirty days. Stars and releases: GitHub. Amber: no release in over a year.

Libraries and code examples

scikit-learn is a machine learning module for Python built on NumPy and SciPy, which pip installs alongside it. Every model is an estimator with the same two methods. fit trains the estimator on rows of data, while predict returns its answers for new rows. Classification, regression, clustering, and preprocessing tools all share that interface. A Pipeline uses it to chain a scaler and a model into one estimator that cross-validation can score.

Downloads / mo
214.2M
Stars
68.1K
Last release
1.9.1
License
BSD-3-Clause

Strengths

  • Keeps preprocessing with prediction. Combine transformations and an estimator in a Pipeline.
  • Evaluates models across data splits. Use cross-validation tools to score models on unseen data.

Limitations

  • Saved models need matching versions. Load a saved model with the same scikit-learn version that trained it.

Quickstart

From getting_started.html
$ pip install -U scikit-learn
from sklearn.ensemble import RandomForestClassifier
clf = RandomForestClassifier(random_state=0)
X = [[ 1,  2,  3],  # 2 samples, 3 features
     [11, 12, 13]]
y = [0, 1]  # classes of each sample
clf.fit(X, y)

scikit-learn examples

From open-source projects on GitHub

PyTorch pairs a tensor library with GPU support and an automatic differentiation engine, torch.autograd. The engine records operations as code runs and replays them backward to compute gradients. Neural network layers come from torch.nn, while DataLoader in torch.utils feeds batches during training. A model can change its structure from one input to the next, which the README contrasts with frameworks that fix a network before training. The install command differs for CUDA, ROCm, and CPU builds, so a selector on the PyTorch site generates it.

Downloads / mo
59.7M
Stars
105.4K
Last release
2.15.0
License
NOASSERTION

Strengths

  • Supports custom training loops. Combine neural-network modules and automatic differentiation in a custom training loop.
  • Runs tensor operations on GPUs. Move tensors to CUDA devices for GPU execution.

Limitations

  • Layers and loops only. Training loops, early stopping, and checkpointing are written by hand or added through a library such as Lightning.

Quickstart

From tensorqs_tutorial.py
$ pip install torch torchvision
import torch

data = [[1, 2],[3, 4]]
x_data = torch.tensor(data)

PyTorch examples

From open-source projects on GitHub

XGBoost trains gradient-boosted decision trees on one machine or across Kubernetes, Hadoop, Dask, or Spark. XGBClassifier and XGBRegressor follow the scikit-learn fit and predict interface, so they work inside scikit-learn pipelines. Tree boosters learn which branch missing values take during training, so gaps in the data need no filling first. Like LightGBM, XGBoost builds trees from histograms of each feature when tree_method is set to hist.

Downloads / mo
32.7M
Stars
29.0K
Last release
3.4.1
License
Apache-2.0

Strengths

  • Learns routes for missing values. Tree boosters learn where missing values go during training.
  • Recodes categories during inference. Dataframe inputs retain category encodings for prediction and continued training.

Limitations

  • Categories need JSON or UBJSON. Save categorical models as JSON or UBJSON to retain category information.

Quickstart

From sklearn_estimator.html
$ pip install xgboost
from sklearn.datasets import load_breast_cancer
from sklearn.model_selection import train_test_split

import xgboost as xgb

X, y = load_breast_cancer(return_X_y=True)
X_train, X_test, y_train, y_test = train_test_split(X, y, stratify=y, random_state=94)

# Use "hist" for constructing the trees, with early stopping enabled.
clf = xgb.XGBClassifier(tree_method="hist", early_stopping_rounds=2)
# Fit the model, test sets are used for early stopping.
clf.fit(X_train, y_train, eval_set=[(X_test, y_test)])

XGBoost examples

From open-source projects on GitHub

LightGBM is a gradient boosting framework, first released by Microsoft and now maintained at lightgbm-org. Before searching for splits, the library buckets each feature's values into histograms to lower memory use. Trees grow one leaf at a time, choosing the leaf with the largest drop in loss. On small datasets that growth can overfit, so the docs suggest capping max_depth. In Python, lgb.Dataset wraps the training arrays and labels, with categorical columns kept as integer codes instead of one-hot columns.

Downloads / mo
23.6M
Stars
19.0K
Last release
4.7.0
License
MIT

Strengths

  • Uses compact category inputs. Use integer category codes instead of expanding one-hot columns.
  • Handles missing values automatically. Use NaN to mark missing values during training.

Limitations

  • Leaf growth risks overfitting. Set max_depth to limit tree depth on small datasets.
  • Negative category codes become missing. Encode categories as nonnegative integers or use pandas categorical columns.

Quickstart

From Python-Intro.html
$ pip install lightgbm
import lightgbm as lgb

import numpy as np

rng = np.random.default_rng()
data = rng.uniform(size=(500, 10))  # 500 entities, each contains 10 features
label = rng.integers(low=0, high=2, size=(500, ))  # binary target
train_data = lgb.Dataset(data, label=label)

LightGBM examples

From open-source projects on GitHub

JAX runs NumPy-style array code on CPUs, GPUs, and TPUs and transforms Python functions. Three transformations do most of the work. jax.grad returns a function's gradient, jax.jit compiles a function with XLA, a compiler for accelerators, and jax.vmap maps a function over a batch dimension. Because the transformations compose, jax.jit(jax.grad(loss)) is a compiled gradient function. GPU and TPU builds install as extras of the jax package.

Downloads / mo
12.6M
Stars
36.6K
Last release
0.12.0.1
License
Apache-2.0

Strengths

  • Runs on GPUs and TPUs. The same code runs on CPU, GPU, and TPU backends.
  • Differentiates Python control flow. jax.grad takes gradients through loops, branches, recursion, and closures.

Limitations

  • Needs pure functions. Pass every input as an argument and return every result, or transformed functions can behave unexpectedly.
  • No neural-network layers. Add Flax, Equinox, or Keras to build and train networks.

Quickstart

From README.md
$ pip install -U jax
import jax
import jax.numpy as jnp

def tanh(x):
  y = jnp.exp(-2.0 * x)
  return (1.0 - y) / (1.0 + y)

grad_tanh = jax.grad(tanh)
print(grad_tanh(1.0))
# prints 0.4199743

JAX examples

From open-source projects on GitHub

TensorFlow is a machine learning platform first built by the Google Brain team, with stable Python and C++ APIs. pip install tensorflow includes CUDA support for NVIDIA GPUs. A smaller package, tensorflow-cpu, leaves GPU support out. Trained models export as a SavedModel for serving, and LiteRT runs them on Android. Models are usually built with Keras, which runs on TensorFlow as one of its backends.

Downloads / mo
12.4M
Stars
201.6K
Last release
2.21.0
License
Apache-2.0

Strengths

  • Uses available GPUs automatically. Compatible TensorFlow operations and Keras models run on an available GPU.
  • Exports models for deployment. Export a SavedModel for serving without the original model-building code.

Limitations

  • Windows GPUs need WSL. Use WSL2 for supported NVIDIA GPU training on Windows.

Quickstart

From tensorflow.org
$ pip install tensorflow
import tensorflow as tf
mnist = tf.keras.datasets.mnist

(x_train, y_train),(x_test, y_test) = mnist.load_data()
x_train, x_test = x_train / 255.0, x_test / 255.0

model = tf.keras.models.Sequential([
  tf.keras.layers.Flatten(input_shape=(28, 28)),
  tf.keras.layers.Dense(128, activation='relu'),
  tf.keras.layers.Dropout(0.2),
  tf.keras.layers.Dense(10, activation='softmax')
])

model.compile(optimizer='adam',
  loss='sparse_categorical_crossentropy',
  metrics=['accuracy'])

model.fit(x_train, y_train, epochs=5)
model.evaluate(x_test, y_test)

TensorFlow examples

From open-source projects on GitHub

Keras is a deep learning API that runs on JAX, TensorFlow, or PyTorch, and on OpenVINO for inference only. The backend comes from the KERAS_BACKEND environment variable or the keras.json config file. Models are built from layers, for example with keras.Sequential. Training goes through fit, which accepts tf.data datasets, PyTorch DataLoader objects, and NumPy arrays. Code written for tf.keras runs on Keras when models are saved in the .keras format.

Downloads / mo
12.0M
Stars
64.4K
Last release
3.15.1
License
Apache-2.0

Strengths

  • Exports to each framework. Use a Keras model as a PyTorch Module, a TensorFlow SavedModel, or a JAX function.
  • Trains from any data pipeline. fit() accepts tf.data datasets, PyTorch DataLoaders, NumPy arrays, and pandas dataframes.

Limitations

  • Set the backend first. Set KERAS_BACKEND before importing Keras. It can't change afterward.
  • Needs a backend installed. Install a backend such as JAX, PyTorch, or TensorFlow alongside Keras.
  • Windows through WSL. The README supports Linux and macOS and recommends the Windows Subsystem for Linux on Windows.

Quickstart

From getting_started
$ pip install --upgrade keras pip install -U jax
import os
os.environ["KERAS_BACKEND"] = "jax"
import keras

model = keras.Sequential()
model.add(keras.Input(shape=(16,)))
model.add(keras.layers.Dense(8))

Keras examples

From open-source projects on GitHub
def create_mlp(hidden_units, dropout_rate, activation, normalization_layer, name=None):
    mlp_layers = []
    for units in hidden_units:
        mlp_layers.append(normalization_layer())
        mlp_layers.append(layers.Dense(units, activation=activation))
        mlp_layers.append(layers.Dropout(dropout_rate))

    return keras.Sequential(mlp_layers, name=name)

CatBoost is Yandex's gradient boosting library for decision trees. Categorical columns go into training without one-hot encoding. The docs warn against encoding them first, because CatBoost builds numeric features from the categories and their combinations itself. Text and embedding columns are accepted too. CatBoostClassifier trains on a CPU or a GPU, with a Pool object containing the data, labels, and feature types.

Downloads / mo
6.9M
Stars
9.2K
Last release
1.2.10
License
Apache-2.0

Strengths

  • Handles mixed feature types. Use numeric, categorical, text, and embedding features together.

Limitations

  • GPU training is nondeterministic. Repeated GPU training does not guarantee identical model results.
  • ONNX export needs numeric features. Categorical, text, and embedding features cannot use ONNX-ML export.

Quickstart

From python-quickstart
$ pip install catboost
import numpy as np

from catboost import CatBoostClassifier, Pool

# initialize data
train_data = np.random.randint(0,
                               100,
                               size=(100, 10))

train_labels = np.random.randint(0,
                                 2,
                                 size=(100))

test_data = catboost_pool = Pool(train_data,
                                 train_labels)

model = CatBoostClassifier(iterations=2,
                           depth=2,
                           learning_rate=1,
                           loss_function='Logloss',
                           verbose=True)
# train the model
model.fit(train_data, train_labels)

CatBoost examples

From open-source projects on GitHub

FAQ

Use scikit-learn, with 214.2M downloads a month, for classical models, preprocessing, and evaluation. For gradient-boosted trees, use XGBoost, LightGBM, or CatBoost, and for neural networks, use PyTorch.

Use PyTorch for most new neural-network work. It has far more downloads, at 59.7M a month against 12.4M for TensorFlow, and a training loop is written by hand with its modules and autograd. Choose TensorFlow to deploy to mobile or the browser, because a SavedModel exports to TFLite and TensorFlow.js.

Neither wins everywhere. Both train gradient-boosted trees, run on GPUs, handle missing values, and support early stopping. LightGBM's histogram-based learning speeds up training and reduces memory use, but its leaf-wise trees can overfit small datasets unless max_depth is set.

Use PyTorch for neural-network layers and training in one library. JAX compiles NumPy-style code with XLA and composes grad, jit, and vmap, but it is narrowly scoped, so building networks takes Flax, Equinox, or Keras on top.

Pick CatBoost when the data has many categorical or text columns. It accepts numeric, categorical, text, and embedding features directly and builds numeric features from the categories automatically. Its ONNX export works only for models with numeric features, and GPU training doesn't give identical results between runs.

No. Keras is a deep learning API that runs on JAX, TensorFlow, or PyTorch, so an install needs Keras and one backend. TensorFlow also ships its own Keras API as tf.keras.

For coding agents

Found your machine learning library? Help your agent use it.

Connect Exa so your coding agent can find the library’s documentation, check its API, and look up implementations while you build.

Run in your terminal

claude plugin install exa@claude-plugins-official