Ass2 PDF

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

10/18/22, 11:21 AM ass2 (1) - Jupyter Notebook

In [20]:

import pandas as pd
import numpy as np
from sklearn import linear_model
import matplotlib.pyplot as plt
from word2number import w2n

In [21]:

d = pd.read_csv("hiring.csv")
d
Out[21]:

experience test_score(out of 10) interview_score(out of 10) salary($)

0 NaN 8.0 9 50000

1 NaN 8.0 6 45000

2 five 6.0 7 60000

3 two 10.0 10 65000

4 seven 9.0 6 70000

5 three 7.0 10 62000

6 ten NaN 7 72000

7 eleven 7.0 8 80000

In [22]:

d.head(210)
Out[22]:

experience test_score(out of 10) interview_score(out of 10) salary($)

0 NaN 8.0 9 50000

1 NaN 8.0 6 45000

2 five 6.0 7 60000

3 two 10.0 10 65000

4 seven 9.0 6 70000

5 three 7.0 10 62000

6 ten NaN 7 72000

7 eleven 7.0 8 80000

localhost:8888/notebooks/Downloads/ass2 (1).ipynb 1/5


10/18/22, 11:21 AM ass2 (1) - Jupyter Notebook

In [23]:

d.experience = d.experience.fillna("zero")
d
Out[23]:

experience test_score(out of 10) interview_score(out of 10) salary($)

0 zero 8.0 9 50000

1 zero 8.0 6 45000

2 five 6.0 7 60000

3 two 10.0 10 65000

4 seven 9.0 6 70000

5 three 7.0 10 62000

6 ten NaN 7 72000

7 eleven 7.0 8 80000

In [24]:

d.experience = d.experience.apply(w2n.word_to_num)
d
Out[24]:

experience test_score(out of 10) interview_score(out of 10) salary($)

0 0 8.0 9 50000

1 0 8.0 6 45000

2 5 6.0 7 60000

3 2 10.0 10 65000

4 7 9.0 6 70000

5 3 7.0 10 62000

6 10 NaN 7 72000

7 11 7.0 8 80000

In [25]:

import math
median_test_score = math.floor(d['test_score(out of 10)'].mean())
median_test_score
Out[25]:

localhost:8888/notebooks/Downloads/ass2 (1).ipynb 2/5


10/18/22, 11:21 AM ass2 (1) - Jupyter Notebook

In [26]:

d['test_score(out of 10)'] = d['test_score(out of 10)'].fillna(median_test_score)


d
Out[26]:

experience test_score(out of 10) interview_score(out of 10) salary($)

0 0 8.0 9 50000

1 0 8.0 6 45000

2 5 6.0 7 60000

3 2 10.0 10 65000

4 7 9.0 6 70000

5 3 7.0 10 62000

6 10 7.0 7 72000

7 11 7.0 8 80000

In [27]:

data = d[["experience","test_score(out of 10)","salary($)"]]

In [48]:

fig=plt.figure()
ax=fig.add_subplot(111,projection='3d')
n=100
ax.scatter(d["experience"],d["test_score(out of 10)"],d["salary($)"],color="red")
ax.set_xlabel("experience")
ax.set_ylabel("test_score(out of 10)")
ax.set_zlabel("salary($)")

Out[48]:

Text(0.5, 0, 'salary($)')

localhost:8888/notebooks/Downloads/ass2 (1).ipynb 3/5


10/18/22, 11:21 AM ass2 (1) - Jupyter Notebook

In [32]:

train = d[:(int((len(data)*0.8)))]
test = d[(int((len(data)*0.8))):]

In [38]:

reg = linear_model.LinearRegression()
reg.fit(d[['experience','test_score(out of 10)','interview_score(out of 10)']],d['salary

Out[38]:

LinearRegression()

In [40]:

# Using sklearn package to model data :


train_x = np.array(train[["experience"]])
train_y = np.array(train[["test_score(out of 10)"]])
reg.fit(train_x,train_y)

Out[40]:

LinearRegression()

In [43]:

reg.coef_
Out[43]:

array([[-0.05150215]])

In [44]:

reg.intercept_
Out[44]:

array([8.14592275])

localhost:8888/notebooks/Downloads/ass2 (1).ipynb 4/5


10/18/22, 11:21 AM ass2 (1) - Jupyter Notebook

In [46]:

ax.scatter(data["experience"],data["test_score(out of 10)"],data["salary($)"],color="red
plt.plot(train_x, reg.coef_*train_x + reg.intercept_, '-r')
ax.set_xlabel("experience")
ax.set_ylabel("test_score(out of 10)")
ax.set_zlabel("salary($)")
Out[46]:

Text(0.11410640661270847, 0.015287359751546234, 'salary($)')

In [ ]:

In [ ]:

In [ ]:

In [ ]:

In [ ]:

localhost:8888/notebooks/Downloads/ass2 (1).ipynb 5/5

You might also like