Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

Use scipy.stats.fit when you have sample values and want to estimate parameters for a probability distribution. Use scipy.optimize.curve_fit when you have paired x-y observations and a function to fit. They solve different problems; neither API’s parameter estimates alone prove that the model is appropriate.

The examples and API details below follow the SciPy v1.18.0 documentation. Check the reference pages for your installed SciPy version before relying on version-sensitive signatures or defaults.

Choose the SciPy fit API that matches your data

Your task API What it does
Estimate a named probability distribution from sample values scipy.stats.fit or a continuous distribution object’s fit method Estimates distribution parameters, with the top-level API accepting parameter bounds.
Fit a specified function to paired x-y measurements scipy.optimize.curve_fit Estimates the function’s parameters and returns an approximate covariance matrix.
Minimize a residual vector with robust loss or additional control scipy.optimize.least_squares Lets you define residuals directly and configure bounds, loss, Jacobian, and optimizer controls.
Test whether a sample is compatible with a distribution family scipy.stats.goodness_of_fit Uses Monte Carlo calibration, refitting unknown parameters in simulated samples.

These APIs are not interchangeable. A distribution fit estimates parameters under a family you choose; a curve fit estimates parameters in a function you specify; a goodness-of-fit test addresses compatibility with a distribution family.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Fit a probability distribution to sample values

For one-dimensional sample data from an assumed discrete or continuous family, the top-level scipy.stats.fit function estimates parameters subject to the bounds you provide. Its FitResult includes named parameters and optimizer status.

#1 Best Overall
Sale
TI-30XIIS Scientific Calculator Texas Instruments, Black
  • Fundamental, two-line calculator that combines statistics and advanced scientific functions for high school math and science
  • Two-line display shows the entry and calculated result at the same time for easy understanding of the calculation
  • Fraction features, conversions, and basic scientific and trigonometric functions
  • Solar and battery powered
  • Approved for use on SAT, ACT and AP exams

Example: fit a negative-binomial distribution

import numpy as np
from scipy import stats

# Replace this demonstration data with your one-dimensional observations.
rng = np.random.default_rng(7)
data = stats.nbinom.rvs(5, 0.4, size=500, random_state=rng)

result = stats.fit(
    stats.nbinom,
    data,
    bounds={"n": (1, 20), "p": (0.05, 0.95)},
)

print(result.params)
print(result.success)
print(result.message)
print(result.nllf())
result.plot()

The data-generation line is for a runnable illustration, not a claim about fixed fit results. SciPy’s v1.18.0 documentation likewise notes that its negative-binomial example is stochastic and that numerical results can vary with the default optimizer. Inspect the returned result rather than expecting particular parameter values. See the SciPy stats.fit reference.

Set bounds that reflect plausible parameters

Bounds define the optimizer’s search space; they should reflect the distribution’s parameter domain and what is plausible for the data. SciPy notes that convergence is more likely when bounds are tight while still containing the maximum-likelihood estimate. A parameter can be fixed by giving it equal lower and upper bounds.

Rank #2
Sale
Texas Instruments TI-30XS MultiView Scientific Calculator
  • View multiple calculations at the same time: Compare results and explore patterns on-screen with the MultiView display that supports up to four lines
  • See math exactly as it appears in textbooks: Display math expressions, symbols and stacked fractions exactly the way they appear in textbooks — no need to adapt to a technical syntax; provides quick access to frequently used functions
  • Scientific notation output: View scientific notation with the proper superscripted exponents and see the output in scientific notation
  • Explore (x,y) table of values: Students can easily explore an (x,y) table of values for a given function automatically or by entering specific x values
  • The TI-30XS MultiView scientific calculator is ideal for general math, Pre-Algebra, Algebra 1 and 2, Geometry, Statistics, general science, Biology and Chemistry

Bounds may be a mapping from parameter names to intervals or a sequence. With a sequence, provide intervals for all shape parameters; location and scale bounds may follow. If you omit location and scale bounds, the top-level function fixes them at 0 and 1, respectively. Non-finite input values raise ValueError.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Read the result and check the fit

  • Check result.success and result.message to see whether the optimizer reports success.
  • Inspect result.params for the fitted named parameters and result.nllf() for the negative log likelihood.
  • Use result.plot() to compare the fitted probability mass function or density with a normalized histogram.
  • Check whether the chosen family and parameter constraints make sense for the data; a successful optimization is not proof of an adequate model.

How distribution-instance fitting differs

Continuous univariate distribution objects also provide a fit method. The SciPy v1.18.0 reference describes these methods as maximum-likelihood estimation and documents support for regular data and censored observations represented by CensoredData. This is distinct from the top-level scipy.stats.fit, which supports discrete as well as continuous distributions and accepts explicit bounds.

Rank #3
Sale
Texas Instruments TI-30Xa Scientific Calculator
  • 10-digit display; for general math, pre-algebra, algebra 1 and 2, trigonometry and biology
  • Performs trigonometric functions, logarithms, roots, powers, reciprocals, and factorials
  • Also add, subtract, multiply and divide fractions; 1-variable statistics (mean / standard deviation)
  • Conversions: fractions/decimals, degrees/radians/grads, DMS/decimal/degrees, and polar/rectangular
  • Battery-powered; includes slide case

Starting values matter: defaults do not work well for every distribution. Review the SciPy probability-distributions tutorial and the documentation for the specific distribution and API you use.

Fit a curve to paired x-y observations

