Skip to content


Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?


Failed to load latest commit information.
Latest commit message
Commit time
May 9, 2023 18:48
May 12, 2023 11:08
August 16, 2022 17:49
May 10, 2023 11:09
May 10, 2023 11:09
March 4, 2022 14:55
May 9, 2023 18:48
August 9, 2022 15:07
March 31, 2023 09:27
March 19, 2023 10:52
September 22, 2022 10:05
May 9, 2023 18:48
May 9, 2023 19:51
February 10, 2023 18:03

iminuit ascl:2108.024

iminuit is a Jupyter-friendly Python interface for the Minuit2 C++ library maintained by CERN's ROOT team.

Minuit was designed to minimize statistical cost functions, for likelihood and least-squares fits of parametric models to data. It provides the best-fit parameters and error estimates from likelihood profile analysis.

The iminuit package comes with additional features:

  • Builtin cost functions for statistical fits
    • Binned and unbinned maximum-likelihood
    • Template fits with error propagation
    • Least-squares (optionally robust to outliers)
    • Gaussian penalty terms for parameters
    • Cost functions can be combined by adding them: total_cost = cost_1 + cost_2
    • Visualization of the fit in Jupyter notebooks
  • Support for SciPy minimizers as alternatives to Minuit's MIGRAD algorithm (optional)
  • Support for Numba accelerated functions (optional)


iminuit is (and always will be) a lean package which only depends on numpy, but additional features are enabled if the following optional packages are installed.

  • matplotlib: Visualization of fitted model for builtin cost functions
  • ipywidgets: Interactive fitting, see example below (also requires matplotlib)
  • scipy: Compute Minos intervals for arbitrary confidence levels
  • unicodeitplus: Render names of model parameters in simple LaTeX as Unicode


Checkout our large and comprehensive list of tutorials that take you all the way from beginner to power user. For help and how-to questions, please use the discussions on GitHub or gitter.

Lecture by Glen Cowan

In the exercises to his lecture for the KMISchool 2022, Glen Cowan shows how to solve statistical problems in Python with iminuit. You can find the lectures and exercises on the Github page, which covers both frequentist and Bayesian methods.

Glen Cowan is a known for his papers and international lectures on statistics in particle physics, as a member of the Particle Data Group, and as author of the popular book Statistical Data Analysis.

In a nutshell

iminuit can be used with a user-provided cost functions in form of a negative log-likelihood function or least-squares function. Standard functions are included in iminuit.cost, so you don't have to write them yourself. The following example shows how to perform an unbinned maximum likelihood fit.

import numpy as np
from iminuit import Minuit
from iminuit.cost import UnbinnedNLL
from scipy.stats import norm

x = norm.rvs(size=1000, random_state=1)

def pdf(x, mu, sigma):
    return norm.pdf(x, mu, sigma)

# Negative unbinned log-likelihood, you can write your own
cost = UnbinnedNLL(x, pdf)

m = Minuit(cost, mu=0, sigma=1)
m.limits["sigma"] = (0, np.inf)
m.migrad()  # find minimum
m.hesse()   # compute uncertainties
FCN = 2800 Nfcn = 34
EDM = 2.01e-07 (Goal: 0.0002)
Valid Minimum No Parameters at limit
Below EDM threshold (goal x 10) Below call limit
Covariance Hesse ok Accurate Pos. def. Not forced
Name Value Hesse Error Minos Error- Minos Error+ Limit- Limit+ Fixed
0 mu 0.039 0.031
1 sigma 0.981 0.022 0
mu sigma
mu 0.000962 0
sigma 0 0.000481

Interactive fitting

iminuit optionally supports an interactive fitting mode in Jupyter notebooks.

Animated demo of an interactive fit in a Jupyter notebook

Faster than RooFit

When iminuit is used with cost functions and pdfs that are JIT-compiled with numba (JIT-compiled pdfs are provided by numba_stats ), the fit is up to 10x faster compared to an equivalent fit in the RooFit framework. The gain is particularly large when numba with auto-parallelization is compared to parallel computation in RooFit.

More information about this benchmark is given in the Benchmark section of the documentation.

Partner projects

  • numba_stats provides faster implementations of probability density functions than scipy, and a few specific ones used in particle physics that are not in scipy.
  • boost-histogram from Scikit-HEP provides fast generalized histograms that you can use with the builtin cost functions.
  • jacobi provides a robust, fast, and accurate calculation of the Jacobi matrix of any transformation function and building a function for generic error propagation.


The current 2.x series has introduced breaking interfaces changes with respect to the 1.x series.

All interface changes are documented in the changelog with recommendations how to upgrade. To keep existing scripts running, pin your major iminuit version to <2, i.e. pip install 'iminuit<2' installs the 1.x series.