import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
= pd.read_csv('_data/04.csv')
dataset = dataset.iloc[:, 1:-1].values
x = dataset.iloc[:, -1].values y
Polynorminal Linear Regression
machine learning
preprocessing
Linear Regression Model
from sklearn.linear_model import LinearRegression
= LinearRegression()
regressor 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
= PolynomialFeatures(degree=4)
poly = poly.fit_transform(x)
x_poly = LinearRegression()
regressor2 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
='red')
plt.scatter(x, y, color='blue')
plt.plot(x, regressor.predict(x), color'Linear Regression Model')
plt.title('Position Level')
plt.xlabel('Salary')
plt.ylabel( plt.show()
Visualize Poly Linear Regression
='red')
plt.scatter(x, y, color='blue')
plt.plot(x, regressor2.predict(x_poly), color'Poly Linear Regression Model')
plt.title('Position Level')
plt.xlabel('Salary')
plt.ylabel( plt.show()