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

Function legfit

numpy/polynomial/legendre.py:1286–1412  ·  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

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

Callers

nothing calls this directly

Calls 1

_fitMethod · 0.80

Tested by

no test coverage detected