Jasonntone commited on
Commit
65fa05a
1 Parent(s): d6df378

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +46 -0
app.py ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st # type: ignore
2
+ import numpy as np
3
+ import pandas as pd
4
+ import seaborn as sn
5
+ import matplotlib.pyplot as plt
6
+ from plotly import graph_objs as go
7
+ from sklearn.linear_model import LinearRegression
8
+
9
+ st.set_option('deprecation.showPyplotGlobalUse', False)
10
+
11
+ data = pd.read_csv('Salary_Data.csv')
12
+ st.write(data.head())
13
+ X = np.array(data[['YearsExperience']])
14
+ lr = LinearRegression()
15
+ lr.fit(X, np.array(data.Salary))
16
+
17
+ nav = st.sidebar.radio('Navigation',['Home','Prediction', 'About'])
18
+ if nav == 'Home':
19
+ col1,col2,col3 = st.columns([1,2,1])
20
+ with col2:
21
+ st.title('Salary Prediction')
22
+ st.image('salary.jpg',width=600)
23
+ if st.checkbox('Show Table'):
24
+ st.write(data)
25
+ graph = st.selectbox('What kind of graph you want to plot?',['Non interactive','Interactive'])
26
+ val = st.slider('Filter data using Years', 0,20)
27
+ data = data.loc[data.YearsExperience>= val]
28
+ if graph == 'Non interactive':
29
+ plt.figure(figsize=(10,5))
30
+ plt.scatter(data.YearsExperience,data.Salary)
31
+ plt.xlabel('Years of experience')
32
+ plt.ylabel('Salaries')
33
+ st.pyplot()
34
+ else:
35
+ layout = go.Layout(xaxis = dict(range=[0,16]),
36
+ yaxis = dict(range=[0,210000]))
37
+ fig = go.Figure(data=go.Scatter(x=data.YearsExperience,y=data.Salary,
38
+ mode='markers'),layout=layout)
39
+ st.plotly_chart(fig)
40
+ elif nav == 'Prediction':
41
+ st.header('Know your salary')
42
+ values = st.number_input('Enter your exp',0,20,step=1)
43
+ values = np.array(values).reshape(-1,1)
44
+ pred = lr.predict(values)[0]
45
+ if st.button('Predict'):
46
+ st.success(f"Your Predicted Salary is {round(pred)}")