below is an overview of process
Copy_of_polynomial_regression.pdf
from sklearn.linear_model import LinearRegression
lin_reg = LinearRegression()
lin_reg.fit(X, y)
LinearRegression class from Scikit-Learn is imported to create a linear regression model.LinearRegression is created and trained using the fit method on the original feature matrix X and target values y. This model learns the linear relationship between features and the target variable.from sklearn.preprocessing import PolynomialFeatures
poly_reg = PolynomialFeatures(degree = 4)
X_poly = poly_reg.fit_transform(X)
lin_reg_2 = LinearRegression()
lin_reg_2.fit(X_poly, y)
PolynomialFeatures class is imported to generate polynomial terms from the original features.PolynomialFeatures with degree = 4 is created. This transforms the original feature matrix X into a new matrix X_poly that includes polynomial terms up to the 4th degree.LinearRegression model (lin_reg_2) is created and trained using the polynomial feature matrix X_poly and target values y. This model learns the relationship considering the polynomial terms.plt.scatter(X, y, color = 'red')
plt.plot(X, lin_reg.predict(X), color = 'blue')
plt.title('Polynomial')
plt.xlabel('Truth or Bluff (Linear Regression)')
plt.ylabel('Salary')
plt.show()
plt.scatter creates a scatter plot of the original data points (features vs. target values) in red.plt.plot overlays a line representing the predictions from the linear regression model (lin_reg). This line is drawn using the original feature values X and their corresponding predictions.plt.show().plt.scatter(X, y, color = 'red')
plt.plot(X, lin_reg_2.predict(X_poly), color = 'blue')
plt.title('Polynomial')
plt.xlabel('Position level')
plt.ylabel('Salary')
plt.show()
plt.scatter again creates a scatter plot of the original data points.plt.plot overlays a curve representing the predictions from the polynomial regression model (lin_reg_2). This uses X_poly to generate predictions, fitting a smooth curve.X_grid = np.arange(min(X), max(X), 0.1)
X_grid = X_grid.reshape((len(X_grid), 1))
plt.scatter(X, y, color = 'red')
plt.plot(X_grid, lin_reg_2.predict(poly_reg.fit_transform(X_grid)), color = 'blue')
plt.title('Polynomial')
plt.xlabel('Position level')
plt.ylabel('Salary')
plt.show()