fitting data with numpy

后端 未结 2 664
长情又很酷
长情又很酷 2020-11-28 21:58

Let me start by telling that what I get may not be what I expect and perhaps you can help me here. I have the following data:

>>> x
array([ 3.08,  3         


        
2条回答
  •  抹茶落季
    2020-11-28 22:19

    Note that you can use the Polynomial class directly to do the fitting and return a Polynomial instance.

    from numpy.polynomial import Polynomial
    
    p = Polynomial.fit(x, y, 4)
    plt.plot(*p.linspace())
    

    p uses scaled and shifted x values for numerical stability. If you need the usual form of the coefficients, you will need to follow with

    pnormal = p.convert(domain=(-1, 1))
    

提交回复
热议问题