Spaces:
Sleeping
Sleeping
import joblib | |
import pandas as pd | |
import streamlib 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(): | |
st.title("Adult Income") | |
with st.form("questionaire"): | |
age = st.slider("Age",min_values=10, max_values=100)# user's input | |
workclass = st.selectbox("Workclass",options = unique_class)# user's input | |
education = st.selectbox("education",options = unique_education)# user's input | |
Marital_Status = st.selectbox("Marital status",options = unique_marital_status)# user's input | |
occupation = st.selectbox("ocupation",options = unique_occupation)# user's input | |
relationship = st.selectbox("relationship",options = unique_relationship)# user's input | |
race = st.selectbox("race",options = unique_race)# user's input | |
sex = st.selectbox("sex",options = unique_sex)# user's input | |
hours_per_week = st.slider("Hours per week",min_values=1, max_values=100)# user's input | |
native_country = st.selectbox("Native country",options = unique_country)# user's input | |
# 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' | |
st.success("Your predict income is"+result) | |
if __name__ == '__main__': | |
main() | |
# Run main() |