# -*- coding: utf-8 -*-
"""simple_linear_regression.ipynb

Automatically generated by Colaboratory.

Original file is located at
    https://colab.research.google.com/drive/19sVV5Qd7ciQ3z6MlswBo1Oag1PM0v0pi
"""

## Importing the Libraries
import pandas as pd
import matplotlib.pyplot as plt

## Step 2: Importing the dataset
data = pd.read_csv("https://raw.githubusercontent.com/codePerfectPlus/DataAnalysisWithJupyter/master/SalaryVsExperinceModel/Salary.csv")
X = data.iloc[:, :-1].values
y = data.iloc[:, -1].values
data.head()

## Step 3: Splitting the dataset into the Training set and Test set
from sklearn.model_selection import train_test_split
train_X, test_X, train_y, test_y = train_test_split(X, y, test_size = 0.3, random_state=12)

## Step 4: Training the Simple Linear Regression model on the Training set
from sklearn.linear_model import LinearRegression
lr = LinearRegression()
lr.fit(train_X, train_y)

## Step 5: Predicting the Test set results
predicted_y = lr.predict(test_X)

## Step 6: Comparing the Test Set with Predicted Values
df = pd.DataFrame({'Real Values':test_y,"Predict Value":predicted_y})
df.head()

## Step 7: Visualising the Test set results

plt.scatter(test_X, test_y, color = 'red')
plt.scatter(test_X, predicted_y, color = 'green')
plt.plot(train_X, lr.predict(train_X), color = 'black')
plt.title('Salary vs Experience (Result)')
plt.xlabel('YearsExperience')
plt.ylabel('Salary')
plt.savefig("slr.jpeg")
plt.show()
# -*- coding: utf-8 -*-
"""simple_linear_regression.ipynb

Automatically generated by Colaboratory.

Original file is located at
    https://colab.research.google.com/drive/19sVV5Qd7ciQ3z6MlswBo1Oag1PM0v0pi
"""

## Importing the Libraries
import pandas as pd
import matplotlib.pyplot as plt

## Step 2: Importing the dataset
data = pd.read_csv("https://raw.githubusercontent.com/codePerfectPlus/DataAnalysisWithJupyter/master/SalaryVsExperinceModel/Salary.csv")
X = data.iloc[:, :-1].values
y = data.iloc[:, -1].values
data.head()

## Step 3: Splitting the dataset into the Training set and Test set
from sklearn.model_selection import train_test_split
train_X, test_X, train_y, test_y = train_test_split(X, y, test_size = 0.3, random_state=12)

## Step 4: Training the Simple Linear Regression model on the Training set
from sklearn.linear_model import LinearRegression
lr = LinearRegression()
lr.fit(train_X, train_y)

## Step 5: Predicting the Test set results
predicted_y = lr.predict(test_X)

## Step 6: Comparing the Test Set with Predicted Values
df = pd.DataFrame({'Real Values':test_y,"Predict Value":predicted_y})
df.head()

## Step 7: Visualising the Test set results

plt.scatter(test_X, test_y, color = 'red')
plt.scatter(test_X, predicted_y, color = 'green')
plt.plot(train_X, lr.predict(train_X), color = 'black')
plt.title('Salary vs Experience (Result)')
plt.xlabel('YearsExperience')
plt.ylabel('Salary')
plt.savefig("slr.jpeg")
plt.show()
# -*- coding: utf-8 -*- simple_linear_regression.ipynb  Automatically generated by Colaboratory.  Original file is located at     https://colab.research.google.com/drive/19sVV5Qd7ciQ3z6MlswBo1Oag1PM0v0pi ## Importing the Libraries ## Step 2: Importing the dataset ## Step 3: Splitting the dataset into the Training set and Test set ## Step 4: Training the Simple Linear Regression model on the Training set ## Step 5: Predicting the Test set results ## Step 6: Comparing the Test Set with Predicted Values ## Step 7: Visualising the Test set results