MCPcopy Index your code
hub / github.com/numpy/numpy / fit

Method fit

numpy/polynomial/_polybase.py:946–1034  ·  view source on GitHub ↗

Least squares fit to data. Return a series instance that is the least squares fit to the data `y` sampled at `x`. The domain of the returned instance can be specified and this will often result in a superior fit with less chance of ill conditioning. Paramete

(cls, x, y, deg, domain=None, rcond=None, full=False, w=None,
        window=None, symbol='x')

Source from the content-addressed store, hash-verified

944
945 @classmethod
946 def fit(cls, x, y, deg, domain=None, rcond=None, full=False, w=None,
947 window=None, symbol='x'):
948 """Least squares fit to data.
949
950 Return a series instance that is the least squares fit to the data
951 `y` sampled at `x`. The domain of the returned instance can be
952 specified and this will often result in a superior fit with less
953 chance of ill conditioning.
954
955 Parameters
956 ----------
957 x : array_like, shape (M,)
958 x-coordinates of the M sample points ``(x[i], y[i])``.
959 y : array_like, shape (M,)
960 y-coordinates of the M sample points ``(x[i], y[i])``.
961 deg : int or 1-D array_like
962 Degree(s) of the fitting polynomials. If `deg` is a single integer
963 all terms up to and including the `deg`'th term are included in the
964 fit. For NumPy versions >= 1.11.0 a list of integers specifying the
965 degrees of the terms to include may be used instead.
966 domain : {None, [beg, end], []}, optional
967 Domain to use for the returned series. If ``None``,
968 then a minimal domain that covers the points `x` is chosen. If
969 ``[]`` the class domain is used. The default value was the
970 class domain in NumPy 1.4 and ``None`` in later versions.
971 The ``[]`` option was added in numpy 1.5.0.
972 rcond : float, optional
973 Relative condition number of the fit. Singular values smaller
974 than this relative to the largest singular value will be
975 ignored. The default value is ``len(x)*eps``, where eps is the
976 relative precision of the float type, about 2e-16 in most
977 cases.
978 full : bool, optional
979 Switch determining nature of return value. When it is False
980 (the default) just the coefficients are returned, when True
981 diagnostic information from the singular value decomposition is
982 also returned.
983 w : array_like, shape (M,), optional
984 Weights. If not None, the weight ``w[i]`` applies to the unsquared
985 residual ``y[i] - y_hat[i]`` at ``x[i]``. Ideally the weights are
986 chosen so that the errors of the products ``w[i]*y[i]`` all have
987 the same variance. When using inverse-variance weighting, use
988 ``w[i] = 1/sigma(y[i])``. The default value is None.
989 window : {[beg, end]}, optional
990 Window to use for the returned series. The default
991 value is the default class domain
992 symbol : str, optional
993 Symbol representing the independent variable. Default is 'x'.
994
995 Returns
996 -------
997 new_series : series
998 A series that represents the least squares fit to the data and
999 has the domain and window specified in the call. If the
1000 coefficients for the unscaled and unshifted basis polynomials are
1001 of interest, do ``new_series.convert().coef``.
1002
1003 [resid, rank, sv, rcond] : list

Callers 4

test_bad_conditioned_fitFunction · 0.80
test_fitFunction · 0.80
test_fitFunction · 0.80

Calls 1

_fitMethod · 0.80

Tested by 4

test_bad_conditioned_fitFunction · 0.64
test_fitFunction · 0.64
test_fitFunction · 0.64