File size: 3,009 Bytes
ef55d35
 
843afd7
ef55d35
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
843afd7
 
ef55d35
 
 
 
 
 
 
 
 
 
843afd7
 
ef55d35
843afd7
 
 
 
 
 
 
 
 
 
8395c82
ef55d35
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7f6f1f4
 
 
 
843afd7
 
304379d
843afd7
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
import joblib
import pandas as pd
import streamlit as st #<-

EDU_DICT = {'Preschool': 1,
            '1st-4th': 2,
            '5th-6th': 3,
            '7th-8th': 4,
            '9th': 5,
            '10th': 6,
            '11th': 7,
            '12th': 8,
            'HS-grad': 9, 
            'Some-college': 10,
            'Assoc-voc': 11,
            'Assoc-acdm': 12,
            'Bachelors': 13,
            'Masters': 14,
            'Prof-school': 15,
            'Doctorate': 16
            }

model = joblib.load('model.joblib') #<-
unique_values = joblib.load('unique_values.joblib') #<-
    
unique_class =  unique_values["workclass"]
unique_education =  unique_values["education"]
unique_marital_status =  unique_values["marital.status"]
unique_relationship =  unique_values["relationship"]
unique_occupation =  unique_values["occupation"]
unique_sex =  unique_values["sex"]
unique_race = unique_values["race"]
unique_country =  unique_values["native.country"]

def main(): #<- defined main
    st.title("Adult Income") #<- app name

    with st.form("questionaire"): #<- input from user 
        age = st.slider('Age',min_value=10, max_value=100) #<-
        workclass = st.selectbox('Workclass',options=unique_class) #<-
        education = st.selectbox('Education',options=unique_education) #<-
        Marital_Status = st.selectbox('Marital_status',options=unique_marital_status) #<-
        occupation = st.selectbox('occupation',options=unique_occupation) #<-
        relationship = st.selectbox('relationship',options=unique_relationship) #<-
        race = st.selectbox('race',options=unique_race) #<-
        sex =st.selectbox('sex',options=unique_sex) #<-
        hours_per_week =  st.slider('hours_per_week',min_value=1, max_value=100) #<-
        native_country =st.selectbox('native_country',options=unique_country) #<-

        # clicked==True only when the button is clicked
        clicked = st.form_submit_button("Predict income")
        if clicked:
            result=model.predict(pd.DataFrame({"age": [age],
                                               "workclass": [workclass],
                                               "education": [EDU_DICT[education]],
                                               "marital.status": [Marital_Status],
                                               "occupation": [occupation],
                                               "relationship": [relationship],
                                               "race": [race],
                                               "sex": [sex],
                                               "hours.per.week": [hours_per_week],
                                               "native.country": [native_country]}))
            # Show prediction
            result= '>50k' if result[0]==1 else '<=50k'
            #print report 
            st.success("Your predictor income is "+result)
            
# Run main() 
#when import but dont wanna run main so..
if __name__== "__main__":
    main()