-
Notifications
You must be signed in to change notification settings - Fork 35
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
Showing
1 changed file
with
78 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,78 @@ | ||
# Simple Linear Regression | ||
# Importing the libraries | ||
|
||
import numpy as np | ||
import matplotlib.pyplot as plt | ||
import pandas as pd | ||
|
||
# Importing the datasets | ||
|
||
datasets = pd.read_csv('Salary_Data.csv') | ||
|
||
X = datasets.iloc[:, :-1].values | ||
Y = datasets.iloc[:, 1].values | ||
|
||
# Splitting the dataset into the Training set and Test set | ||
|
||
from sklearn.model_selection import train_test_split | ||
X_Train, X_Test, Y_Train, Y_Test = train_test_split(X, Y, test_size = 1/3, random_state = 0) | ||
|
||
# Feature Scaling | ||
|
||
"""from sklearn.preprocessing import StandardScaler | ||
sc_X = StandardScaler() | ||
X_Train = sc_X.fit_transform(X_Train) | ||
X_Test = sc_X.transform(X_Test) | ||
""" | ||
|
||
# Fitting Simple Linear Regression to the training set | ||
|
||
from sklearn.linear_model import LinearRegression | ||
regressor = LinearRegression() | ||
regressor.fit(X_Train, Y_Train) | ||
|
||
# Predicting the Test set result  | ||
|
||
Y_Pred = regressor.predict(X_Test) | ||
|
||
|
||
# Visualising the Training set results | ||
|
||
plt.scatter(X_Train, Y_Train, color = 'red') | ||
plt.plot(X_Train, regressor.predict(X_Train), color = 'blue') | ||
plt.title('Salary vs Experience (Training Set)') | ||
plt.xlabel('Years of experience') | ||
plt.ylabel('Salary') | ||
plt.show() | ||
|
||
# Visualising the Test set results | ||
|
||
plt.scatter(X_Test, Y_Test, color = 'red') | ||
plt.plot(X_Train, regressor.predict(X_Train), color = 'blue') | ||
plt.title('Salary vs Experience (Training Set)') | ||
plt.xlabel('Years of experience') | ||
plt.ylabel('Salary') | ||
plt.show() | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
 | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|