-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPy1.py
83 lines (43 loc) · 1.52 KB
/
Py1.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import streamlit as st
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import pickle
import urllib.request
url ='https://github.com/knightmaiga/Stremlit_proto_novice/raw/main/Salary_Data.csv'
response = urllib.request.urlopen(url)
data=pd.read_csv(response)
x=data['YearsExperience']
st.write("X--> Years of Experience",x)
y=data['Salary']
st.write("Y--> Salary",y)
m=st.sidebar.radio("Menu",['Home','Prediction'])
st.title("Salary Prediction")
if m=='Home':
st.subheader("EDA")
st.write("Shape")
st.write(data.shape)
st.write("Head")
st.write(data.head())
st.write("Dataset Information")
st.write(data.describe())
fig, ax=plt.subplots(figsize=(10,5))
plt.xlabel("Years of Experience")
plt.ylabel("Salary")
plt.title("Years of Experience VS Salary")
plt.scatter(x,y)
st.pyplot(fig)
elif m=='Prediction':
st.subheader("PREDICTION")
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=np.array(x).reshape(-1,1)
y=np.array(y).reshape(-1,1)
from sklearn.linear_model import LinearRegression
regressor=LinearRegression()
regressor.fit(x,y)
exp=st.number_input("Experience in Years:",0,42,1)
exp=np.array(exp).reshape(1,-1)
prediction=regressor.predict(exp)[0]
if st.button("Salary Prediction"):
st.write(f"{prediction}")