Spaces:
Runtime error
Runtime error
File size: 3,746 Bytes
7c5d2af 64a5096 b544d4a f084cde b544d4a 86e79e6 b544d4a 86e79e6 b544d4a 64a5096 7c5d2af b544d4a 7c5d2af 5deba94 64a5096 86e79e6 64a5096 9ed0d89 64a5096 5deba94 64a5096 7c5d2af fdf232a 64a5096 86e79e6 64a5096 86e79e6 64a5096 fdf232a c9b0186 7c5d2af 18cb2f3 5deba94 79f7f77 64a5096 |
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 73 74 75 76 77 78 79 80 |
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 (2).joblib')
unique_values = joblib.load('unique_values (2).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"]
print(list(unique_values.keys()))
def main():
st.title("Adult Income")
with st.form("questionnaire"):
age = st.slider("Age", min_value=10, max_value=100)
workclass = st.selectbox("Workclass", options=unique_class)
fnlwgt = st.selectbox("fnlwgt", options=unique_fnlwgt) # ต้องกำหนด unique_fnlwgt ก่อนใช้
education = st.selectbox("Education", options=unique_education)
educational_num = st.selectbox("Educational Num", options=unique_education_num) # ต้องกำหนด unique_education_num ก่อนใช้
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) # ต้องกำหนด unique_gender ก่อนใช้
capital_gain = st.selectbox("Capital Gain", options=unique_capital_gain) # ต้องกำหนด unique_capital_gain ก่อนใช้
capital_loss = st.selectbox("Capital Loss", options=unique_capital_loss) # ต้องกำหนด unique_capital_loss ก่อนใช้
hours_per_week = st.slider("Hours per week", min_value=1, max_value=100)
native_country = st.selectbox("Country", options=unique_country)
clicked = st.form_submit_button("predict income")
if clicked:
education_encoded = EDU_DICT.get(education, 0) # Default to 0 if education is not found
result = model.predict(pd.DataFrame({"age": [age],
"workclass": [workclass],
"fnlwgt": [fnlwgt],
"education": [education_encoded],
"educational-num": [educational_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]}))
result = '>50K' if result[0] == 1 else '<=50K'
st.success('The predicted income is {}'.format(result))
if __name__ == '__main__':
main()
|