-
Notifications
You must be signed in to change notification settings - Fork 67
/
app.py
60 lines (50 loc) · 2.01 KB
/
app.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
import streamlit as st
import pandas as pd
from matplotlib import pyplot as plt
from plotly import graph_objs as go
from sklearn.linear_model import LinearRegression
import numpy as np
data = pd.read_csv("data//Salary_Data.csv")
x = np.array(data['YearsExperience']).reshape(-1,1)
lr = LinearRegression()
lr.fit(x,np.array(data['Salary']))
st.title("Salary Predictor")
st.image("data//sal.jpg",width = 800)
nav = st.sidebar.radio("Navigation",["Home","Prediction","Contribute"])
if nav == "Home":
if st.checkbox("Show Table"):
st.table(data)
graph = st.selectbox("What kind of Graph ? ",["Non-Interactive","Interactive"])
val = st.slider("Filter data using years",0,20)
data = data.loc[data["YearsExperience"]>= val]
if graph == "Non-Interactive":
plt.figure(figsize = (10,5))
plt.scatter(data["YearsExperience"],data["Salary"])
plt.ylim(0)
plt.xlabel("Years of Experience")
plt.ylabel("Salary")
plt.tight_layout()
st.pyplot()
if graph == "Interactive":
layout =go.Layout(
xaxis = dict(range=[0,16]),
yaxis = dict(range =[0,210000])
)
fig = go.Figure(data=go.Scatter(x=data["YearsExperience"], y=data["Salary"], mode='markers'),layout = layout)
st.plotly_chart(fig)
if nav == "Prediction":
st.header("Know your Salary")
val = st.number_input("Enter you exp",0.00,20.00,step = 0.25)
val = np.array(val).reshape(1,-1)
pred =lr.predict(val)[0]
if st.button("Predict"):
st.success(f"Your predicted salary is {round(pred)}")
if nav == "Contribute":
st.header("Contribute to our dataset")
ex = st.number_input("Enter your Experience",0.0,20.0)
sal = st.number_input("Enter your Salary",0.00,1000000.00,step = 1000.0)
if st.button("submit"):
to_add = {"YearsExperience":[ex],"Salary":[sal]}
to_add = pd.DataFrame(to_add)
to_add.to_csv("data//Salary_Data.csv",mode='a',header = False,index= False)
st.success("Submitted")