# Interactive Linear and Polynomial Regression In Jupyter Notebook Python

In this we will create an interactive gui for curve fitting using linear and polynomial regression this is a great way to see what polynomial order degree will give you best results

Linear Regression Formula

Y = mx + c

m = slope , c = constant , x = variable which changes output Just you know linear Regression always give straight line and not much useful in most of the real life scenarios

Polynomial Regression

Y = b1X^n +c

b1= slope , c = constant , x = variable which changes output Just you know linear Regression always give straight line and not much useful in most of the real life scenarios

n = degree of polynomial regression

import numpy

import matplotlib.pyplot as plt

from ipywidgets import interactive

def f(n,t):

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, t, 100)

plt.scatter(x, y)

plt.plot(curve_fitting_line, curve_model(curve_fitting_line))

plt.show()

interactive_plot= interactive(f,n=(1,20),t = (1,30))

interactive_plot

## 0 Comments

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