pattawat commited on
Commit
d977b3f
1 Parent(s): 7f7e017

Upload app (1).py

Browse files
Files changed (1) hide show
  1. app (1).py +69 -0
app (1).py ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import joblib
2
+ import pandas as pd
3
+ import streamlit as st #เอาไว้ถามuser ว่าจะใส่อะไรบ้าง
4
+
5
+
6
+ EDU_DICT = {'Preschool': 1,
7
+ '1st-4th': 2,
8
+ '5th-6th': 3,
9
+ '7th-8th': 4,
10
+ '9th': 5,
11
+ '10th': 6,
12
+ '11th': 7,
13
+ '12th': 8,
14
+ 'HS-grad': 9,
15
+ 'Some-college': 10,
16
+ 'Assoc-voc': 11,
17
+ 'Assoc-acdm': 12,
18
+ 'Bachelors': 13,
19
+ 'Masters': 14,
20
+ 'Prof-school': 15,
21
+ 'Doctorate': 16
22
+ }
23
+
24
+ model = joblib.load('model.joblib')
25
+ unique_values = joblib.load('unique_values.joblib')
26
+
27
+ unique_class = unique_values["workclass"]
28
+ unique_education = unique_values["education"]
29
+ unique_marital_status = unique_values["marital.status"]
30
+ unique_relationship = unique_values["relationship"]
31
+ unique_occupation = unique_values["occupation"]
32
+ unique_sex = unique_values["sex"]
33
+ unique_race = unique_values["race"]
34
+ unique_country = unique_values["native.country"]
35
+
36
+ def main():
37
+ st.title("Adult Income")
38
+
39
+ with st.form("questionaire"):
40
+ age = st.slider("Age",min_value = 10 , max_value=100)
41
+ workclass = st.selectbox("Workcalss", options = unique_class)
42
+ education = st.selectbox("Education", options = unique_education)
43
+ Marital_Status = st.selectbox("Marital status", options = unique_marital_status)
44
+ occupation = st.selectbox("Occupation", options = unique_occupation)
45
+ relationship = st.selectbox("Relationship", options = unique_relationship)
46
+ race = st.selectbox("Race", options = unique_race)
47
+ sex =st.selectbox("Sex", options = unique_sex)
48
+ hours_per_week =st.slider("Hours per week",min_value = 1 , max_value=100)
49
+ native_country =st.selectbox("Native country", options = unique_country)
50
+
51
+ # clicked==True only when the button is clicked
52
+ clicked = st.form_submit_button("Predict income")
53
+ if clicked:
54
+ result=model.predict(pd.DataFrame({"age": [age],
55
+ "workclass": [workclass],
56
+ "education": [EDU_DICT[education]],
57
+ "marital.status": [Marital_Status],
58
+ "occupation": [occupation],
59
+ "relationship": [relationship],
60
+ "race": [race],
61
+ "sex": [sex],
62
+ "hours.per.week": [hours_per_week],
63
+ "native.country": [native_country]}))
64
+
65
+ result = '>50k' if result[0] == 1 else '<=50k'
66
+ st.success("Your Predicted income is"+result)
67
+
68
+ if __name__ == "__main__":
69
+ main()