-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d94b6c4
commit 5500495
Showing
4 changed files
with
59 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
# Data Preprocessing Template | ||
|
||
# Importing the libraries | ||
import numpy as np | ||
import matplotlib.pyplot as plt | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
Part 2 - Regression/Section 6 - Polynomial Regression/Position_Salaries.csv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
Position,Level,Salary | ||
Business Analyst,1,45000 | ||
Junior Consultant,2,50000 | ||
Senior Consultant,3,60000 | ||
Manager,4,80000 | ||
Country Manager,5,110000 | ||
Region Manager,6,150000 | ||
Partner,7,200000 | ||
Senior Partner,8,300000 | ||
C-level,9,500000 | ||
CEO,10,1000000 |
44 changes: 44 additions & 0 deletions
44
Part 2 - Regression/Section 6 - Polynomial Regression/polynomial_linear_regression.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import numpy as np | ||
import matplotlib.pyplot as plt | ||
import pandas as pd | ||
|
||
# Importing the dataset | ||
dataset = pd.read_csv('Position_Salaries.csv') | ||
X = dataset.iloc[:, 1:2].values | ||
y = dataset.iloc[:, 2].values | ||
|
||
#Fitting Linear Regression to the dataset | ||
from sklearn.linear_model import LinearRegression | ||
lin_reg = LinearRegression() | ||
lin_reg.fit(X,y) | ||
|
||
#Fitting Polynomial Regression to the dataset | ||
from sklearn.preprocessing import PolynomialFeatures | ||
poly_reg = PolynomialFeatures(degree=4) | ||
X_poly = poly_reg.fit_transform(X) #transform to matrix | ||
lin_reg_2 = LinearRegression() | ||
lin_reg_2.fit(X_poly,y) | ||
|
||
#Visusalizong Linear Regression | ||
plt.scatter(X,y, color= 'red') | ||
plt.plot(X, lin_reg.predict(X), color='blue') | ||
plt.title('Truth or Bluff(Linear Refression)') | ||
plt.xlabel('Position Level') | ||
plt.ylabel('Salary') | ||
plt.show() | ||
|
||
#Visusalizong Polynomial Regression | ||
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('Truth or Bluff(Linear Refression)') | ||
plt.xlabel('Position Level') | ||
plt.ylabel('Salary') | ||
plt.show() | ||
|
||
#Predicting new result with Linear Regression | ||
lin_reg.predict(6.5) | ||
|
||
#Predicting new result with Linear Regression | ||
lin_reg_2.predict(poly_reg.fit_transform(6.5)) |