File size: 25,918 Bytes
e448441 |
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 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 |
{
"cells": [
{
"cell_type": "code",
"execution_count": 13,
"id": "85bab64d",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[Errno 2] No such file or directory: '../../IRL-MOOC/'\n",
"/Users/huonglan/Documents/codeproject/IRL-MOOC\n"
]
}
],
"source": [
"cd ../../IRL-MOOC/"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "53d2c43e",
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd\n",
"import tensorflow as tf\n",
"import numpy as np\n",
"import os\n",
"import pickle\n",
"import models.maxcausal as maxcausal\n",
"from utils.data_helper import *\n",
"from environment import raw_world as Env"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "f3039f07",
"metadata": {},
"outputs": [],
"source": [
"course_id = 'dsp-002'\n",
"datadir = 'data/mooc_raw/coursera'"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "ced9e2a8",
"metadata": {},
"outputs": [],
"source": [
"with open('trajectories_each_week.pkl', 'rb') as f:\n",
" trajectories_each_week = pickle.load(f)\n",
"\n",
"with open('trajectories_each_week_pass.pkl', 'rb') as f:\n",
" trajectories_each_week_pass = pickle.load(f)\n",
" \n",
"with open('trajectories_each_week_fail.pkl', 'rb') as f:\n",
" trajectories_each_week_fail = pickle.load(f)\n",
"\n",
"with open('trajectories.pkl', 'rb') as f:\n",
" trajectories = pickle.load(f)"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "c6d4d368",
"metadata": {},
"outputs": [],
"source": [
"with open('history_whatif_fail_300.pkl', 'rb') as f:\n",
" history_whatif_fail = pickle.load(f)\n",
"\n",
"with open('history_whatif_pass_300.pkl', 'rb') as f:\n",
" history_whatif_pass = pickle.load(f)"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "ee098a42",
"metadata": {},
"outputs": [],
"source": [
"# load combinedg, dict_event, dict_action, map_week, map_event_id, map_action\n",
"combinedg = pd.read_csv(f'data/{course_id}/combinedg_features_{course_id}.csv')\n",
"with open(f'data/{course_id}/dict_event.pkl', 'rb') as f:\n",
" dict_event = pickle.load(f)\n",
"with open(f'data/{course_id}/dict_action.pkl', 'rb') as f:\n",
" dict_action = pickle.load(f)\n",
"with open(f'data/{course_id}/map_week.pkl', 'rb') as f:\n",
" map_week = pickle.load(f)\n",
"with open(f'data/{course_id}/map_event_id.pkl', 'rb') as f:\n",
" map_event_id = pickle.load(f)\n",
"with open(f'data/{course_id}/map_action.pkl', 'rb') as f:\n",
" map_action = pickle.load(f)\n",
"with open(f'data/{course_id}/problem_event.pkl', 'rb') as f:\n",
" problem_event = pickle.load(f)\n",
"with open(f'data/{course_id}/video_event.pkl', 'rb') as f:\n",
" video_event = pickle.load(f)"
]
},
{
"cell_type": "code",
"execution_count": 14,
"id": "4df5608e",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/Users/huonglan/Documents/codeproject/IRL-MOOC/utils/data_helper.py:247: SettingWithCopyWarning: \n",
"A value is trying to be set on a copy of a slice from a DataFrame.\n",
"Try using .loc[row_indexer,col_indexer] = value instead\n",
"\n",
"See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
" video_length['duration'] = (video_length['duration']-min_len)/(max_len-min_len)\n",
"/Users/huonglan/Documents/codeproject/IRL-MOOC/utils/data_helper.py:252: FutureWarning: A value is trying to be set on a copy of a DataFrame or Series through chained assignment using an inplace method.\n",
"The behavior will change in pandas 3.0. This inplace method will never work because the intermediate object on which we are setting values always behaves as a copy.\n",
"\n",
"For example, when doing 'df[col].method(value, inplace=True)', try using 'df.method({col: value}, inplace=True)' or df[col] = df[col].method(value) instead, to perform the operation inplace on the original object.\n",
"\n",
"\n",
" event_value['duration'].fillna(event_value['duration'].mean(), inplace=True)\n"
]
}
],
"source": [
"schedule = pd.read_csv(f'{datadir}/schedule/{course_id}.csv')\n",
"values = whatif_values(combinedg, schedule, map_event_id=map_event_id, problem_event=problem_event)"
]
},
{
"cell_type": "code",
"execution_count": 21,
"id": "f2f688b1",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"['video' 'problem']\n"
]
}
],
"source": [
"print(schedule.type.unique())"
]
},
{
"cell_type": "code",
"execution_count": 25,
"id": "510e39ad",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" Unnamed: 0 id type subtype chapter subchapter date duration \\\n",
"0 0 55 video NaN 1 1.0 2013-10-13 202.0 \n",
"1 1 21 video NaN 1 1.1 2013-10-13 926.0 \n",
"2 2 53 video NaN 2 2.1 2013-10-20 588.0 \n",
"3 3 27 video NaN 2 2.2 2013-10-20 648.0 \n",
"4 4 25 video NaN 2 2.3 2013-10-20 1061.0 \n",
"\n",
" grade_max title \\\n",
"0 NaN 1.0 - Welcome to the DSP course [3:22] \n",
"1 NaN 1.1 - Introduction to signal processing [15:25] \n",
"2 NaN 2.1 - Discrete time signals [9:48] \n",
"3 NaN 2.2 - The complex exponential [10:48] \n",
"4 NaN 2.3 - The Karplus-Strong Algorithm [17:41] \n",
"\n",
" source event_id \n",
"0 DSP Introduction video.mov 22.0 \n",
"1 Module 1-h264 for Coursera.mp4 6.0 \n",
"2 Module 2_1-h264 for Coursera.mp4 21.0 \n",
"3 Module 2_2-h264 for Coursera.mp4 9.0 \n",
"4 Module 2_3-h264 for Coursera.mp4 8.0 \n",
" chapter count videos count quizzes\n",
"0 1 2 2\n",
"1 2 3 4\n",
"2 3 4 4\n",
"3 4 13 10\n",
"4 5 12 7\n"
]
}
],
"source": [
"print(schedule.head(5))\n",
"presiquilite_skills = pd.read_csv(f'dsp_prerequisite_skills.csv')\n",
"# Count videos and quizzes per chapter\n",
"video_counts = schedule[schedule.type == 'video'].groupby('chapter')['type'].count().reset_index()\n",
"video_counts.columns = ['chapter', 'count videos']\n",
"\n",
"quiz_counts = schedule[schedule.type == 'problem'].groupby('chapter')['type'].count().reset_index()\n",
"quiz_counts.columns = ['chapter', 'count quizzes']\n",
"\n",
"# Merge video and quiz counts into one table\n",
"count_b = pd.merge(video_counts, quiz_counts, on='chapter', how='outer')\n",
"\n",
"# Fill missing counts with 0\n",
"count_b[['count videos', 'count quizzes']] = count_b[['count videos', 'count quizzes']].fillna(0).astype(int)\n",
"print(count_b.head(5))\n",
"# Merge with A\n",
"df_merged = presiquilite_skills.merge(count_b, left_on='Topic', right_on='chapter', how='left')\n",
"\n",
"# Optional: count total objects per topic\n",
"df_merged['count_objects'] = df_merged['count videos'].fillna(0) + df_merged['count quizzes'].fillna(0)\n",
"df_merged['count_objects'] = df_merged['count_objects'].astype(int)\n",
"\n",
"# Drop unnecessary column\n",
"df_merged.drop(columns=['chapter'], inplace=True)\n",
"\n",
"# Export to CSV\n",
"df_merged.to_csv('dsp_prerequisite_skills_2.csv', index=False)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "6c068109",
"metadata": {},
"outputs": [],
"source": [
"import streamlit as st\n",
"import pandas as pd\n",
"import plotly.express as px\n",
"\n",
"# ---------------------\n",
"# Meta Information\n",
"# ---------------------\n",
"st.set_page_config(page_title=\"DSP Prerequisite Skills\", layout=\"wide\")\n",
"st.title(\"π DSP Prerequisite Skills Analysis\")\n",
"st.markdown(\"\"\"\n",
"This dashboard shows the mapping between prerequisite topics and their actual content.\n",
"On the left is the skill table; on the right is a bar chart of object counts per topic.\n",
"\"\"\")\n",
"\n",
"# ---------------------\n",
"# Load or simulate data\n",
"# ---------------------\n",
"# Replace this with your actual merged DataFrame\n",
"df_merged = pd.DataFrame({\n",
" 'Topic': ['Digital Signals', 'FFT', 'Filter Design'],\n",
" 'count videos': [5, 3, 4],\n",
" 'count quizzes': [2, 1, 3],\n",
" 'count_objects': [7, 4, 7]\n",
"})\n",
"\n",
"# ---------------------\n",
"# Layout: Two columns\n",
"# ---------------------\n",
"col1, col2 = st.columns([1, 2]) # Left: Table, Right: Plot\n",
"\n",
"with col1:\n",
" st.subheader(\"π Topic Table\")\n",
" st.dataframe(df_merged)\n",
"\n",
"with col2:\n",
" st.subheader(\"π Content Count per Topic\")\n",
" fig = px.bar(\n",
" df_merged,\n",
" x='Topic',\n",
" y=['count videos', 'count quizzes'],\n",
" barmode='group',\n",
" title=\"Videos and Quizzes per Topic\",\n",
" labels={\"value\": \"Count\", \"variable\": \"Content Type\"},\n",
" )\n",
" st.plotly_chart(fig, use_container_width=True)"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "22f27762",
"metadata": {},
"outputs": [],
"source": [
"ids = np.load('/Users/huonglan/Documents/codeproject/IRL-MOOC/results/whatif/dsp-002/test_students_5.npy')"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "e9979fe1",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Logging: p_transition updated\n",
"Skills set: {1: 'Digital Signals', 2: 'Hilbert/Linear Algebra', 3: 'DFT', 4: 'DTFT & DFS', 5: 'Modulation', 6: 'FFT', 7: 'Ideal Filters', 8: 'Filter Design', 9: 'De-Modulation', 10: 'Interpolation & Sampling', 11: 'Multirate', 12: 'Quantization', 13: 'Applications'}\n",
"Complexity Level of each Week: {1: 0.0, 2: 0.0, 3: 0.0, 4: 0.42857142857142855, 5: 0.6428571428571429, 6: 0.7857142857142857, 7: 0.8571428571428571, 8: 0.42857142857142855, 9: 0.7857142857142857, 10: 1.0}\n"
]
},
{
"ename": "AttributeError",
"evalue": "'StateManager' object has no attribute 'create_interactive_state_manager'",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)",
"Cell \u001b[0;32mIn[11], line 16\u001b[0m\n\u001b[1;32m 2\u001b[0m world \u001b[38;5;241m=\u001b[39m Env\u001b[38;5;241m.\u001b[39mClickstreamWorld(trajectories\u001b[38;5;241m=\u001b[39mtrajectories,\n\u001b[1;32m 3\u001b[0m dict_action\u001b[38;5;241m=\u001b[39mdict_action, \n\u001b[1;32m 4\u001b[0m dict_event\u001b[38;5;241m=\u001b[39mdict_event,\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 7\u001b[0m values\u001b[38;5;241m=\u001b[39mvalues,\n\u001b[1;32m 8\u001b[0m add_state\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mTrue\u001b[39;00m)\n\u001b[1;32m 9\u001b[0m interactive_state_manager \u001b[38;5;241m=\u001b[39m trajectory_comparison\u001b[38;5;241m.\u001b[39mStateManager(world\u001b[38;5;241m=\u001b[39mworld, trajectories\u001b[38;5;241m=\u001b[39mtrajectories, test_ids\u001b[38;5;241m=\u001b[39mids,\n\u001b[1;32m 10\u001b[0m trajectories_each_week\u001b[38;5;241m=\u001b[39mtrajectories_each_week,\n\u001b[1;32m 11\u001b[0m trajectories_each_week_pass\u001b[38;5;241m=\u001b[39mtrajectories_each_week_pass,\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 14\u001b[0m history_whatif_fail\u001b[38;5;241m=\u001b[39mhistory_whatif_fail,\n\u001b[1;32m 15\u001b[0m week_list\u001b[38;5;241m=\u001b[39m[\u001b[38;5;241m6\u001b[39m])\n\u001b[0;32m---> 16\u001b[0m \u001b[43minteractive_state_manager\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mcreate_interactive_state_manager\u001b[49m()\n",
"\u001b[0;31mAttributeError\u001b[0m: 'StateManager' object has no attribute 'create_interactive_state_manager'"
]
}
],
"source": [
"import utils.trajectory_comparison as trajectory_comparison\n",
"world = Env.ClickstreamWorld(trajectories=trajectories,\n",
" dict_action=dict_action, \n",
" dict_event=dict_event,\n",
" video_arr=video_event,\n",
" problem_arr=problem_event,\n",
" values=values,\n",
" add_state=True)\n",
"interactive_state_manager = trajectory_comparison.StateManager(world=world, trajectories=trajectories, test_ids=ids,\n",
" trajectories_each_week=trajectories_each_week,\n",
" trajectories_each_week_pass=trajectories_each_week_pass,\n",
" trajectories_each_week_fail=trajectories_each_week_fail,\n",
" history_whatif_pass=history_whatif_pass,\n",
" history_whatif_fail=history_whatif_fail,\n",
" week_list=[6])\n",
"interactive_state_manager.create_interactive_state_manager()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "e0e2b10b",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"2025-06-22 19:52:18.401 WARNING streamlit.runtime.scriptrunner_utils.script_run_context: Thread 'MainThread': missing ScriptRunContext! This warning can be ignored when running in bare mode.\n",
"2025-06-22 19:52:18.459 \n",
" \u001b[33m\u001b[1mWarning:\u001b[0m to view this Streamlit app on a browser, run it with the following\n",
" command:\n",
"\n",
" streamlit run /Users/huonglan/miniconda3/envs/irl/lib/python3.12/site-packages/ipykernel_launcher.py [ARGUMENTS]\n",
"2025-06-22 19:52:18.459 Thread 'MainThread': missing ScriptRunContext! This warning can be ignored when running in bare mode.\n",
"2025-06-22 19:52:18.459 Thread 'MainThread': missing ScriptRunContext! This warning can be ignored when running in bare mode.\n",
"2025-06-22 19:52:18.460 Thread 'MainThread': missing ScriptRunContext! This warning can be ignored when running in bare mode.\n",
"2025-06-22 19:52:18.460 Session state does not function when running a script without `streamlit run`\n",
"2025-06-22 19:52:18.461 Thread 'MainThread': missing ScriptRunContext! This warning can be ignored when running in bare mode.\n",
"2025-06-22 19:52:18.461 Thread 'MainThread': missing ScriptRunContext! This warning can be ignored when running in bare mode.\n",
"2025-06-22 19:52:18.461 Thread 'MainThread': missing ScriptRunContext! This warning can be ignored when running in bare mode.\n",
"2025-06-22 19:52:18.462 Thread 'MainThread': missing ScriptRunContext! This warning can be ignored when running in bare mode.\n",
"2025-06-22 19:52:18.462 Thread 'MainThread': missing ScriptRunContext! This warning can be ignored when running in bare mode.\n",
"2025-06-22 19:52:18.462 Thread 'MainThread': missing ScriptRunContext! This warning can be ignored when running in bare mode.\n",
"2025-06-22 19:52:18.462 Thread 'MainThread': missing ScriptRunContext! This warning can be ignored when running in bare mode.\n",
"2025-06-22 19:52:18.463 Thread 'MainThread': missing ScriptRunContext! This warning can be ignored when running in bare mode.\n",
"2025-06-22 19:52:18.463 Thread 'MainThread': missing ScriptRunContext! This warning can be ignored when running in bare mode.\n",
"2025-06-22 19:52:18.463 Thread 'MainThread': missing ScriptRunContext! This warning can be ignored when running in bare mode.\n",
"2025-06-22 19:52:18.463 Thread 'MainThread': missing ScriptRunContext! This warning can be ignored when running in bare mode.\n",
"2025-06-22 19:52:18.463 Thread 'MainThread': missing ScriptRunContext! This warning can be ignored when running in bare mode.\n",
"2025-06-22 19:52:18.465 Thread 'MainThread': missing ScriptRunContext! This warning can be ignored when running in bare mode.\n",
"2025-06-22 19:52:18.466 Thread 'MainThread': missing ScriptRunContext! This warning can be ignored when running in bare mode.\n",
"2025-06-22 19:52:18.466 Thread 'MainThread': missing ScriptRunContext! This warning can be ignored when running in bare mode.\n",
"2025-06-22 19:52:18.466 Thread 'MainThread': missing ScriptRunContext! This warning can be ignored when running in bare mode.\n",
"2025-06-22 19:52:18.467 Thread 'MainThread': missing ScriptRunContext! This warning can be ignored when running in bare mode.\n",
"2025-06-22 19:52:18.467 Thread 'MainThread': missing ScriptRunContext! This warning can be ignored when running in bare mode.\n",
"2025-06-22 19:52:18.468 Thread 'MainThread': missing ScriptRunContext! This warning can be ignored when running in bare mode.\n",
"2025-06-22 19:52:18.468 Thread 'MainThread': missing ScriptRunContext! This warning can be ignored when running in bare mode.\n",
"2025-06-22 19:52:18.469 Thread 'MainThread': missing ScriptRunContext! This warning can be ignored when running in bare mode.\n",
"2025-06-22 19:52:18.469 Thread 'MainThread': missing ScriptRunContext! This warning can be ignored when running in bare mode.\n",
"2025-06-22 19:52:18.470 Thread 'MainThread': missing ScriptRunContext! This warning can be ignored when running in bare mode.\n",
"2025-06-22 19:52:18.470 Thread 'MainThread': missing ScriptRunContext! This warning can be ignored when running in bare mode.\n",
"2025-06-22 19:52:18.470 Thread 'MainThread': missing ScriptRunContext! This warning can be ignored when running in bare mode.\n",
"2025-06-22 19:52:18.470 Thread 'MainThread': missing ScriptRunContext! This warning can be ignored when running in bare mode.\n",
"2025-06-22 19:52:18.470 Thread 'MainThread': missing ScriptRunContext! This warning can be ignored when running in bare mode.\n",
"2025-06-22 19:52:18.471 Thread 'MainThread': missing ScriptRunContext! This warning can be ignored when running in bare mode.\n",
"2025-06-22 19:52:18.471 Thread 'MainThread': missing ScriptRunContext! This warning can be ignored when running in bare mode.\n",
"2025-06-22 19:52:18.471 Thread 'MainThread': missing ScriptRunContext! This warning can be ignored when running in bare mode.\n",
"2025-06-22 19:52:18.472 Thread 'MainThread': missing ScriptRunContext! This warning can be ignored when running in bare mode.\n",
"2025-06-22 19:52:18.472 Thread 'MainThread': missing ScriptRunContext! This warning can be ignored when running in bare mode.\n",
"2025-06-22 19:52:18.473 Thread 'MainThread': missing ScriptRunContext! This warning can be ignored when running in bare mode.\n",
"2025-06-22 19:52:18.473 Thread 'MainThread': missing ScriptRunContext! This warning can be ignored when running in bare mode.\n",
"2025-06-22 19:52:18.473 Thread 'MainThread': missing ScriptRunContext! This warning can be ignored when running in bare mode.\n",
"2025-06-22 19:52:18.473 Thread 'MainThread': missing ScriptRunContext! This warning can be ignored when running in bare mode.\n",
"2025-06-22 19:52:18.474 Thread 'MainThread': missing ScriptRunContext! This warning can be ignored when running in bare mode.\n",
"2025-06-22 19:52:18.475 Thread 'MainThread': missing ScriptRunContext! This warning can be ignored when running in bare mode.\n",
"2025-06-22 19:52:18.475 Thread 'MainThread': missing ScriptRunContext! This warning can be ignored when running in bare mode.\n",
"2025-06-22 19:52:18.475 Thread 'MainThread': missing ScriptRunContext! This warning can be ignored when running in bare mode.\n",
"2025-06-22 19:52:18.475 Thread 'MainThread': missing ScriptRunContext! This warning can be ignored when running in bare mode.\n",
"2025-06-22 19:52:18.476 Thread 'MainThread': missing ScriptRunContext! This warning can be ignored when running in bare mode.\n",
"2025-06-22 19:52:18.476 Thread 'MainThread': missing ScriptRunContext! This warning can be ignored when running in bare mode.\n",
"2025-06-22 19:52:18.476 Thread 'MainThread': missing ScriptRunContext! This warning can be ignored when running in bare mode.\n",
"2025-06-22 19:52:18.476 Thread 'MainThread': missing ScriptRunContext! This warning can be ignored when running in bare mode.\n",
"2025-06-22 19:52:18.477 Thread 'MainThread': missing ScriptRunContext! This warning can be ignored when running in bare mode.\n",
"2025-06-22 19:52:18.477 Thread 'MainThread': missing ScriptRunContext! This warning can be ignored when running in bare mode.\n",
"2025-06-22 19:52:18.482 Thread 'MainThread': missing ScriptRunContext! This warning can be ignored when running in bare mode.\n"
]
}
],
"source": []
},
{
"cell_type": "code",
"execution_count": 25,
"id": "b8184edd",
"metadata": {},
"outputs": [],
"source": [
"course = 'dsp-002'\n",
"scores = pd.DataFrame(columns=['data_5_weeks', 'syn_week_6', 'data_6_weeks', 'model_name'])\n",
"DATA_DIR = 'checkpoints/'\n",
"model_path = {\n",
" 5: 'lstm-bi-32-64-5-1722490972.1859/model.keras_final_e.keras',\n",
" 6: 'lstm-bi-32-64-6-1722494926.4949/model.keras_final_e.keras',\n",
" 7: 'lstm-bi-32-64-7-1722499225.71723/model.keras_final_e.keras',\n",
" 8: 'lstm-bi-32-64-8-1722504182.3553/model.keras_final_e.keras',\n",
" 9: 'lstm-bi-32-64-9-1722511435.7777/model.keras_final_e.keras',\n",
" 10: 'lstm-bi-32-64-10-1722519098.62673/model.keras_final_e.keras',\n",
"}"
]
},
{
"cell_type": "code",
"execution_count": 31,
"id": "90a9aa4b",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"course: dsp-002\n",
"Test shape: (397, 1000, 26)\n",
"\u001b[1m13/13\u001b[0m \u001b[32mββββββββββββββββββββ\u001b[0m\u001b[37m\u001b[0m \u001b[1m2s\u001b[0m 121ms/step\n",
"Scores: {'acc': 0.9118387909319899, 'bac': 0.9051181380871534, 'prec': 0.9653979238754326, 'rec': 0.9177631578947368, 'f1': 0.9409780775716695, 'auc': 0.9051181380871532, 'feature_type': '', 'week_type': 'eq_week', 'course': 'dsp-002', 'model_name': 'Sequential', 'timestamp': 0, 'percentile': 0.6, 'data_balance': 0.7657430730478589}\n"
]
}
],
"source": [
"from utils.evaluation import *\n",
"from utils.rnn_models import *\n",
"week = 6\n",
"percentile = week / 10\n",
"week_type = 'eq_week'\n",
"DATA_DIR = 'results/whatif/dsp-002/'\n",
"labels = pd.read_csv(f'data/{course}/early-prediction_{course}_labels.csv')['label-pass-fail']\n",
"reconstructed_model = tf.keras.models.load_model(f'checkpoints/{model_path[week]}')\n",
"score_fail_arr, score_pass_arr = [], []\n",
"course_features = np.load(f'{DATA_DIR}/real-data-early-prediction_dsp-002_1to10_ver2.npy_features.npy')\n",
"test_ids = np.load(f'{DATA_DIR}/test_students_5.npy')\n",
"x_test, y_test = course_features[test_ids, :, :], labels[test_ids]\n",
"print('course: ', course)\n",
"print('Test shape:', x_test.shape)\n",
"scores = evaluate(reconstructed_model, x_test, y_test, week_type, \"\", course, percentile=percentile, current_timestamp=0)\n",
"print('Scores:', scores)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "irl",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.2"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
|