0% found this document useful (0 votes)
3 views2 pages

Salary Prediction with Python Code

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)
3 views2 pages

Salary Prediction with Python Code

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

1 import pandas as pd

2 import numpy as np
3 import [Link] as plt
4 from [Link] import LinearSegmentedColormap
5
6 df = pd.read_csv(r"C:\Users\Adarsh Mishra\Downloads\[Link]")
7 df['xy'] = df[['year', 'salary']].product(axis=1)
8 df['xsq'] = df['year']**2
9 df['ysq'] = df['salary']**2
10 sumx = df['year'].sum()
11 sumy = df['salary'].sum()
12 sumxy = df['xy'].sum()
13 sumxsq = df['xsq'].sum()
14 sumysq = df['ysq'].sum()
15 n = df['year'].count()
16 m = ((n*sumxy)-(sumx*sumy))/((n*sumxsq)-(sumx**2))
17 yb = sumy/n
18 xb = sumx/n
19 c = yb - (m*xb)
20
21
22
23
24 [Link]("dark_background")
25 fig, ax = [Link](figsize=(8, 5))
26 [Link].set_facecolor("#0b0f26")
27 ax.set_facecolor("#0b0f26")
28 [Link]['bottom'].set_color('#888888')
29 [Link]['left'].set_color('#888888')
30 ax.tick_params(colors='#bbbbbb')
31
32 cmap = LinearSegmentedColormap.from_list("space_grad", ["#7F00FF", "#E100FF",
"#00FFFF"])
33
34 scatter = [Link]([Link], [Link], c=[Link](0,1,len(df)),
cmap=cmap, s=70, edgecolor='white', linewidth=0.3, alpha=0.9, zorder=3)
35
36 samx = [Link]([Link](), [Link](), 200)
37 samy = m*samx + c
38 for i in range(len(samx)-1):
39 [Link](samx[i:i+2], samy[i:i+2], color=cmap(i/len(samx)), linewidth=2.5,
alpha=0.9)
40
41 ax.set_xlabel('Years of experience', color='#dddddd', fontsize=12)
42 ax.set_ylabel('Salary', color='#dddddd', fontsize=12)
43 [Link](True, linestyle=':', linewidth=0.8, color='#888888', alpha=0.5)
44
45 [Link]()
46
47
48 sampx = float(input("enter:"))
49 sampy = (m*sampx) +c
50 print("The predicted salary is: ")
51

You might also like