-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathui.py
327 lines (272 loc) · 11.4 KB
/
ui.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
import streamlit as st
import numpy as np
from PIL import Image
import pandas as pd
import pickle
from sklearn.preprocessing import StandardScaler
# ================================================================================
# Images
image_data = Image.open("images/data.png")
image_prep_data = Image.open("images/prep-data.png")
image_education_data = Image.open("images/education-data.png")
image_lunch_data = Image.open("images/lunch-data.png")
image_race = Image.open("images/race-ethnicity-plot.png")
image_gender = Image.open("images/gender-plot.png")
image_lunch = Image.open("images/lunch-plot.png")
image_preparation = Image.open("images/preparation-plot.png")
image_education = Image.open("images/education.png")
image_grades = Image.open("images/grade-distribution.png")
image_total = Image.open("images/total-grade.png")
# ================================================================================
# Numpy files
option_gender = np.load('np_files/gender.npy', allow_pickle=True)
option_race = np.load('np_files/race.npy', allow_pickle=True)
option_education = np.load('np_files/education.npy', allow_pickle=True)
option_lunch = np.load('np_files/lunch.npy', allow_pickle=True)
option_preparation = np.load('np_files/test_prep.npy', allow_pickle=True)
coefs = np.load('np_files/coefs.npy')
# ================================================================================
# Page Title
st.title("Students Performance Prediction on the Exam")
# ================================================================================
# Header
st.header("Introduction:")
intro_txt = '''
During the university application process, applicants are required to complete
a survey as part of the application form. This survey typically encompasses
a wide range of questions related to the applicant's economic, sociological,
and ethnic background. Such information is valuable for admission departments
to gain insight into the diverse characteristics of the applicants.
-------------------------------------------------------------------------------
For instance, at Nazarbayev University, students applying to Bachelor programs
or the Foundation program are presented with a variety of questions.
These questions may cover aspects such as:
1. Gender
2. Ethnicity
3. Educational background of parents
In response to the current trend where many students utilize external services
during their preparation period, the application form may also include queries
to understand the extent to which these external courses contribute to the
applicant's readiness. This additional information aids in comprehending the
effectiveness and impact of external resources on the applicants' preparedness
for university studies.
'''
st.text(intro_txt)
# ================================================================================
# Presentation parts
st.header("Objectives:")
st.subheader("Project-wise:")
project_goals = '''
1. Understanding the Influence of Parental Education on Children's Grades
2. Exploring the Impact of Utilizing External Services on Applicant's Academic
Performance
3. Considering Whether Having a Meal Before an Exam is Beneficial for Applicants
'''
st.text(project_goals)
st.subheader("Personal:")
personal_goals = '''
1. Achieving an End-to-End Data Science Project
2. Harnessing the Power of Streamlit Apps to Present Analysis Results in a
User-Friendly Manner
3. Implementing a Test-Driven Approach by Designing Tests
4. Enhancing Proficiency in Version Control Systems for Systematic Project
Development
'''
st.text(personal_goals)
# ================================================================================
# Software presentation
st.header("Softwares:")
st.subheader('Python')
softwares = '''
1. Numpy => Numerical Calculations
2. Pandas => Data Analysis
3. Matplotlib => Visualizations
4. Seaborn => Visualizations
5. Sci-kit Learn => Machine Learning Models
6. Streamlit => User Interface
7. Git and GitHub => Version Control
'''
st.text(softwares)
# ================================================================================
# Data presentation
st.header("Model Formulation")
st.subheader('Data Analysis')
st.image(image_data, caption="Table 1. Given Data", use_column_width=True)
st.text('Sociological Data')
st.image(image_race, caption='Figure 1. Race', use_column_width=True)
st.image(image_gender, caption='Figure 2. Gender', use_column_width=True)
st.text('Score Distribution')
st.image(image_grades, caption="Figure 3. Score Distribution", use_column_width=True)
st.image(image_total, caption="Figure 4. Total Score Distribution", use_column_width=True)
st.text('Data related to the Parental Education')
st.image(image_education, caption='Figure 5. Parental Education', use_column_width=True)
st.image(image_education_data, caption='Table 2. Parental Education', use_column_width=True)
st.text('Data related to the Applicants Preparation')
st.image(image_preparation, caption='Figure 6. Test Preparation', use_column_width=True)
st.image(image_prep_data, caption='Table 3. Test Preparation', use_column_width=True)
st.text('LUNCH')
st.image(image_lunch, caption='Figure 7. Did you have Lunch before Exam?', use_column_width=True)
st.image(image_lunch_data, caption='Table 4. Did you have Lunch before Exam?', use_column_width=True)
# ================================================================================
# ML model
st.subheader('Machine Learning Model')
st.text('Linear Regression')
units = '''
x1 - Gender of an Applicant
x2 - Race of an Applicant
x3 - the Parental Education of an Applicant
x4 - Did an Applicant have a lunch before the exam?
x5 - Did an Applicant attend courses to prepare?
'''
st.text(units)
st.text('Equation to Calculate the Math Score:')
st.text(f'''
Math Score = {round(coefs[0][0], 3)} * x1 + {round(coefs[0][1], 3)} * x2 {round(coefs[0][2], 3)} * x3 + {round(coefs[0][3], 3)} * x4 {round(coefs[0][4], 3)} * x5 + {round(coefs[0][5], 3)}
Root Mean Squared Error = 13.284
R^2 = 0.232
Writing Score = {round(coefs[1][0], 3)} * x1 + {round(coefs[1][1], 3)} * x2 {round(coefs[1][2], 3)} * x3 + {round(coefs[1][3], 3)} * x4 {round(coefs[1][4], 3)} * x5 + {round(coefs[1][5], 3)}
Root Mean Squared Error = 12.727
R^2 = 0.255
Reading Score = {round(coefs[2][0], 3)} * x1 + {round(coefs[2][1], 3)} * x2 {round(coefs[2][2], 3)} * x3 + {round(coefs[2][3], 3)} * x4 {round(coefs[2][4], 3)} * x5 + {round(coefs[2][5], 3)}
Root Mean Squared Error = 13.203
R^2 = 0.171
''')
# ================================================================================
# User Input
st.subheader("Let's test: ")
inputs = []
user_input_gender = int(st.number_input('Enter your gender'))
gender_txt = '''
Options are:
1. female => 1
2. male => 2
'''
st.text(gender_txt)
inputs.append(user_input_gender)
user_input_race = int(st.number_input('Enter your ethnicity'))
race_txt = '''
Options are:
1. Group A => 1
2. Group B => 2
3. Group C => 3
4. Group D => 4
5. Group E => 5
'''
st.text(race_txt)
inputs.append(user_input_race)
user_input_education = int(st.number_input('Enter the education level of your parents'))
education_txt = '''
Options are:
1. Associate's Degree => 1
2. Bachelor's Degree => 2
3. High School => 3
4. Master's Degree => 4
5. Some College => 5
6. Some High School => 6
'''
st.text(education_txt)
inputs.append(user_input_education)
user_input_lunch = int(st.number_input('Did you have a lunch before the exam?'))
lunch_txt = '''
Options are:
1. No or Partially (free/reduced) => 1
2. Yes (standard lunch) => 2
'''
st.text(lunch_txt)
inputs.append(user_input_lunch)
user_input_preparation = int(st.number_input('Did you attend preparation courses?'))
preparation_txt = '''
Options are:
1. Yes (completed) => 1
2. No (none) => 2
'''
st.text(preparation_txt)
inputs.append(user_input_preparation)
st.subheader('Testing results')
def tests(inputs):
test_results = np.zeros(5)
# Input Tests
# test 1
if (inputs[0]-1 in list(option_gender)):
st.write("<font color='green'>Test 1 --- Passed</font>", unsafe_allow_html=True)
st.text('Gender of the user is in the correct range')
test_results[0] = inputs[0]-1
else:
st.write("<font color='red'>Test 1 --- Failed</font>", unsafe_allow_html=True)
st.text('Gender of the user is not in the correct range')
# test 2
if (inputs[1]-1 in list(option_race)):
st.write("<font color='green'>Test 2 --- Passed</font>", unsafe_allow_html=True)
st.text('Ethnicity of the user is in the correct range')
test_results[1] = inputs[1]-1
else:
st.write("<font color='red'>Test 2 --- Failed</font>", unsafe_allow_html=True)
st.text('Ethnicity of the user is not in the correct range')
return -1
# test 3
if (inputs[2]-1 in list(option_education)):
st.write("<font color='green'>Test 3 --- Passed</font>", unsafe_allow_html=True)
st.text('Education of Parents of the user is in the correct range')
test_results[2] = inputs[2]-1
else:
st.write("<font color='red'>Test 3 --- Failed</font>", unsafe_allow_html=True)
st.text('Education of Parents of the user is not in the correct range')
return -1
# test 4
if (inputs[3]-1 in list(option_lunch)):
st.write("<font color='green'>Test 4 --- Passed</font>", unsafe_allow_html=True)
st.text('Question did user have a lunch is in the correct range')
test_results[3] = inputs[3]-1
else:
st.write("<font color='red'>Test 4 --- Failed</font>", unsafe_allow_html=True)
st.text('Question did user have a lunch is not in the correct range')
return -1
# test 5
if (inputs[4]-1 in list(option_preparation)):
st.write("<font color='green'>Test 5 --- Passed</font>", unsafe_allow_html=True)
st.text('Preparation of the user is in the correct range')
test_results[4] = inputs[4]-1
else:
st.write("<font color='red'>Test 5 --- Failed</font>", unsafe_allow_html=True)
st.text('Preparation of the user a lunch is not in the correct range')
return -1
return test_results
def math_score(results):
with open('scalers/scaler1.pkl', 'rb') as file:
scaler1 = pickle.load(file)
scaled_data = scaler1.transform(results.reshape(1, -1))
score = np.sum(np.multiply(coefs[0][:5], scaled_data)) + coefs[0][5]
return score
def writing_score(results):
with open('scalers/scaler2.pkl', 'rb') as file:
scaler2 = pickle.load(file)
scaled_data = scaler2.transform(results.reshape(1, -1))
score = np.sum(np.multiply(coefs[1][:5], scaled_data)) + coefs[1][5]
return score
def reading_score(results):
with open('scalers/scaler3.pkl', 'rb') as file:
scaler3 = pickle.load(file)
scaled_data = scaler3.transform(results.reshape(1, -1))
score = np.sum(np.multiply(coefs[2][:5], scaled_data)) + coefs[2][5]
return score
def scores (results):
st.header('Score Results')
st.subheader('Score of the Math exam:')
math = round(math_score(results))
st.text(math)
st.subheader('Score of the Writing exam:')
writing = round(writing_score(results))
st.text(writing)
st.subheader('Score of the Reading exam:')
reading = round(reading_score(results))
st.text(reading)
st.subheader('Total score on the exam:')
st.text(f'{math + writing + reading} ({100*round((math + writing + reading)/300, 3)})%')
if (0 not in inputs):
results = tests(inputs)
if (type(results) == int):
st.text('Enter the valid information!')
else:
scores(results)
else:
st.text('You have not entered all information!')