I created a small program that does linear and polynomial regression. For now, both regressions are on the same graph. I want to put them to two different graphs (to make subplots), but also I want to have different titles (Linear regression and Polynomial regression).
I do not know how to do this, can you please help me?
import numpy as np
import matplotlib.pyplot as plt
import math
X = np.array([1,2,3,5,6,7,4,7,8,9,5,10,11,7,6,6,10,11,11,12,13,13,14])
Y = np.array([2,3,5,8,11,14,9,19,15,19,15,16,14,7,13,13,14,13,23,25,26,27,33])
#_______________ polinomial ________________
koeficienti_polinom = np.polyfit(X, Y, 2)
a=koeficienti_polinom[0]
b=koeficienti_polinom[1]
c=koeficienti_polinom[2]
xval=np.linspace(np.min(X), np.max(X))
regression=a * xval**2 + b*xval + c
predX = float(input("Enter: "))
predY = a * predX**2 + b*predX + c
plt.scatter(X,Y, s=20, color="blue" )
plt.scatter(predX, predY, color="red")
plt.plot(xval, regression, color="black", linewidth=1)
print("Polynomial: ",round(predY,2))
#________________ linear _________________
koeficienti_linear = np.polyfit(X, Y, 1)
a1=koeficienti_linear[0]
b1=koeficienti_linear[1]
xval1=np.linspace(np.min(X), np.max(X))
regression1=a1 * xval1 + b1
predY1 = a1 * predX+ b1
plt.scatter(predX, predY1, color="red")
plt.subplot(2,2,2)
plt.plot(xval1, regression1, color="black", linewidth=1)
plt.xlabel("Size")
plt.ylabel("Costs")
plt.title("Cost Prediction Graph")
plt.grid()
print("Linear: ", round(predY1,2))
plt.show()