|
import joblib |
|
import pandas as pd |
|
import streamlit as st |
|
|
|
EDU_DICT = {'some high school': 1, |
|
'some college': 2, |
|
'high school': 3, |
|
"associate's degree": 4, |
|
"bachelor's degree": 5, |
|
"master's degree": 6 |
|
} |
|
|
|
race = {'group A': 0, |
|
'group B': 1, |
|
'group C': 2, |
|
'group D': 3, |
|
'group E': 4 |
|
} |
|
|
|
model = joblib.load('modelN.joblib') |
|
unique_values = joblib.load('unique_valuesN.joblib') |
|
|
|
unique_gender = unique_values["gender"] |
|
unique_lunch = unique_values["lunch"] |
|
unique_test_preparation_course = unique_values["test preparation course"] |
|
unique_education = unique_values["parental level of education"] |
|
|
|
|
|
def main(): |
|
st.title("Race Prediction") |
|
|
|
with st.form("questionaire"): |
|
gender = st.selectbox("gender", options = unique_gender) |
|
lunch = st.selectbox("lunch", options = unique_lunch) |
|
test = st.selectbox("test preparation course", options = unique_test_preparation_course) |
|
education = st.selectbox("parental level of education", options = unique_education) |
|
math_score = st.slider("math score", min_value = 1, max_value = 100) |
|
reading_score = st.slider("reading score", min_value = 1, max_value = 100) |
|
writing_score = st.slider("writing score", min_value = 1, max_value = 100) |
|
|
|
|
|
|
|
clicked = st.form_submit_button("Predict income") |
|
if clicked: |
|
result=model.predict(pd.DataFrame({"gender": [gender], |
|
"lunch": [lunch], |
|
"test preparation course": [test], |
|
"parental level of education": [EDU_DICT[education]], |
|
"math score": [math_score], |
|
"reading score": [reading_score], |
|
"writing score": [writing_score]})) |
|
|
|
if result[0] == 0: |
|
result = 'group A' |
|
elif result[0] == 1: |
|
result = 'group B' |
|
elif result[0] == 2: |
|
result = 'group C' |
|
elif result[0] == 3: |
|
result = 'group D' |
|
elif result[0] == 4: |
|
result = 'group E' |
|
else: |
|
'ERROR' |
|
st.success("Race Prediction is "+result) |
|
|
|
if __name__ == "__main__": |
|
main() |
|
|