0% found this document useful (0 votes)
11 views3 pages

Linear Reg 33

The document outlines a Python script for analyzing salary data based on years of experience using linear regression. It includes data loading, preprocessing, model training, and visualization of the results. The script employs libraries such as pandas, numpy, and matplotlib to facilitate data manipulation and plotting.

Uploaded by

160421737033
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views3 pages

Linear Reg 33

The document outlines a Python script for analyzing salary data based on years of experience using linear regression. It includes data loading, preprocessing, model training, and visualization of the results. The script employs libraries such as pandas, numpy, and matplotlib to facilitate data manipulation and plotting.

Uploaded by

160421737033
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

#Salary_Database

import numpy as nm
import matplotlib.pyplot as mtp
import pandas as pd

data_set = pd.read_csv('Salary_Data.csv')

data_set

1.1 39343

0 1.3 46205

1 1.5 37731

2 2.0 43525

3 2.2 39891

4 2.9 56642

5 3.0 60150

6 3.2 54445

7 3.2 64445

8 3.7 57189

9 3.9 63218

10 4.0 55794

11 4.0 56957

12 4.1 57081

13 4.5 61111

14 4.9 67938

15 5.1 66029

16 5.3 83088

17 5.9 81363

18 6.0 93940

19 6.8 91738

20 7.1 98273

21 7.9 101302

22 8.2 113812

23 8.7 109431

24 9.0 105582

25 9.5 116969

26 9.6 112635

27 10.3 122391

28 10.5 121872

x = data_set.iloc[:, :-1].values

y = data_set.iloc[:, 1].values

x
array([[ 1.3],
[ 1.5],
[ 2. ],
[ 2.2],
[ 2.9],
[ 3. ],
[ 3.2],
[ 3.2],
[ 3.7],
[ 3.9],
[ 4. ],
[ 4. ],
[ 4.1],
[ 4.5],
[ 4.9],
[ 5.1],
[ 5.3],
[ 5.9],
[ 6. ],
[ 6.8],
[ 7.1],
[ 7.9],
[ 8.2],
[ 8.7],
[ 9. ],
[ 9.5],
[ 9.6],
[10.3],
[10.5]])

array([ 46205, 37731, 43525, 39891, 56642, 60150, 54445, 64445,


57189, 63218, 55794, 56957, 57081, 61111, 67938, 66029,
83088, 81363, 93940, 91738, 98273, 101302, 113812, 109431,
105582, 116969, 112635, 122391, 121872], dtype=int64)

#Splitting the dataset into training and test set.


from sklearn.model_selection import train_test_split
x_train,x_test,y_train,y_test = train_test_split(x,y, test_size = 0.2, random_state = 0)

x_test

array([[2. ],
[7.1],
[8.7],
[4.5],
[4. ],
[9.5]])

#Fitting the simple linear regression model to the training dataset


from sklearn.linear_model import LinearRegression
regressor = LinearRegression()
regressor.fit(x_train, y_train)

▾ LinearRegression
LinearRegression()

#Prediction of Test and Training set result


y_pred = regressor.predict(x_test)
x_pred = regressor.predict(x_train)

x_pred

array([ 54560.25600817, 72489.8086666 , 61165.8806718 , 76264.45133154,


103630.61065232, 81926.41532894, 40405.34601466, 63996.8626705 ,
125334.80597569, 56447.57734063, 53616.59534193, 82870.07599517,
90419.36132504, 63053.20200427, 56447.57734063, 111179.89598218,
47010.9706783 , 38518.02468219, 100799.62865361, 74377.12999907,
64940.52333674])

mtp.scatter(x_train, y_train, color="green")


mtp.plot(x_train, x_pred, color="red")
mtp.title("Salary vs Experience(Training DataSet)")
mtp.xlabel("Year of Experience")
mtp.ylabel("Salary(In Rupees)")
mtp.show()
mtp.scatter(x_test, y_test, color="blue")
mtp.plot(x_train, x_pred, color="red")
mtp.title("Salary vs Experience(Training DataSet)")
mtp.xlabel("Year of Experience")
mtp.ylabel("Salary(In Rupees)")
mtp.show()

Loading [MathJax]/jax/output/CommonHTML/fonts/TeX/fontdata.js

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy