MCPcopy Create free account
hub / github.com/numpy/numpy / legfit

Function legfit

numpy/polynomial/legendre.py:1296–1420  ·  view source on GitHub ↗

Least squares fit of Legendre series to data. Return the coefficients of a Legendre series of degree `deg` that is the least squares fit to the data values `y` given at points `x`. If `y` is 1-D the returned coefficients will also be 1-D. If `y` is 2-D multiple fits are done, o

(x, y, deg, rcond=None, full=False, w=None)

Source from the content-addressed store, hash-verified

1294
1295
1296def legfit(x, y, deg, rcond=None, full=False, w=None):
1297 """
1298 Least squares fit of Legendre series to data.
1299
1300 Return the coefficients of a Legendre series of degree `deg` that is the
1301 least squares fit to the data values `y` given at points `x`. If `y` is
1302 1-D the returned coefficients will also be 1-D. If `y` is 2-D multiple
1303 fits are done, one for each column of `y`, and the resulting
1304 coefficients are stored in the corresponding columns of a 2-D return.
1305 The fitted polynomial(s) are in the form
1306
1307 .. math:: p(x) = c_0 + c_1 * L_1(x) + ... + c_n * L_n(x),
1308
1309 where `n` is `deg`.
1310
1311 Parameters
1312 ----------
1313 x : array_like, shape (M,)
1314 x-coordinates of the M sample points ``(x[i], y[i])``.
1315 y : array_like, shape (M,) or (M, K)
1316 y-coordinates of the sample points. Several data sets of sample
1317 points sharing the same x-coordinates can be fitted at once by
1318 passing in a 2D-array that contains one dataset per column.
1319 deg : int or 1-D array_like
1320 Degree(s) of the fitting polynomials. If `deg` is a single integer
1321 all terms up to and including the `deg`'th term are included in the
1322 fit. For NumPy versions >= 1.11.0 a list of integers specifying the
1323 degrees of the terms to include may be used instead.
1324 rcond : float, optional
1325 Relative condition number of the fit. Singular values smaller than
1326 this relative to the largest singular value will be ignored. The
1327 default value is len(x)*eps, where eps is the relative precision of
1328 the float type, about 2e-16 in most cases.
1329 full : bool, optional
1330 Switch determining nature of return value. When it is False (the
1331 default) just the coefficients are returned, when True diagnostic
1332 information from the singular value decomposition is also returned.
1333 w : array_like, shape (`M`,), optional
1334 Weights. If not None, the weight ``w[i]`` applies to the unsquared
1335 residual ``y[i] - y_hat[i]`` at ``x[i]``. Ideally the weights are
1336 chosen so that the errors of the products ``w[i]*y[i]`` all have the
1337 same variance. When using inverse-variance weighting, use
1338 ``w[i] = 1/sigma(y[i])``. The default value is None.
1339
1340 Returns
1341 -------
1342 coef : ndarray, shape (M,) or (M, K)
1343 Legendre coefficients ordered from low to high. If `y` was
1344 2-D, the coefficients for the data in column k of `y` are in
1345 column `k`. If `deg` is specified as a list, coefficients for
1346 terms not included in the fit are set equal to zero in the
1347 returned `coef`.
1348
1349 [residuals, rank, singular_values, rcond] : list
1350 These values are only returned if ``full == True``
1351
1352 - residuals -- sum of squared residuals of the least squares fit
1353 - rank -- the numerical rank of the scaled Vandermonde matrix

Callers

nothing calls this directly

Calls 1

_fitMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…