__CURVE FITTING IN PYTHON USING POLYFIT AND IPYWIDGETS__

In this article you will learn how to make a interactive curve fitting in python. the advantage of this it is interactive one so instead of running your code again and again you can ipywidgets to make a interactive curve fitting graph in jupyter

note : this program is specially designed for jupyter

make sure to install ipywidgets

pip install ipywidgets (run this anacond command manager)

# MAIN PROGRAM

import numpy

import matplotlib.pyplot as plt

from ipywidgets import interactive

def f(n):

x = [1,2,3,4,5,6,7,8,9,10,11,12,15,17,22,23,25,30]

y = [100,90,80,60,60,55,60,65,70,70,75,76,78,79,90,99,99,100]

curve_model = numpy.poly1d(numpy.polyfit(x, y, n))

curve_fitting_line = numpy.linspace(1, 30, 1000)

plt.scatter(x, y)

plt.plot(curve_fitting_line, curve_model(curve_fitting_line))

plt.show()

interactive_plot= interactive(f,n=(1,10))

interactive_plot

curve_model = this line of code basically hold all the data and specify what kind of

polyfit/ curve fitting equation we want to use in our graph. the variable n defined

basically the type of equation we are going to use if it's 1 it means we are using

linear regression equation to do that

curve_fitting_line = this line represent that basically show much our curve fitting

happens (if you have any doubt here just comment i will modify the blog and clear your

doubt)

we are using ipywidgets to basically to make this interactive graph there are other

cool videos available on my channel to teach so make sure like subscribe and share

## 0 Comments

if you are not getting it then ask i am glad to help