hansaal/Census-Income-Prediction-Tool
0
1import streamlit as st
2import pandas as pd
3import numpy as np
4import pickle
5import json
6
7# function run
8def run():
9
10 # with open('list_num_cols.txt', 'r') as file_1:
11 # list_num_cols = json.load(file_1)
12
13 # with open('list_cat_cols.txt', 'r') as file_2:
14 # list_cat_cols = json.load(file_2)
15
16 # with open('encoder.pkl', 'rb') as file_3:
17 # encoders = pickle.load(file_3)
18
19 # with open('scaler.pkl', 'rb') as file_4:
20 # fitted_scaler = pickle.load(file_4)
21
22 # with open('best_ada_model.pkl', 'rb') as file_5:
23 # best_ada_model = pickle.load(file_5)
24
25 st.title('Predict Income')
26
27 with st.form('form_input'):
28
29 age = st.slider("Age", min_value=17, max_value=90, value=30)
30 fnlwgt = st.number_input("Final Weight (fnlwgt)", min_value=1, max_value=1000000, value=100000)
31 workclass = st.selectbox("Workclass", ["Private", "Self-emp-not-inc", "Self-emp-inc", "Federal-gov", "Local-gov", "State-gov", "Without-pay", "Never-worked"])
32 education = st.selectbox("Education", ["Bachelors", "Some-college", "11th", "HS-grad", "Prof-school", "Assoc-acdm", "Assoc-voc", "9th", "7th-8th", "12th", "Masters", "Doctorate", "Preschool"])
33 marital_status = st.selectbox("Marital Status", ["Married-civ-spouse", "Divorced", "Never-married", "Separated", "Widowed", "Married-spouse-absent", "Married-AF-spouse"])
34 occupation = st.selectbox("Occupation", ["Tech-support", "Craft-repair", "Other-service", "Sales", "Exec-managerial", "Prof-specialty", "Handlers-cleaners", "Machine-op-inspct", "Adm-clerical", "Farmers-farm", "Transport-moving", "Priv-house-serv", "Protective-serv", "Armed-Forces", "Unemployed", "Unknown"])
35 relationship = st.selectbox("Relationship", ["Wife", "Own-child", "Husband", "Not-in-family", "Other-relative", "Unmarried"])
36 race = st.selectbox("Race", ["White", "Asian-Pac-Islander", "Amer-Indian-Eskimo", "Other", "Black"])
37 sex = st.selectbox("Sex", ["Female", "Male"])
38 capital_gain = st.number_input("Capital Gain", min_value=0, max_value=1000000, value=0)
39 capital_loss = st.number_input("Capital Loss", min_value=0, max_value=1000000, value=0)
40 hours_per_week = st.slider("Hours per Week", min_value=1, max_value=99, value=40)
41 native_country = st.selectbox("Native Country", ["United-States", "Cambodia", "England", "Puerto-Rico", "Canada", "Germany", "Outlying-US(Guam-USVI-etc)", "India", "Japan", "Greece", "South", "China", "Cuba", "Iran", "Honduras", "Philippines", "Italy", "Poland", "Jamaica", "Vietnam", "Mexico", "Portugal", "Ireland", "France", "Dominican-Republic", "Laos", "Ecuador", "Taiwan", "Haiti", "Columbia", "Hungary", "Guatemala", "Nicaragua", "Scotland", "Thailand", "Yugoslavia", "El-Salvador", "Trinidad&Tobago", "Peru", "Hong", "Holand-Netherlands"])
42
43 submitted = st.form_submit_button('Predict')
44
45 # data inference
46 data_inf = {
47 'age': 22,
48 'workclass': 'Private',
49 'fnlwgt': 77054,
50 'education':'Some-college',
51 'education.num':10,
52 'marital.status':'Widowed',
53 'occupation':'Dentist',
54 'relationship':'Not-in-family',
55 'race':'White',
56 'sex':'Female',
57 'capital.gain': 0,
58 'capital.loss': 0,
59 'hours.per.week': 18,
60 'native.country':'United-States',
61 }
62
63 data_inf = pd.DataFrame([data_inf])
64 data_inf
65
66 # if submitted:
67 # data_inf = data_inf[list_num_cols]
68
69 # data_inf = data_inf.apply(pd.to_numeric, errors='coerce').fillna(0)
70
71 # data_inf_scaled = fitted_scaler.transform(data_inf)
72
73 # data_inf_encoded = encoders.transform(data_inf_scaled)
74
75 # y_pred_inf = best_ada_model.predict(data_inf_encoded)
76
77 # st.write('# Rating: ', str(int(y_pred_inf)))
78
79 