import streamlit as st # type: ignore import numpy as np import pandas as pd import seaborn as sn import matplotlib.pyplot as plt from plotly import graph_objs as go from sklearn.linear_model import LinearRegression st.set_option('deprecation.showPyplotGlobalUse', False) data = pd.read_csv('Salary_Data.csv') st.write(data.head()) X = np.array(data[['YearsExperience']]) lr = LinearRegression() lr.fit(X, np.array(data.Salary)) nav = st.sidebar.radio('Navigation',['Home','Prediction', 'About']) if nav == 'Home': col1,col2,col3 = st.columns([1,2,1]) with col2: st.title('Salary Prediction') st.image('salary.jpg',width=600) if st.checkbox('Show Table'): st.write(data) graph = st.selectbox('What kind of graph you want to plot?',['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.xlabel('Years of experience') plt.ylabel('Salaries') st.pyplot() else: 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) elif nav == 'Prediction': st.header('Know your salary') values = st.number_input('Enter your exp',0,20,step=1) values = np.array(values).reshape(-1,1) pred = lr.predict(values)[0] if st.button('Predict'): st.success(f"Your Predicted Salary is {round(pred)}")