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