-
Notifications
You must be signed in to change notification settings - Fork 0
/
predict_page.py
79 lines (66 loc) · 2.12 KB
/
predict_page.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
import streamlit as st
import pickle
import numpy as np
def load_model():
with open('saved_steps.pkl', 'rb') as file:
data = pickle.load(file)
return data
data = load_model()
regressor = data["model"]
le_country = data["le_country"]
le_education = data["le_education"]
le_remote = data["le_remote"]
mm = data["scaler"]
def show_predict_page():
st.title("Salary Prediction")
st.write("Select the country to predict the salary")
countries = (
"United States of America",
"Germany",
"United Kingdom of Great Britain and Northern Ireland",
"Canada",
"India",
"France",
"Netherlands",
"Australia",
"Brazil",
"Spain",
"Sweden",
"Italy",
"Poland",
"Switzerland",
"Denmark",
"Norway",
"Israel",
)
education_levels = (
"Bachelor’s degree",
"Less than a Bachelors",
"Master’s degree",
"Post grad",
)
remote_options = (
"Remote",
"In-person",
"Hybrid"
)
country = st.selectbox("Country:", countries)
education = st.selectbox("Education Level:", education_levels)
remote = st.selectbox("Remote Work:", remote_options)
age = st.slider("Age:", 18, 65, 25)
# Calculate the maximum possible experience based on age
max_experience = max(0, age - 18)
experience = st.slider("Years of Experience:", 0, max_experience, 3 if max_experience >= 3 else max_experience)
calculate = st.button("Calculate")
if calculate:
if experience > max_experience:
st.error("Experience cannot be greater than the age minus 18.")
else:
X = np.array([[country, age, remote, education, experience]])
X[:, 0] = le_country.transform([X[0, 0]])
X[:, 2] = le_remote.transform([X[0, 2]])
X[:, 3] = le_education.transform([X[0, 3]])
X = X.astype(float)
X = mm.transform(X)
salary = regressor.predict(X)
st.subheader(f"The estimated salary for the year 2023 is ${salary[0]:,.2f}")