Source Code Link: https://drive.google.com/drive/folders/1izq7lIUDex8yFgWp5oNKbZX0HTcvNgpa
Dataset Link : https://drive.google.com/file/d/139GGmfrf6QGCXMAwCI6P9Gs0O8Ubh0Mw/view?usp=drive_link
import pandas as pd
dataset=pd.read_csv("<https://raw.githubusercontent.com/RamishaRaniK/dataset/main/Salary_Data.csv>")
dataset
indep=dataset[["YearsExperience"]]
indep
dep=dataset[["Salary"]]
dep
import matplotlib.pyplot as plt
plt.scatter(indep,dep)
plt.xlabel("experience")
plt.ylabel("salary")
plt.show()
from sklearn.model_selection import train_test_split
X_train,X_test,y_train,y_test=train_test_split(indep,dep,test_size=0.30,random_state=0)
X_train.shape
len(X_train)
X_train
y_test.shape
from sklearn.linear_model import LinearRegression
regressor=LinearRegression()
regressor.fit(X_train,y_train)
weight=regressor.coef_
weight
bais=regressor.intercept_
print(bais)
y_pred=regressor.predict(X_test)
y_pred
predActual=pd.DataFrame(index=range(0,10))
y_test.index=range(0,9)
y_test
predActual["ActualValue"]=y_test
y_pred_table=pd.DataFrame(y_pred,columns=["Pred"])
y_pred_table
predActual["PredValue"]=y_pred_table
y_pred
predActual
from sklearn.metrics import r2_score
r=r2_score(y_test,y_pred)
r
import pickle
filename="finalModel.sav"
pickle.dump(regressor,open(filename,'wb'))
load_model=pickle.load(open("finalModel.sav",'rb'))
result=load_model.predict([[15]])
result
dir(pd)
# Import libraries
# Importing the libraries
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
#data variablecsv valus is stored
data = pd.read_csv('Salary_Data.csv')
data
independent = data[["YearsExperience"]] #Indepedent Variable,years of Experience, datatype float
dependent = data[["Salary"]] # Depedent Variable, Salary, datatype float
plt.scatter(independent,dependent)
plt.xlabel('YearsExperience',fontsize=20)
plt.ylabel('Salary',fontsize=20)
plt.show()
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(independent,dependent, test_size = 1/3, random_state = 0)
y_test
from sklearn.linear_model import LinearRegression
regressor = LinearRegression()
regressor.fit(X_train, y_train)#y=W*x1+b0 for this equation we got value for b1 and bo
# Viewing the b1 and bo value
weight=regressor.coef_
print("Weight of the model={}".format(weight))
bais=regressor.intercept_
print("Intercept of the model={}".format(bais))
y_pred=regressor.predict(X_test)
y_pred
from sklearn.metrics import r2_score
r_score=r2_score(y_test,y_pred)
r_score
import pickle
filename = 'finalized_model.sav'
pickle.dump(regressor, open(filename, 'wb'))
loaded_model = pickle.load(open('finalized_model.sav', 'rb'))
result = loaded_model.predict([[15]])
print(result)
prediction_input=int(input("Enter the Prediction input value:"))
Future_Prediction=regressor.predict([[prediction_input]])# change the paramter,play with it.
print("Future_Prediction={}".format(Future_Prediction))
import pickle
load_model=pickle.load(open("finalModel.sav",'rb'))
result=load_model.predict([[0]])
result
| YearsExperience | Salary |
|---|---|
| 1.1 | 39343 |
| 1.3 | 46205 |
| 1.5 | 37731 |
| 2.0 | 43525 |
| 2.2 | 39891 |
| 2.9 | 56642 |
| 3.0 | 60150 |
| 3.2 | 54445 |
| 3.2 | 64445 |
| 3.7 | 57189 |
| 3.9 | 63218 |
| 4.0 | 55794 |
| 4.0 | 56957 |
| 4.1 | 57081 |
| 4.5 | 61111 |
| 4.9 | 67938 |
| 5.1 | 66029 |
| 5.3 | 83088 |
| 5.9 | 81363 |
| 6.0 | 93940 |
| 6.8 | 91738 |
| 7.1 | 98273 |
| 7.9 | 101302 |
| 8.2 | 113812 |
| 8.7 | 109431 |
| 9.0 | 105582 |
| 9.5 | 116969 |
| 9.6 | 112635 |
| 10.3 | 122391 |
| 10.5 | 121872 |