Spaces:
Sleeping
Sleeping
ibrahim yıldız commited on
Upload 3 files
Browse files- app.py +87 -0
- my_model.h5 +3 -0
- scaler.pkl +3 -0
app.py
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import tensorflow as tf
|
| 4 |
+
from tensorflow.keras.models import load_model
|
| 5 |
+
from sklearn.preprocessing import StandardScaler
|
| 6 |
+
import numpy as np
|
| 7 |
+
import pickle
|
| 8 |
+
|
| 9 |
+
# Load the model
|
| 10 |
+
model = load_model('my_model.h5')
|
| 11 |
+
|
| 12 |
+
# Load the scaler
|
| 13 |
+
with open('scaler.pkl', 'rb') as f:
|
| 14 |
+
scaler = pickle.load(f)
|
| 15 |
+
|
| 16 |
+
# Create a sample input dataframe
|
| 17 |
+
sample_data = {
|
| 18 |
+
'Application mode': [1],
|
| 19 |
+
'Application order': [1],
|
| 20 |
+
'Previous qualification (grade)': [125],
|
| 21 |
+
'Admission grade': [119],
|
| 22 |
+
'Displaced': [1],
|
| 23 |
+
'Debtor': [0],
|
| 24 |
+
'Tuition fees up to date': [1],
|
| 25 |
+
'Gender': [0],
|
| 26 |
+
'Scholarship holder': [0],
|
| 27 |
+
'Age at enrollment': [18],
|
| 28 |
+
'Curricular units 1st sem (enrolled)': [6],
|
| 29 |
+
'Curricular units 1st sem (evaluations)': [8],
|
| 30 |
+
'Curricular units 1st sem (approved)': [4],
|
| 31 |
+
'Curricular units 1st sem (grade)': [11],
|
| 32 |
+
'Curricular units 2nd sem (enrolled)': [6],
|
| 33 |
+
'Curricular units 2nd sem (evaluations)': [9],
|
| 34 |
+
'Curricular units 2nd sem (approved)': [0],
|
| 35 |
+
'Curricular units 2nd sem (grade)': [0],
|
| 36 |
+
'Curricular units 2nd sem (without evaluations)': [1]
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
sample_df = pd.DataFrame(sample_data)
|
| 40 |
+
|
| 41 |
+
# Function to get user input
|
| 42 |
+
def get_user_input():
|
| 43 |
+
input_data = {
|
| 44 |
+
'Application mode': 1,
|
| 45 |
+
'Application order': 1,
|
| 46 |
+
'Previous qualification (grade)': st.number_input('Previous qualification (grade)', value=int(sample_df['Previous qualification (grade)'][0])),
|
| 47 |
+
'Admission grade': st.number_input('Admission grade', value=int(sample_df['Admission grade'][0])),
|
| 48 |
+
'Displaced': st.selectbox('Displaced', options=[0, 1], format_func=lambda x: 'Yes' if x == 1 else 'No'),
|
| 49 |
+
'Debtor': st.selectbox('Debtor', options=[0, 1], format_func=lambda x: 'Yes' if x == 1 else 'No'),
|
| 50 |
+
'Tuition fees up to date': st.selectbox('Tuition fees up to date', options=[0, 1], format_func=lambda x: 'Yes' if x == 1 else 'No'),
|
| 51 |
+
'Gender': st.selectbox('Gender', options=[0, 1], format_func=lambda x: 'Female' if x == 1 else 'Male'),
|
| 52 |
+
'Scholarship holder': st.selectbox('Scholarship holder', options=[0, 1], format_func=lambda x: 'Yes' if x == 1 else 'No'),
|
| 53 |
+
'Age at enrollment': st.number_input('Age at enrollment', value=int(sample_df['Age at enrollment'][0])),
|
| 54 |
+
'Curricular units 1st sem (enrolled)': st.number_input('Curricular units 1st sem (enrolled)', value=int(sample_df['Curricular units 1st sem (enrolled)'][0])),
|
| 55 |
+
'Curricular units 1st sem (evaluations)': st.number_input('Curricular units 1st sem (evaluations)', value=int(sample_df['Curricular units 1st sem (evaluations)'][0])),
|
| 56 |
+
'Curricular units 1st sem (approved)': st.number_input('Curricular units 1st sem (approved)', value=int(sample_df['Curricular units 1st sem (approved)'][0])),
|
| 57 |
+
'Curricular units 1st sem (grade)': st.number_input('Curricular units 1st sem (grade)', value=int(sample_df['Curricular units 1st sem (grade)'][0])),
|
| 58 |
+
'Curricular units 2nd sem (enrolled)': st.number_input('Curricular units 2nd sem (enrolled)', value=int(sample_df['Curricular units 2nd sem (enrolled)'][0])),
|
| 59 |
+
'Curricular units 2nd sem (evaluations)': st.number_input('Curricular units 2nd sem (evaluations)', value=int(sample_df['Curricular units 2nd sem (evaluations)'][0])),
|
| 60 |
+
'Curricular units 2nd sem (approved)': st.number_input('Curricular units 2nd sem (approved)', value=int(sample_df['Curricular units 2nd sem (approved)'][0])),
|
| 61 |
+
'Curricular units 2nd sem (grade)': st.number_input('Curricular units 2nd sem (grade)', value=int(sample_df['Curricular units 2nd sem (grade)'][0])),
|
| 62 |
+
'Curricular units 2nd sem (without evaluations)': st.number_input('Curricular units 2nd sem (without evaluations)', value=int(sample_df['Curricular units 2nd sem (without evaluations)'][0]))
|
| 63 |
+
}
|
| 64 |
+
return pd.DataFrame(input_data, index=[0])
|
| 65 |
+
|
| 66 |
+
# Streamlit app
|
| 67 |
+
st.title('Student Outcome Prediction 🧑🎓')
|
| 68 |
+
st.write('This app predicts whether a student is enrolled, graduated or dropout. 🎓')
|
| 69 |
+
st.write('Model is trained on a dataset by UC Irvine, acquired from several disjoint higher education institution databases. It has 82% accuracy. 🏫')
|
| 70 |
+
|
| 71 |
+
# Get user input
|
| 72 |
+
user_input_df = get_user_input()
|
| 73 |
+
|
| 74 |
+
# Normalize the user input
|
| 75 |
+
user_input_scaled = scaler.transform(user_input_df)
|
| 76 |
+
|
| 77 |
+
# Make prediction
|
| 78 |
+
prediction = model.predict(user_input_scaled)
|
| 79 |
+
predicted_class = prediction.argmax(axis=1)[0]
|
| 80 |
+
|
| 81 |
+
# Map the predicted class back to words
|
| 82 |
+
target_mapping = {0: 'Graduate', 1: 'Dropout', 2: 'Enrolled'}
|
| 83 |
+
predicted_label = target_mapping[predicted_class]
|
| 84 |
+
|
| 85 |
+
# Display the prediction
|
| 86 |
+
st.header(f'The predicted outcome is: ***{predicted_label}***')
|
| 87 |
+
st.image('https://d13b2ieg84qqce.cloudfront.net/c42fed0bb5d4f458b8606152e7dec885cd3e751d')
|
my_model.h5
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:5675cc27256fa60ad8c4ce225a4175881d52612753e1a5e2ed5e97d9eb3acf73
|
| 3 |
+
size 9290248
|
scaler.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:9a5f8f60e304a736508c033168586b624754c523a0d186900e3161bf09accc08
|
| 3 |
+
size 1532
|