Update app.py
Browse files
app.py
CHANGED
|
@@ -1,65 +1,67 @@
|
|
| 1 |
import joblib
|
| 2 |
import pandas as pd
|
|
|
|
| 3 |
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
'
|
| 7 |
-
'
|
| 8 |
-
'
|
| 9 |
-
'
|
| 10 |
-
'10th': 6,
|
| 11 |
-
'11th': 7,
|
| 12 |
-
'12th': 8,
|
| 13 |
-
'HS-grad': 9,
|
| 14 |
-
'Some-college': 10,
|
| 15 |
-
'Assoc-voc': 11,
|
| 16 |
-
'Assoc-acdm': 12,
|
| 17 |
-
'Bachelors': 13,
|
| 18 |
-
'Masters': 14,
|
| 19 |
-
'Prof-school': 15,
|
| 20 |
-
'Doctorate': 16
|
| 21 |
}
|
| 22 |
|
| 23 |
-
|
| 24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
unique_sex = unique_values["sex"]
|
| 32 |
-
unique_race = unique_values["race"]
|
| 33 |
-
unique_country = unique_values["native.country"]
|
| 34 |
|
| 35 |
def main():
|
| 36 |
-
st.title("
|
| 37 |
|
| 38 |
with st.form("questionaire"):
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
sex = # user's input
|
| 47 |
-
hours_per_week = # user's input
|
| 48 |
-
native_country = # user's input
|
| 49 |
|
|
|
|
| 50 |
# clicked==True only when the button is clicked
|
| 51 |
clicked = st.form_submit_button("Predict income")
|
| 52 |
if clicked:
|
| 53 |
-
result=model.predict(pd.DataFrame({"
|
| 54 |
-
"
|
| 55 |
"education": [EDU_DICT[education]],
|
| 56 |
-
"
|
| 57 |
-
"
|
| 58 |
-
"
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import joblib
|
| 2 |
import pandas as pd
|
| 3 |
+
import streamlit as st
|
| 4 |
|
| 5 |
+
EDU_DICT = {'some high school': 1,
|
| 6 |
+
'some college': 2,
|
| 7 |
+
'high school': 3,
|
| 8 |
+
"associate's degree": 4,
|
| 9 |
+
"bachelor's degree": 5,
|
| 10 |
+
"master's degree": 6
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
}
|
| 12 |
|
| 13 |
+
race = {'group A': 0,
|
| 14 |
+
'group B': 1,
|
| 15 |
+
'group C': 2,
|
| 16 |
+
'group D': 3,
|
| 17 |
+
'group E': 4
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
model = joblib.load('modelN.joblib')
|
| 21 |
+
unique_values = joblib.load('unique_valuesN.joblib')
|
| 22 |
|
| 23 |
+
unique_gender = unique_values["gender"]
|
| 24 |
+
unique_lunch = unique_values["lunch"]
|
| 25 |
+
unique_test_preparation_course = unique_values["test preparation course"]
|
| 26 |
+
unique_education = unique_values["parental level of education"]
|
| 27 |
+
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
def main():
|
| 30 |
+
st.title("Race Prediction")
|
| 31 |
|
| 32 |
with st.form("questionaire"):
|
| 33 |
+
gender = st.selectbox("gender", options = unique_gender)
|
| 34 |
+
lunch = st.selectbox("lunch", options = unique_lunch)
|
| 35 |
+
test = st.selectbox("test preparation course", options = unique_test_preparation_course)
|
| 36 |
+
education = st.selectbox("parental level of education", options = unique_education)
|
| 37 |
+
math_score = st.slider("math score", min_value = 1, max_value = 100)
|
| 38 |
+
reading_score = st.slider("reading score", min_value = 1, max_value = 100)
|
| 39 |
+
writing_score = st.slider("writing score", min_value = 1, max_value = 100)
|
|
|
|
|
|
|
|
|
|
| 40 |
|
| 41 |
+
|
| 42 |
# clicked==True only when the button is clicked
|
| 43 |
clicked = st.form_submit_button("Predict income")
|
| 44 |
if clicked:
|
| 45 |
+
result=model.predict(pd.DataFrame({"gender": [gender],
|
| 46 |
+
"lunch": [lunch],
|
| 47 |
"education": [EDU_DICT[education]],
|
| 48 |
+
"math score": [math_score],
|
| 49 |
+
"reading score": [reading_score],
|
| 50 |
+
"writing score": [writing_score]}))
|
| 51 |
+
|
| 52 |
+
if result[0] == 0:
|
| 53 |
+
result = 'group A'
|
| 54 |
+
elif result[0] == 1:
|
| 55 |
+
result = 'group B'
|
| 56 |
+
elif result[0] == 2:
|
| 57 |
+
result = 'group C'
|
| 58 |
+
elif result[0] == 3:
|
| 59 |
+
result = 'group D'
|
| 60 |
+
elif result[0] == 4:
|
| 61 |
+
result = 'group E'
|
| 62 |
+
else:
|
| 63 |
+
'ERROR'
|
| 64 |
+
st.success("Race Prediction is"+result)
|
| 65 |
+
|
| 66 |
+
if __name__ == "__main__":
|
| 67 |
+
main()
|