I use the following code to produce a plot:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
dataset = pd.read_csv('Position_Salaries.csv')
X = dataset.iloc[: , 1:2].values
y = dataset.iloc[: , 2:3].values
from sklearn.linear_model import LinearRegression
l_regressor = LinearRegression()
l_regressor.fit(X, y)
from sklearn.preprocessing import PolynomialFeatures
p_regressor = PolynomialFeatures(degree = (0,5))
X_poly = p_regressor.fit_transform(X)
lp_regressor = LinearRegression()
lp_regressor.fit(X_poly, y)
plt.scatter(X, y, color='red')
plt.plot(X, l_regressor.predict(X), color='blue')
plt.title('Salary vs Position (Linear Reg)')
plt.xlabel('Position')
plt.ylabel('Salary')
plt.show()
Output:
How can I achieve something like the following output instead?