-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMODEL_5_STUDENT_PERFORMANCE.tsx
More file actions
299 lines (281 loc) · 13.1 KB
/
MODEL_5_STUDENT_PERFORMANCE.tsx
File metadata and controls
299 lines (281 loc) · 13.1 KB
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
import * as dfd from 'danfojs'
import * as tfjs from '@tensorflow/tfjs'
import { Trans } from 'react-i18next'
import * as _Types from '@core/types'
import * as DataFrameUtils from '@core/dataframe/DataFrameUtils'
import I_MODEL_REGRESSION from './_model'
import { F_FILTER_Categorical, F_MAP_LabelEncoder } from '@core/nn-utils/utils'
export default class MODEL_5_STUDENT_PERFORMANCE extends I_MODEL_REGRESSION {
static KEY = 'STUDENT_PERFORMANCE'
static URL = 'https://archive.ics.uci.edu/dataset/320/student+performance'
URL = 'https://archive.ics.uci.edu/dataset/320/student+performance'
i18n_TITLE = 'datasets-models.1-regression.student-performance.title'
_KEY = 'STUDENT_PERFORMANCE'
student_performance_columns_X = [
'school',
'sex',
'age',
'address',
'famsize',
'Pstatus',
'Medu',
'Fedu',
'Mjob',
'Fjob',
'reason',
'guardian',
'traveltime',
'studytime',
'failures',
'schoolsup',
'famsup',
'paid',
'activities',
'nursery',
'higher',
'internet',
'romantic',
'famrel',
'freetime',
'goout',
'Dalc',
'Walc',
'health',
'absences'
]
DESCRIPTION () {
const prefix = 'datasets-models.1-regression.student-performance.description.'
return <>
<p><Trans i18nKey={prefix + 'text.0'} /></p>
<p><Trans i18nKey={prefix + 'text.1'} /></p>
<p><Trans i18nKey={prefix + 'text.2'} /></p>
<p><Trans i18nKey={prefix + 'text.3'} /></p>
<p>
<Trans i18nKey={prefix + 'link'}
components={{
link1: <a href={this.URL} target={'_blank'} rel="noreferrer">link</a>,
}} />
</p>
<details>
<summary><Trans i18nKey={prefix + 'details-1-input.title'} /></summary>
<ol>
{Object.entries(this.t(prefix + 'details-1-input.list', { returnObjects: true, defaultValue: [] }))
.map((_value, index) => {
return <li key={index}><Trans i18nKey={prefix + 'details-1-input.list.' + index} /></li>
})}
</ol>
</details>
<details>
<summary><Trans i18nKey={prefix + 'details-2-output.title'} /></summary>
<ol>
{Object.entries(this.t(prefix + 'details-2-output.list', { returnObjects: true, defaultValue: [] }))
.map((_value, index) => {
return <li key={index}><Trans i18nKey={prefix + 'details-2-output.list.' + index} /></li>
})}
</ol>
</details>
<details>
<summary><Trans i18nKey={prefix + 'details-3-references.title'} /></summary>
<ol>
<li><Trans i18nKey={prefix + 'details-3-references.list.0'}
components={{
link1: <a href={this.URL} target={'_blank'} rel={'noreferrer'}>TEXT</a>
}} /></li>
</ol>
</details>
<details>
<summary>BibTeX</summary>
<pre>
{`
@misc{misc_student_performance_320,
author = {Cortez,Paulo},
title = {{Student Performance}},
year = {2014},
howpublished = {UCI Machine Learning Repository},
note = {{DOI}: https://doi.org/10.24432/C5TG7T}
}
`}
</pre>
</details>
</>
}
/**
*
* @returns {Promise<_Types.DatasetProcessed_t[]>}
*/
async DATASETS (): Promise<_Types.DatasetProcessed_t[]> {
const path_datasets = import.meta.env.VITE_PATH + '/datasets/01-regression/student-performance/'
const student_info = 'student.names'
const mat_csv = 'student-mat-2024.csv'
const por_csv = 'student-por-2024.csv'
const dataset_fetch_info = await fetch(path_datasets + student_info)
const student_container_info = await dataset_fetch_info.text()
/**
* @type {_Types.Dataset_t}
*/
const dataset: _Types.Dataset_t = [
{ column_name: 'school', column_type: 'Categorical', column_role: 'Feature', column_missing_values: false },
{ column_name: 'sex', column_type: 'Binary', column_role: 'Feature', column_missing_values: false },
{ column_name: 'age', column_type: 'Integer', column_role: 'Feature', column_missing_values: false },
{ column_name: 'address', column_type: 'Categorical', column_role: 'Feature', column_missing_values: false },
{ column_name: 'famsize', column_type: 'Categorical', column_role: 'Feature', column_missing_values: false },
{ column_name: 'Pstatus', column_type: 'Categorical', column_role: 'Feature', column_missing_values: false },
{ column_name: 'Medu', column_type: 'Integer', column_role: 'Feature', column_missing_values: false },
{ column_name: 'Fedu', column_type: 'Integer', column_role: 'Feature', column_missing_values: false },
{ column_name: 'Mjob', column_type: 'Categorical', column_role: 'Feature', column_missing_values: false },
{ column_name: 'Fjob', column_type: 'Categorical', column_role: 'Feature', column_missing_values: false },
{ column_name: 'reason', column_type: 'Categorical', column_role: 'Feature', column_missing_values: false },
{ column_name: 'guardian', column_type: 'Categorical', column_role: 'Feature', column_missing_values: false },
{ column_name: 'traveltime', column_type: 'Integer', column_role: 'Feature', column_missing_values: false },
{ column_name: 'studytime', column_type: 'Integer', column_role: 'Feature', column_missing_values: false },
{ column_name: 'failures', column_type: 'Integer', column_role: 'Feature', column_missing_values: false },
{ column_name: 'schoolsup', column_type: 'Binary', column_role: 'Feature', column_missing_values: false },
{ column_name: 'famsup', column_type: 'Binary', column_role: 'Feature', column_missing_values: false },
{ column_name: 'paid', column_type: 'Binary', column_role: 'Feature', column_missing_values: false },
{ column_name: 'activities', column_type: 'Binary', column_role: 'Feature', column_missing_values: false },
{ column_name: 'nursery', column_type: 'Binary', column_role: 'Feature', column_missing_values: false },
{ column_name: 'higher', column_type: 'Binary', column_role: 'Feature', column_missing_values: false },
{ column_name: 'internet', column_type: 'Binary', column_role: 'Feature', column_missing_values: false },
{ column_name: 'romantic', column_type: 'Binary', column_role: 'Feature', column_missing_values: false },
{ column_name: 'famrel', column_type: 'Integer', column_role: 'Feature', column_missing_values: false },
{ column_name: 'freetime', column_type: 'Integer', column_role: 'Feature', column_missing_values: false },
{ column_name: 'goout', column_type: 'Integer', column_role: 'Feature', column_missing_values: false },
{ column_name: 'Dalc', column_type: 'Integer', column_role: 'Feature', column_missing_values: false },
{ column_name: 'Walc', column_type: 'Integer', column_role: 'Feature', column_missing_values: false },
{ column_name: 'health', column_type: 'Integer', column_role: 'Feature', column_missing_values: false },
{ column_name: 'absences', column_type: 'Integer', column_role: 'Feature', column_missing_values: false },
// { column_name: 'G1', column_type: 'Categorical', column_role: 'Target', column_missing_values: false },
// { column_name: 'G2', column_type: 'Categorical', column_role: 'Target', column_missing_values: false },
{ column_name: 'G3', column_type: 'Integer', column_role: 'Target', column_missing_values: false },
]
// #region Student Mat
const mat_dataframe_original = await dfd.readCSV(path_datasets + mat_csv)
let mat_dataframe_processed = await dfd.readCSV(path_datasets + mat_csv)
/** @type {_Types.DataFrameColumnTransform_t[]} */
const mat_dataset_transforms = [
...dataset.filter(F_FILTER_Categorical).map(F_MAP_LabelEncoder),
// { column_name: 'G1', column_transform: 'drop' },
// { column_name: 'G2', column_transform: 'drop' },
// { column_name: 'G3', column_transform: 'drop' },
]
const mat_target = 'G3' // G1;G2;G3
const mat_dataframe_encoder = DataFrameUtils.DataFrameTransformAndEncoder(mat_dataframe_processed, mat_dataset_transforms)
const mat_encoders_map = mat_dataframe_encoder.encoder_map
mat_dataframe_processed = mat_dataframe_encoder.dataframe_processed
const mat_dataframe_X = mat_dataframe_processed.drop({ columns: ['G3'] }).copy()
/**@type {_Types.Series_t}*/
const mat_dataframe_y = mat_dataframe_original[mat_target]
const minMaxScaler1 = new dfd.MinMaxScaler()
const mat_scaler = minMaxScaler1.fit(mat_dataframe_X)
const mat_X = mat_scaler.transform(mat_dataframe_X)
const mat_y = mat_dataframe_y
// #endregion
// #region Student Por
const por_dataframe_original = await dfd.readCSV(path_datasets + por_csv)
let por_dataframe_processed = await dfd.readCSV(path_datasets + por_csv)
/** @type {_Types.DataFrameColumnTransform_t[]} */
const por_dataset_transforms: _Types.DataFrameColumnTransform_t[] = [
...dataset.filter(F_FILTER_Categorical).map(F_MAP_LabelEncoder),
// { column_name: 'G1', column_transform: 'drop' },
// { column_name: 'G2', column_transform: 'drop' },
// { column_name: 'G3', column_transform: 'drop' },
]
const por_target = 'G3' // G1;G2;G3
const por_dataframe_encoder = DataFrameUtils.DataFrameTransformAndEncoder(por_dataframe_processed, por_dataset_transforms)
const por_encoders_map = por_dataframe_encoder.encoder_map
por_dataframe_processed = por_dataframe_encoder.dataframe_processed
const por_dataframe_X = por_dataframe_processed.drop({ columns: ['G3'] }).copy()
/**@type {_Types.Series_t}*/
const por_dataframe_y = por_dataframe_original[por_target]
const minMaxScaler2 = new dfd.MinMaxScaler()
const por_minMaxScaler = minMaxScaler2.fit(por_dataframe_X)
/**@type {_Types.DataFrame_t}*/
const por_X = por_minMaxScaler.transform(por_dataframe_X)
const por_y = por_dataframe_y
// #endregion
return [
{
is_dataset_upload : false,
is_dataset_processed: true,
path : path_datasets,
info : student_info,
container_info : student_container_info,
csv : mat_csv,
dataset : dataset,
dataset_transforms : mat_dataset_transforms,
dataframe_original : mat_dataframe_original,
dataframe_processed : mat_dataframe_processed,
data_processed : {
dataframe_X : mat_dataframe_X,
dataframe_y : mat_dataframe_y,
X : mat_X,
y : mat_y,
scaler : mat_scaler,
encoders : mat_encoders_map,
column_name_target: mat_target,
}
},
{
is_dataset_upload : false,
is_dataset_processed: true,
path : path_datasets,
info : student_info,
container_info : student_container_info,
csv : por_csv,
dataset : dataset,
dataset_transforms : por_dataset_transforms,
dataframe_original : por_dataframe_original,
dataframe_processed : por_dataframe_processed,
data_processed : {
dataframe_X : por_dataframe_X,
dataframe_y : por_dataframe_y,
X : por_X,
y : por_y,
scaler : por_minMaxScaler,
encoders : por_encoders_map,
column_name_target: por_target,
}
}
]
}
/**
*
* @param {string} [dataset='']
* @return {Promise<_Types.CustomModel_t[]>}
*/
async MODELS (dataset: string = ''): Promise<_Types.CustomModel_t[]> {
const path = import.meta.env.VITE_PATH + '/models/01-regression/student-performance'
const mat_model_0 = await tfjs.loadLayersModel(path + '/0/lr-model-mat.json')
const por_model_0 = await tfjs.loadLayersModel(path + '/0/lr-model-por.json')
const models: { [key: string]: _Types.CustomModel_t[] } = {
'student-mat-2024.csv': [
{
model : mat_model_0,
model_path: path + '/0/lr-model-mat.json',
X : this.student_performance_columns_X,
y : 'G3'
},
],
'student-por-2024.csv': [
{
model : por_model_0,
model_path: path + '/0/lr-model-por.json',
X : this.student_performance_columns_X,
y : 'G3'
},
]
}
return models[dataset]
}
DEFAULT_LAYERS () {
return [
{ is_disabled: false, units: 32, activation: 'sigmoid' },
{ is_disabled: false, units: 16, activation: 'sigmoid' },
{ is_disabled: true, units: 1, activation: 'linear' }
]
}
ATTRIBUTE_INFORMATION () {
return <>
</>
}
}