Alcohol_Effects / app.py
mby026's picture
Update app.py
8fcf00d
import joblib
import pandas as pd
import streamlit as st
sex_dict = {'Female': 0, 'Male': 1}
address_dict = {'Urban': 0, 'Rural':1}
famsize_dict = {'Greater than 3': 0, 'Less than or equal to 3': 1}
Pstatus_dict = {'Living together': 0, 'Apart': 1}
Mjob_dict = {'at_home': 0, 'health': 1, 'other': 1, 'services': 1, 'teacher': 1}
Fjob_dict = {'at_home': 0, 'health': 1, 'other': 1, 'services': 1, 'teacher': 1}
schoolsup_dict = {'no': 0, 'yes': 1}
famsup_dict = {'no': 0, 'yes': 1}
activities_dict = {'no': 0, 'yes': 1}
higher_dict = {'no': 0, 'yes': 1}
romantic_dict = {'no': 0, 'yes': 1}
model = joblib.load('model.joblib')
unique_values = joblib.load('unique_values.joblib')
unique_sex = unique_values["sex"]
unique_address = unique_values["address"]
unique_famsize = unique_values["famsize"]
unique_Pstatus = unique_values["Pstatus"]
unique_Mjob = unique_values["Mjob"]
unique_Fjob = unique_values["Fjob"]
unique_schoolsup = unique_values["schoolsup"]
unique_famsup = unique_values["famsup"]
unique_activities = unique_values["activities"]
unique_higher = unique_values["higher"]
unique_romantic = unique_values["romantic"]
def main():
st.title("Predict Score")
with st.form("questionnaire"):
age = st.slider("student's age", min_value=0, max_value=100)
studytime = st.slider("weekly study time", min_value=0, max_value=10)
famrel = st.slider("quality of family relationships (from 1 - very bad to 5 - excellent)", min_value=1, max_value=5)
goout = st.slider("going out with friends (from 1 - very low to 5 - very high)", min_value=1, max_value=5)
Dalc = st.slider("workday alcohol consumption (from 1 - very low to 5 - very high)", min_value=1, max_value=5)
Walc = st.slider("weekend alcohol consumption (from 1 - very low to 5 - very high)", min_value=1, max_value=5)
health = st.slider("current health status (from 1 - very bad to 5 - very good)", min_value=1, max_value=5)
freetime = st.slider("free time after school (from 1 - very low to 5 - very high)", min_value=1, max_value=5)
absences = st.slider("number of school absences", min_value=0, max_value=100)
sex = st.selectbox("student's sex", unique_sex)
address = st.selectbox("student's home address type", unique_address)
famsize = st.selectbox("family size", unique_famsize)
Pstatus = st.selectbox("parent's cohabitation status", unique_Pstatus)
Mjob = st.selectbox("mother's job", unique_Mjob)
Fjob = st.selectbox("father's job", unique_Fjob)
schoolsup = st.selectbox("extra educational support", unique_schoolsup)
famsup = st.selectbox("family educational support", unique_famsup)
activities = st.selectbox("extra-curricular activities", unique_activities)
higher = st.selectbox("wants to take higher education", unique_higher)
romantic = st.selectbox("with a romantic relationship", unique_romantic)
clicked = st.form_submit_button("Predict Student's Score")
if clicked:
result = model.predict(pd.DataFrame({
"age": [age],
"studytime": [studytime],
"famrel": [famrel],
"goout": [goout],
"Dalc": [Dalc],
"Walc": [Walc],
"health": [health],
"freetime": [freetime],
"absences": [absences],
"sex": [sex_dict[sex]],
"address": [address_dict[address]],
"famsize": [famsize_dict[famsize]],
"Pstatus": [Pstatus_dict[Pstatus]],
"Mjob": [Mjob_dict[Mjob]],
"Fjob": [Fjob_dict[Fjob]],
"schoolsup": [schoolsup_dict[schoolsup]],
"famsup": [famsup_dict[famsup]],
"activities": [activities_dict[activities]],
"higher": [higher_dict[higher]],
"romantic": [romantic_dict[romantic]]
}))
result = result[0]
st.success('The predicted score is {:.2f}'.format(round(result, 2)))
if __name__=='__main__':
main()