import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
dataset = pd.read_csv('_data/04.csv')
x = dataset.iloc[:, 1:-1].values
y = dataset.iloc[:, -1].valuesPolynorminal Linear Regression
machine learning
![]()
preprocessing
Linear Regression Model
from sklearn.linear_model import LinearRegression
regressor = LinearRegression()
regressor.fit(x, y)LinearRegression()In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook.
On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.
LinearRegression()
Polynorminal Linear Regression
from sklearn.preprocessing import PolynomialFeatures
poly = PolynomialFeatures(degree=4)
x_poly = poly.fit_transform(x)
regressor2 = LinearRegression()
regressor2.fit(x_poly, y)LinearRegression()In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook.
On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.
LinearRegression()
Visualize Linear Regression
plt.scatter(x, y, color='red')
plt.plot(x, regressor.predict(x), color='blue')
plt.title('Linear Regression Model')
plt.xlabel('Position Level')
plt.ylabel('Salary')
plt.show()
Visualize Poly Linear Regression
plt.scatter(x, y, color='red')
plt.plot(x, regressor2.predict(x_poly), color='blue')
plt.title('Poly Linear Regression Model')
plt.xlabel('Position Level')
plt.ylabel('Salary')
plt.show()