Skip to main content
`Ctrl`+`K`

# LinearLSQFitter

class astropy.modeling.fitting.LinearLSQFitter(calc_uncertainties=False)

  Bases: `Fitter`

  A class performing a linear least square fitting. Uses `numpy.linalg.lstsq` to do the fitting. Given a model and data, fits the model to the data and changes the model’s parameters. Keeps a dictionary of auxiliary fitting information.

  Notes

  Note that currently LinearLSQFitter does not support compound models.

  Attributes Summary

  `supported_constraints` |
  `supports_masked_input` |

  Methods Summary

  `__call__`(model, x, y[, z, weights, rcond, ...]) | Fit data to this model.
  `objective_function`(fps, *args) | Function to minimize.

  Attributes Documentation

  supported_constraints = ['fixed']
  supports_masked_input = True

  Methods Documentation

  __call__(model, x, y, z=None, weights=None, rcond=None, *, inplace=False)

    Fit data to this model.

    Parameters:
      model `FittableModel`

        model to fit to x, y, z

      x `array`

        Input coordinates

      y numpy:array_like

        Input coordinates

      z numpy:array_like, optional

        Input coordinates. If the dependent (`y` or `z`) coordinate values are provided as a `numpy.ma.MaskedArray`, any masked points are ignored when fitting. Note that model set fitting is significantly slower when there are masked points (not just an empty mask), as the matrix equation has to be solved for each model separately when their coordinate grids differ.

      weights `array`, optional

        Weights for fitting. For data with Gaussian uncertainties, the weights should be 1/sigma.

      rcond `python:float`, optional

        Cut-off ratio for small singular values of `a`. Singular values are set to zero if they are smaller than `rcond` times the largest singular value of `a`.

      equivalencies `python:list` or `python:None`, optional, keyword-only

        List of additional equivalencies that are should be applied in case x, y and/or z have units. Default is None.

      inplace bool, optional

        If `False` (the default), a copy of the model with the fitted parameters set will be returned. If `True`, the returned model will be the same instance as the model passed in, and the parameter values will be changed inplace.

    Returns:
      fitted_model `FittableModel`

        If `inplace` is `False` (the default), this is a copy of the input model with parameters set by the fitter. If `inplace` is `True`, this is the same model as the input model, with parameters updated to be those set by the fitter.

  objective_function(fps, *args)

    Function to minimize.

    Parameters:
      fps `python:list`

        parameters returned by the fitter

      args `python:list`

        [model, [other_args], [input coordinates]] other_args may include weights or any other quantities specific for a statistic

    Notes

    The list of arguments (args) is set in the `__call__` method. Fitters may overwrite this method, e.g. when statistic functions require other arguments.