Last active
June 28, 2020 03:13
-
-
Save codeperfectplus/ba90d861c9679542a3a0714a884e7cb1 to your computer and use it in GitHub Desktop.
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
## Importing the Libraries | |
import pandas as pd | |
import matplotlib.pyplot as plt | |
## 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() | |
## 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) | |
## Fit and Predict Model | |
from sklearn.linear_model import LinearRegression | |
lr = LinearRegression() | |
lr.fit(train_X, train_y) | |
## Predicting the Test set results | |
predicted_y = lr.predict(test_X) | |
## Comparing the Test Set with Predicted Values | |
df = pd.DataFrame({'Real Values':test_y,"Predict Value":predicted_y}) | |
df.head() | |
## 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.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment