# https://data36.com/polynomial-regression-python-scikit-learn/
import numpy as np
import matplotlib.pyplot as plt
from sklearn.linear_model import LinearRegression
from sklearn.preprocessing import PolynomialFeatures

x = np.arange(0, 30)
y = [3, 4, 5, 7, 10, 8, 9, 10, 10, 23, 27, 44, 50, 63, 67, 60, 62, 70, 75, 88, 81, 87, 95, 100, 108, 135, 151, 160, 169, 179]
plt.figure(figsize=(10,6)) #10 inches width, 6 inches height
plt.scatter(x, y)
plt.show()

poly = PolynomialFeatures(degree=2, include_bias=False)
poly_features = poly.fit_transform(x.reshape(-1, 1)) #Transform x values into polynomial features

poly_reg_model = LinearRegression() #cerate the regression model 
poly_reg_model.fit(poly_features, y)

y_predicted = poly_reg_model.predict(poly_features) #make the predictions

plt.figure(figsize=(10, 6))
plt.title("Your first polynomial regression – congrats! :)", size=16)
plt.scatter(x, y)
plt.plot(x, y_predicted, c="red")
plt.show()