Fit 3rd order Polynomial to graph data using scikit-learn, more infos https://www.datatechnotes.com/2018/06/polynomial-regression-fitting-in-python.html
from matplotlib import pyplot as plt
plt.rcParams["font.size"] = 20
import numpy as np
from sklearn.linear_model import LinearRegression
from sklearn.preprocessing import PolynomialFeatures
data
x = np.array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], dtype='d')
dx = np.array([0.1,0.1,0.5,0.1,0.5,0.1,0.5,0.1,0.5,0.1], dtype='d')
y = np.array([1.1 ,2.3 ,2.7 ,3.2 ,3.1 ,2.4 ,1.7 ,1.5 ,1.5 ,1.7 ], dtype='d')
dy = np.array([0.15,0.22,0.29,0.39,0.31,0.21,0.13,0.15,0.19,0.13], dtype='d')
building polynomial model
polyModel = PolynomialFeatures(degree = 3)
xpol = polyModel.fit_transform(x.reshape(-1, 1))
preg = polyModel.fit(xpol,y)
Building linear model
linearModel = LinearRegression(fit_intercept = True)
linearModel.fit(xpol, y[:, np.newaxis])
Plotting
x_plot = np.linspace(0.1,10.1,200)
polyfit = linearModel.predict(preg.fit_transform(x_plot.reshape(-1, 1)))
plot data
plt.figure()
plt.errorbar(x, y, dy , dx, fmt="o")
plt.plot(x_plot, polyfit )
plt.title("scikit-learn Fit Test")
plt.xlim(-0.1, 10.1)
plt.show()