继续说多项式的数值及拟合,这次主要讨论关于多项式拟合的函数fit。定义如下:
classmethod polynomial.polynomial.Polynomial.fit
(x, y, deg, domain=None, rcond=None, full=False, w=None, window=None, symbol='x')
Polynomial类下面有一个函数fit,官方是这么介绍的:
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.
简单来说,就是通过最小二乘拟合曲线,还是以前面的函数为例:
测试该函数,我们可以先通过原函数,生成系列的对应点,然后利用这些点进行数据的拟合:
import numpy as np
import matplotlib.pyplot as plt
from numpy.polynomial import Polynomial as P
np.polynomial.set_default_printstyle("

最低0.47元/天 解锁文章
356

被折叠的 条评论
为什么被折叠?



