Spaces:
Runtime error
Runtime error
Commit
·
5deba94
1
Parent(s):
246b6ca
Update app.py
Browse files
app.py
CHANGED
@@ -2,66 +2,46 @@ import joblib
|
|
2 |
import pandas as pd
|
3 |
import streamlit as st
|
4 |
|
5 |
-
EDU_DICT = {'Preschool': 1,
|
6 |
-
'1st-4th': 2,
|
7 |
-
'5th-6th': 3,
|
8 |
-
'7th-8th': 4,
|
9 |
-
'9th': 5,
|
10 |
-
'10th': 6,
|
11 |
-
'11th': 7,
|
12 |
-
'12th': 8,
|
13 |
-
'HS-grad': 9,
|
14 |
-
'Some-college': 10,
|
15 |
-
'Assoc-voc': 11,
|
16 |
-
'Assoc-acdm': 12,
|
17 |
-
'Bachelors': 13,
|
18 |
-
'Masters': 14,
|
19 |
-
'Prof-school': 15,
|
20 |
-
'Doctorate': 16
|
21 |
-
}
|
22 |
-
|
23 |
-
model = joblib.load('model.joblib')
|
24 |
-
unique_values = joblib.load('unique_values.joblib')
|
25 |
-
|
26 |
-
unique_class = unique_values["workclass"]
|
27 |
-
unique_education = unique_values["education"]
|
28 |
-
unique_marital_status = unique_values["marital.status"]
|
29 |
-
unique_relationship = unique_values["relationship"]
|
30 |
-
unique_occupation = unique_values["occupation"]
|
31 |
-
unique_gender = unique_values["gender"]
|
32 |
-
unique_race = unique_values["race"]
|
33 |
-
unique_country = unique_values["native.country"]
|
34 |
-
|
35 |
def main():
|
36 |
st.title("Adult Income Analysis")
|
37 |
|
38 |
-
with st.form("
|
39 |
-
age = st.slider("Age",min_value
|
40 |
-
workclass = st.selectbox("
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
|
|
|
|
|
|
|
|
49 |
|
50 |
clicked = st.form_submit_button("Predict income")
|
51 |
if clicked:
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
63 |
result = '>50K' if result[0] == 1 else '<=50K'
|
64 |
-
|
65 |
|
66 |
-
if __name__=='__main__':
|
67 |
main()
|
|
|
2 |
import pandas as pd
|
3 |
import streamlit as st
|
4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
def main():
|
6 |
st.title("Adult Income Analysis")
|
7 |
|
8 |
+
with st.form("questionnaire"):
|
9 |
+
age = st.slider("Age", min_value=10, max_value=100)
|
10 |
+
workclass = st.selectbox("Workclass", unique_class)
|
11 |
+
fnlwgt = st.selectbox("fnlwgt", unique_fnlwgt)
|
12 |
+
education = st.selectbox("Education", unique_education)
|
13 |
+
educational_num = st.selectbox("Educational Num", unique_education_num)
|
14 |
+
marital_status = st.selectbox("Marital Status", unique_marital_status)
|
15 |
+
occupation = st.selectbox("Occupation", unique_occupation)
|
16 |
+
relationship = st.selectbox("Relationship", unique_relationship)
|
17 |
+
race = st.selectbox("Race", unique_race)
|
18 |
+
gender = st.selectbox("Gender", unique_gender)
|
19 |
+
capital_gain = st.selectbox("Capital Gain", unique_capital_gain)
|
20 |
+
capital_loss = st.selectbox("Capital Loss", unique_capital_loss)
|
21 |
+
hours_per_week = st.slider("Hours per week", min_value=1, max_value=100)
|
22 |
+
native_country = st.selectbox("Country", unique_country)
|
23 |
|
24 |
clicked = st.form_submit_button("Predict income")
|
25 |
if clicked:
|
26 |
+
education_encoded = EDU_DICT.get(education, 0) # Default to 0 if education is not found
|
27 |
+
result = model.predict(pd.DataFrame({
|
28 |
+
"age": [age],
|
29 |
+
"workclass": [workclass],
|
30 |
+
"fnlwgt": [fnlwgt],
|
31 |
+
"education": [education_encoded],
|
32 |
+
"educational-num": [educational_num],
|
33 |
+
"marital.status": [marital_status],
|
34 |
+
"occupation": [occupation],
|
35 |
+
"relationship": [relationship],
|
36 |
+
"race": [race],
|
37 |
+
"gender": [gender],
|
38 |
+
"capital_gain": [capital_gain],
|
39 |
+
"capital_loss": [capital_loss],
|
40 |
+
"hours.per.week": [hours_per_week],
|
41 |
+
"native.country": [native_country]
|
42 |
+
}))
|
43 |
result = '>50K' if result[0] == 1 else '<=50K'
|
44 |
+
st.success('The predicted income is {}'.format(result))
|
45 |
|
46 |
+
if __name__ == '__main__':
|
47 |
main()
|