Open In App

Python | Numpy np.lagfit() method

Last Updated : 23 Jan, 2020
Comments
Improve
Suggest changes
Like Article
Like
Report
With the help of np.lagfit() method, we can get the least squares fit of laguerre series of a given data by using np.lagfit() method.
Syntax : np.lagfit(x, y, deg) Return : Return the least squares fit of laguerre series to data.
Example #1 : In this example we can see that by using np.lagfit() method, we are able to get the least squares fit of laguerre series of a given data. Python3 1=1
# import numpy and lagfit
import numpy as np
from numpy.polynomial.laguerre import lagfit

x, y = [1, 2], [3, 4]
deg = 2

# import np.lagfit() method
gfg = lagfit(x, y, deg)

print(gfg)
Output :
[2.125 -0.125 -1.75]
Example #2 : Python3 1=1
# import numpy and lagfit
import numpy as np
from numpy.polynomial.laguerre import lagfit

x, y = [1, 2, 3], [3, 4, 5]
deg = 3

# import np.lagfit() method
gfg = lagfit(x, y, deg)

print(gfg)
Output :
[3.06722689 -0.66386555 -0.40336134 0.40336134]

Next Article

Similar Reads