Simple Linear Regression : Machine Learning Practical - Number Of experiance vs Salary
- It is the Study of two variables.
- One variable is called as In Dependent variable.(x)
- And Other Variable is called as Dependent Variable(y)
Example : Salary dependent on Number Of experience U have.
- So in this example we can say that : Salary is dependent variable and Experience is Independent variable.
- It is used for predictions.
- Here we try to predict the change in dependent variable according to change in independent variable.
Regression y=a+bx;
Here y is dependent variable and x is called as Independent Variable .
In this example sales is dependent on price : sales dependents on prince
In this Example Salary is Dependent Variable and Number of Years of Experience is Independent.
Created on Fri May 25 18:53:42 2017
@author: Govind
"""
import numpy as mp
#this library help to chart graphs
import matplotlib.pyplot as plt
import pandas as pd
import os
os.chdir('C:\\Users\\Govind\\Desktop\\Machine Learning A-Z\\Part 2 - Regression\\Section 4 - Simple Linear Regression')
wd=os.getcwd();
print(wd)
dataset=pd.read_csv('Salary_data.csv')
print (dataset)
#removing last column - x is an independent
#variable so storing values of independent
#in x
x=dataset.iloc[:,:-1].values;
y=dataset.iloc[:,1].values;
print(x)
print(y)
from sklearn.cross_validation import train_test_split
x_train,x_test,y_train,y_test=train_test_split(x,y,test_size=1/3,random_state=0)
#fit simple linier regression on training set
from sklearn.linear_model import LinearRegression
regressor=LinearRegression()
regressor.fit(x_train,y_train)
y_pred=regressor.predict(x_test)
plt.scatter(x_train,y_train,color='red')
plt.plot(x_train,regressor.predict(x_train))
plt.title('Salary vs Experiance')
plt.xlabel('Year of experiance')
plt.ylabel('Salary')
plt.show()
great post. Loved it absolutely. python training in Chennai
ReplyDelete