This blog contains the code for salary prediction machine learning project using python.
STEP1:Installing requirements:
*pip install numpy
*pip install pandas
*pip install sklearn
STEP2:Importing modules
import numpy as np
import pandas as pd
STEP3:Reading CSV
data=pd.read_csv('Salary_Data.csv') # Dataset in Github
data
data
STEP4:Reshaping
x=data.YearsExperience.values.reshape(-1,1)
y=data.Salary.values.reshape(-1,1)
STEP5:Spliting the dataset
from sklearn.model_selection import train_test_split
xtrain,xtest,ytrain,ytest=train_test_split(x,y,test_size=0.3,random_state=0)
STEP6: LinearRegression formula
from sklearn.linear_model import LinearRegression
model=LinearRegression()
STEP7: Applying the formula & prediction
model.fit(x,y)
next_salary=model.predict([[6]])
print(int(next_salary))
STEP8: Accuray
model.score(xtrain,ytrain)
Full code:Github
No comments:
Post a Comment