For measurements modeled as ydata = f(xdata, *params) + eps, define a callable with the independent variable first and the parameters after it. curve_fit returns popt, the estimated parameters, and pcov, an approximate covariance matrix.

Rank #4
CATIGA Scientific Calculators with Graphic Functions, Graphing Calculators with Multiple Modes, Scientific Calculators for Students, High School or College Courses, Calculadora Cientifica, CS-229
  • Scientific Calculator with Graphic Function: All-in-one scientific and graphing calculator. Supports plotting functions, analyzing graphs, and solving complex equations. Displays graphs and formulas simultaneously for clear visualization. Ideal for algebra, calculus, and exam prep.
  • Compact and Comfortable Design: This scientific and graphing calculator sized at 7 x 3.3 inches for a balanced and ergonomic feel. Fits easily in one hand or on a desk without taking up space. Ideal for long study sessions, test environments, and everyday academic or professional use; smooth button layout supports efficient input and navigation.
  • Multiple Modes and 360+ Functions: Includes angle measurement, calculation, and display modes for flexible use across subjects. This scientific and graphing calculator supports over 360 functions such as fractions, complex numbers, statistics, linear regression, standard deviation, and variable solving. Ideal for mastering algebra, geometry, trigonometry, and advanced math applications.
  • Durable and Portable Design: Built with an anti-drop body that resists everyday impacts for long-term use. This scientific and graphing calculator is lightweight and slim for easy carrying in a backpack or pocket that includes a protective case to guard the screen and buttons during travel or storage.
  • If you cannot turn on the calculator, please press the reset button on the back! If you have any further problems, we offer a limited warranty of 365 days. Please contact us and we will give you an answer within 24 hours.

Example: fit an exponential decay

import numpy as np
from scipy.optimize import curve_fit

def decay(x, amplitude, rate, offset):
    return amplitude * np.exp(-rate * x) + offset

rng = np.random.default_rng(7)
xdata = np.linspace(0, 4, 60)
ydata = decay(xdata, 3.0, 1.2, 0.4) + 0.15 * rng.normal(size=xdata.size)

popt, pcov = curve_fit(
    decay,
    xdata,
    ydata,
    bounds=([0, 0, -1], [10, 5, 2]),
)

print(popt)
print(pcov)

The bounds in this example constrain amplitude, rate, and offset to the intervals shown. The noisy synthetic observations mean the exact estimates can vary. For a further example and the full call signature, see SciPy’s curve_fit reference.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use measurement uncertainty when it matters

The sigma argument can be scalar or one-dimensional standard deviations, or a two-dimensional covariance matrix. By default, absolute_sigma=False, so SciPy scales the parameter covariance estimate using residual variance. Set absolute_sigma=True when the supplied uncertainty values should be treated as absolute rather than relatively scaled.

Best Value
Casio FX-300ESPLSB-WAIT Scientific Calculator
  • Natural Textbook Display presents formulas and results exactly as written in textbooks for intuitive learning.

Check numerical reliability

  • Use float64 inputs and ensure the model returns compatible values.
  • Constrain parameters with bounds when their valid ranges are known.
  • If parameters have very different scales, take care with scaling and interpretability.
  • Treat pcov as a local approximation, not a guarantee. A poor Jacobian rank or a large covariance condition number can signal unreliable estimates.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Use least squares for direct residual control

Choose scipy.optimize.least_squares when it is clearer to construct the residual vector yourself or when you need a robust loss function. For example, define residuals as the model’s predictions minus the observed values, then pass that residual function to the optimizer. SciPy’s official example contrasts ordinary least squares with soft-L1 and Cauchy losses on data containing outliers. Robust losses reduce the influence of large residuals; they do not validate the model or guarantee correct estimates.

See the least_squares reference for bounds, loss choices, Jacobian options, and optimizer controls, and the SciPy optimization tutorial for an outlier example.

Test distribution compatibility separately

Parameter estimation answers which parameters best fit a chosen family under the fitting method; it does not test whether that family is a plausible description of the sample. For a formal check, scipy.stats.goodness_of_fit simulates samples under the null model and refits unknown parameters in each simulated sample. It supports Anderson-Darling, Kolmogorov-Smirnov, Cramér-von Mises, and Filliben statistics.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

This repeated fitting can be slow for distributions that require numerical optimization. Avoid treating estimated parameters as if they were known in a traditional fixed-parameter test: SciPy characterizes that shortcut as conservative and low power. See the goodness_of_fit reference for the test procedure and options.

Quick Recap

SaleBestseller No. 1
TI-30XIIS Scientific Calculator Texas Instruments, Black
TI-30XIIS Scientific Calculator Texas Instruments, Black
Fraction features, conversions, and basic scientific and trigonometric functions; Solar and battery powered
$13.88
SaleBestseller No. 3
Texas Instruments TI-30Xa Scientific Calculator
Texas Instruments TI-30Xa Scientific Calculator
10-digit display; for general math, pre-algebra, algebra 1 and 2, trigonometry and biology
$10.98

Practical workflow

  1. Decide whether your input is a sample for a probability distribution or paired x-y measurements for a function.
  2. Choose the matching API, then inspect its documentation for your installed SciPy version.
  3. Set plausible parameter bounds or constraints; avoid unnecessarily broad ranges.
  4. Inspect optimizer status and estimates, then compare the fitted model with the observations.
  5. For a distribution, use a goodness-of-fit procedure when you need a formal compatibility test; do not infer model adequacy from fitted parameters alone.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.