Spaces:
Sleeping
Sleeping
import joblib | |
import pandas as pd | |
import streamlit as st | |
EDU_DICT = {'Bachelorsl': 1, | |
'Some-college': 2, | |
'11th': 3, | |
'HS-grad': 4, | |
'Prof-school': 5, | |
'Assoc-acdm': 6, | |
'Assoc-voc': 7, | |
'9th': 8, | |
'7th-8th': 9, | |
'12th': 10, | |
'Masters': 11, | |
'1st-4th': 12, | |
'10th': 13, | |
'Doctorate': 14, | |
'5th-6th': 15, | |
'Preschool': 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 = unique_values["marital-status"] | |
unique_occupation = unique_values["occupation"] | |
unique_relationship = unique_values["relationship"] | |
unique_race = unique_values["race"] | |
unique_sex = unique_values["sex"] | |
unique_country = unique_values["native-country"] | |
def main(): | |
st.title("Adult Income") | |
with st.form("questionaire"): | |
age = st.slider("Age" , min_value=17 , max_value=90) | |
workclass = st.selectbox("Workclass" , options=unique_class) | |
fnlwgt = st.slider("Fnlwgt" , min_value=12285 , max_value=1484705) | |
education = st.selectbox("Education" , options=unique_education) | |
education_num = st.slider("Education-num" , min_value=1 , max_value=16) | |
marital_status = st.selectbox("Marital-status" , options=unique_marital) | |
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) | |
capital_gain = st.slider("Capital-gain" , min_value=0 , max_value=99999) | |
capital_loss = st.slider("Capital-loss" , min_value=0 , max_value=4356) | |
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], | |
"fnlwgt": [fnlwgt], | |
"education": [EDU_DICT[education]], | |
"education_num": [education_num], | |
"marital_status": [marital_status], | |
"occupation": [occupation], | |
"relationship": [relationship], | |
"race": [race], | |
"sex": [sex], | |
"capital-gain": [capital_gain], | |
"capital-loss": [capital_loss], | |
"hours-per-week": [hours_per_week], | |
"native-country": [native_country]})) | |
# Show prediction | |
result = '>50k' if result[0] == 1 else '<=50k' | |
st.success("Your predicted income is "+result) | |
# Run main() | |
if __name__ == "__main__" : | |
main() | |