ALLIA12 commited on
Commit
2c7f915
·
verified ·
1 Parent(s): c98061b

Intro to AI Stage 2 practical exam: 1038 dual-graded students, rubric, solutions

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. Practical_AI_exam_grades.csv +1039 -0
  2. README.md +159 -0
  3. Solutions/Q1_Regression_Solution.ipynb +331 -0
  4. Solutions/Q2_Pytorch_Solution.ipynb +396 -0
  5. Solutions/Q3_Classification_Solution.ipynb +397 -0
  6. stage_2_rubrics_ta.md +156 -0
  7. submissions_extracted/1/Q1.ipynb +286 -0
  8. submissions_extracted/1/Q3.ipynb +190 -0
  9. submissions_extracted/10/Q1.ipynb +280 -0
  10. submissions_extracted/10/Q2.ipynb +323 -0
  11. submissions_extracted/10/Q3.ipynb +307 -0
  12. submissions_extracted/100/Q1.ipynb +311 -0
  13. submissions_extracted/100/Q2.ipynb +365 -0
  14. submissions_extracted/100/Q3.ipynb +219 -0
  15. submissions_extracted/1000/Q1.ipynb +293 -0
  16. submissions_extracted/1000/Q2.ipynb +400 -0
  17. submissions_extracted/1000/Q3.ipynb +257 -0
  18. submissions_extracted/1001/Q1.ipynb +229 -0
  19. submissions_extracted/1001/Q2.ipynb +198 -0
  20. submissions_extracted/1001/Q3.ipynb +160 -0
  21. submissions_extracted/1002/Q1.ipynb +286 -0
  22. submissions_extracted/1002/Q2.ipynb +406 -0
  23. submissions_extracted/1002/Q3.ipynb +275 -0
  24. submissions_extracted/1003/Q1.ipynb +259 -0
  25. submissions_extracted/1004/Q1.ipynb +286 -0
  26. submissions_extracted/1004/Q2.ipynb +330 -0
  27. submissions_extracted/1004/Q3.ipynb +250 -0
  28. submissions_extracted/1005/Q1.ipynb +261 -0
  29. submissions_extracted/1005/Q2.ipynb +410 -0
  30. submissions_extracted/1006/Q1.ipynb +434 -0
  31. submissions_extracted/1006/Q2.ipynb +204 -0
  32. submissions_extracted/1006/Q3.ipynb +321 -0
  33. submissions_extracted/1007/Q1.ipynb +399 -0
  34. submissions_extracted/1007/Q2.ipynb +419 -0
  35. submissions_extracted/1007/Q3.ipynb +335 -0
  36. submissions_extracted/1008/Q1.ipynb +325 -0
  37. submissions_extracted/1008/Q3.ipynb +190 -0
  38. submissions_extracted/1009/Q1.ipynb +317 -0
  39. submissions_extracted/101/Q1.ipynb +326 -0
  40. submissions_extracted/101/Q2.ipynb +386 -0
  41. submissions_extracted/101/Q3.ipynb +318 -0
  42. submissions_extracted/1010/Q1.ipynb +289 -0
  43. submissions_extracted/1010/Q2.ipynb +353 -0
  44. submissions_extracted/1010/Q3.ipynb +274 -0
  45. submissions_extracted/1011/Q1.ipynb +325 -0
  46. submissions_extracted/1011/Q2.ipynb +488 -0
  47. submissions_extracted/1011/Q3.ipynb +332 -0
  48. submissions_extracted/1012/Q1.ipynb +285 -0
  49. submissions_extracted/1012/Q2.ipynb +394 -0
  50. submissions_extracted/1012/Q3.ipynb +264 -0
Practical_AI_exam_grades.csv ADDED
@@ -0,0 +1,1039 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Number,TA_1_ID,TA_2_ID,TA 1 - Q1 Grade,TA 1 - Q2 Grade,TA 1 - Q3 Grade,TA 1 - Total Grade,TA 2 - Q1 Grade,TA 2 - Q2 Grade,TA 2 - Q3 Grade,TA 2 - Total Grade,Average Grade
2
+ 1,TA_1,TA_2,3.0,0.0,2.0,5.0,7.0,0.0,2.0,9.0,7.0
3
+ 2,TA_1,TA_2,1.0,0.0,0.0,1.0,1.5,0.0,0.0,1.5,1.25
4
+ 3,TA_1,TA_2,2.0,0.0,2.0,4.0,2.5,0.0,2.0,4.5,4.25
5
+ 4,TA_1,TA_2,6.0,9.0,5.0,20.0,4.5,5.5,5.5,15.5,17.75
6
+ 5,TA_1,TA_2,8.0,0.0,0.0,8.0,9.0,0.0,0.0,9.0,8.5
7
+ 6,TA_1,TA_2,14.0,0.0,2.0,16.0,15.0,0.0,2.0,17.0,16.5
8
+ 7,TA_1,TA_2,1.5,0.0,0.0,1.5,5.0,0.0,0.0,5.0,3.25
9
+ 8,TA_1,TA_2,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0
10
+ 9,TA_1,TA_2,4.5,1.0,2.5,8.0,2.5,6.0,3.5,12.0,10.0
11
+ 10,TA_1,TA_2,15.0,16.0,21.0,52.0,21.0,17.0,22.0,60.0,56.0
12
+ 11,TA_1,TA_2,3.0,9.0,0.0,12.0,4.0,8.0,0.0,12.0,12.0
13
+ 12,TA_1,TA_2,1.5,3.5,1.5,6.5,-0.5,2.5,3.0,5.0,5.75
14
+ 13,TA_1,TA_2,8.0,2.25,3.0,13.25,7.5,3.5,3.5,14.5,13.875
15
+ 14,TA_1,TA_2,6.0,10.0,13.0,29.0,5.0,7.0,12.0,24.0,26.5
16
+ 15,TA_1,TA_2,8.5,9.0,4.0,21.5,9.5,7.5,3.5,20.5,21.0
17
+ 16,TA_1,TA_2,2.5,0.0,0.0,2.5,1.0,1.0,0.0,2.0,2.25
18
+ 17,TA_1,TA_2,4.75,0.0,2.5,7.25,5.5,0.0,2.5,8.0,7.625
19
+ 18,TA_1,TA_2,1.5,0.0,0.0,1.5,2.0,0.0,0.0,2.0,1.75
20
+ 19,TA_1,TA_2,11.0,0.0,0.0,11.0,11.5,0.0,0.0,11.5,11.25
21
+ 20,TA_1,TA_2,1.5,3.5,1.5,6.5,3.0,7.5,3.0,13.5,10.0
22
+ 21,TA_1,TA_2,2.0,0.0,0.0,2.0,2.0,0.0,0.0,2.0,2.0
23
+ 22,TA_1,TA_2,0.0,2.0,0.0,2.0,0.0,0.0,0.0,0.0,1.0
24
+ 23,TA_1,TA_2,6.5,3.0,0.0,9.5,4.0,4.0,0.0,8.0,8.75
25
+ 24,TA_1,TA_2,15.0,4.0,2.0,21.0,17.5,4.0,2.0,23.5,22.25
26
+ 25,TA_1,TA_2,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0
27
+ 26,TA_1,TA_2,6.0,2.0,0.0,8.0,8.0,3.0,0.0,11.0,9.5
28
+ 27,TA_1,TA_2,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0
29
+ 28,TA_1,TA_2,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0
30
+ 29,TA_1,TA_2,6.0,6.5,14.0,26.5,0.0,0.0,0.0,0.0,13.25
31
+ 30,TA_1,TA_2,4.0,0.0,0.0,4.0,3.5,0.0,0.0,3.5,3.75
32
+ 31,TA_1,TA_2,1.25,0.0,2.0,3.25,2.0,0.0,2.0,4.0,3.625
33
+ 32,TA_1,TA_2,8.5,0.0,4.0,12.5,13.5,2.0,5.5,21.0,16.75
34
+ 33,TA_1,TA_2,10.5,0.0,0.0,10.5,13.5,0.0,0.0,13.5,12.0
35
+ 34,TA_1,TA_2,3.0,0.0,0.0,3.0,3.0,0.0,0.0,3.0,3.0
36
+ 35,TA_1,TA_2,1.5,0.0,0.0,1.5,2.0,0.0,0.0,2.0,1.75
37
+ 36,TA_1,TA_2,1.0,0.0,0.0,1.0,-1.5,0.0,0.0,-1.5,-0.25
38
+ 37,TA_1,TA_2,0.0,2.0,0.0,2.0,-1.0,1.5,0.0,0.5,1.25
39
+ 38,TA_1,TA_2,12.0,0.0,6.0,18.0,13.5,0.0,5.5,19.0,18.5
40
+ 39,TA_1,TA_2,5.0,0.0,0.0,5.0,11.0,0.0,0.0,11.0,8.0
41
+ 40,TA_1,TA_2,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0
42
+ 41,TA_1,TA_2,1.5,4.0,3.5,9.0,5.5,4.5,4.5,14.5,11.75
43
+ 42,TA_1,TA_2,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0
44
+ 43,TA_1,TA_2,1.0,0.0,0.0,1.0,0.5,0.0,0.0,0.5,0.75
45
+ 44,TA_3,TA_4,7.0,8.25,3.0,18.25,9.0,8.0,2.0,19.0,18.625
46
+ 45,TA_3,TA_4,4.0,2.5,5.0,11.5,6.0,2.75,4.5,13.25,12.375
47
+ 46,TA_3,TA_4,2.0,8.75,2.0,12.75,3.0,7.75,2.0,12.75,12.75
48
+ 47,TA_3,TA_4,2.0,8.75,4.25,15.0,2.2,7.5,4.0,13.7,14.35
49
+ 48,TA_3,TA_4,10.0,6.75,4.5,21.25,9.5,6.5,5.0,21.0,21.125
50
+ 49,TA_3,TA_4,6.0,9.75,5.5,21.25,5.5,9.0,7.0,21.5,21.375
51
+ 50,TA_3,TA_4,7.5,2.75,0.0,10.25,11.2,3.5,0.0,14.7,12.475
52
+ 51,TA_3,TA_4,11.0,0.75,0.0,11.75,10.5,3.0,0.0,13.5,12.625
53
+ 52,TA_3,TA_4,9.0,0.0,4.25,13.25,7.0,0.0,3.0,10.0,11.625
54
+ 53,TA_3,TA_4,3.0,2.75,2.0,7.75,4.0,4.0,2.0,10.0,8.875
55
+ 54,TA_3,TA_4,10.5,0.0,0.0,10.5,10.5,0.0,0.0,10.5,10.5
56
+ 55,TA_3,TA_4,10.0,7.75,10.0,27.75,14.0,7.25,7.0,28.25,28.0
57
+ 56,TA_3,TA_4,21.0,17.0,20.0,58.0,20.5,17.0,19.25,56.75,57.375
58
+ 57,TA_3,TA_4,11.0,8.5,8.5,28.0,6.5,9.5,6.25,22.25,25.125
59
+ 58,TA_3,TA_4,9.5,9.5,4.5,23.5,10.0,9.5,5.0,24.5,24.0
60
+ 59,TA_3,TA_4,4.0,9.0,8.25,21.25,4.5,11.0,9.0,24.5,22.875
61
+ 60,TA_3,TA_4,20.0,16.25,21.5,57.75,20.0,15.0,19.75,54.75,56.25
62
+ 61,TA_3,TA_4,22.0,15.0,22.0,59.0,20.0,16.0,19.5,55.5,57.25
63
+ 62,TA_3,TA_4,7.0,9.5,7.5,24.0,14.25,9.5,8.0,31.75,27.875
64
+ 63,TA_3,TA_4,6.5,9.25,7.5,23.25,7.15,9.25,5.0,21.4,22.325
65
+ 64,TA_3,TA_4,10.5,11.5,5.0,27.0,12.5,10.5,2.0,25.0,26.0
66
+ 65,TA_3,TA_4,8.5,13.0,2.0,23.5,12.0,12.5,2.0,26.5,25.0
67
+ 66,TA_3,TA_4,25.0,0.0,0.0,25.0,20.0,0.0,0.0,20.0,22.5
68
+ 67,TA_3,TA_4,8.5,0.0,8.5,17.0,10.0,0.0,6.5,16.5,16.75
69
+ 68,TA_3,TA_4,5.5,6.5,4.5,16.5,4.9,6.5,4.5,15.9,16.2
70
+ 69,TA_3,TA_4,8.5,0.0,2.0,10.5,10.0,0.0,2.0,12.0,11.25
71
+ 70,TA_3,TA_4,20.0,17.0,18.0,55.0,20.0,17.0,15.0,52.0,53.5
72
+ 71,TA_3,TA_4,0.0,4.25,0.0,4.25,2.5,4.5,0.0,7.0,5.625
73
+ 72,TA_3,TA_4,16.5,0.0,5.0,21.5,19.35,0.0,5.5,24.85,23.175
74
+ 73,TA_3,TA_4,1.5,3.0,1.0,5.5,1.5,3.5,2.5,7.5,6.5
75
+ 74,TA_3,TA_4,4.0,10.5,3.75,18.25,6.3,10.5,3.0,19.8,19.025
76
+ 75,TA_3,TA_4,11.0,0.0,4.0,15.0,10.4,0.0,4.0,14.4,14.7
77
+ 76,TA_3,TA_4,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0
78
+ 77,TA_3,TA_4,6.0,0.0,0.0,6.0,5.5,0.0,0.0,5.5,5.75
79
+ 78,TA_3,TA_4,6.0,6.5,0.0,12.5,6.5,5.5,2.0,14.0,13.25
80
+ 79,TA_3,TA_4,9.5,3.5,8.0,21.0,10.5,3.0,7.25,20.75,20.875
81
+ 80,TA_3,TA_4,5.0,4.25,4.5,13.75,5.3,5.5,4.0,14.8,14.275
82
+ 81,TA_3,TA_4,22.0,17.0,16.25,55.25,22.0,17.0,15.75,54.75,55.0
83
+ 82,TA_3,TA_4,14.0,15.0,17.25,46.25,15.15,15.9,15.55,46.6,46.425
84
+ 83,TA_3,TA_4,4.0,0.5,6.0,10.5,5.3,1.0,5.5,11.8,11.15
85
+ 84,TA_3,TA_4,6.0,0.0,0.0,6.0,3.75,0.0,0.0,3.75,4.875
86
+ 85,TA_3,TA_4,9.5,10.5,3.75,23.75,6.2,10.5,3.0,19.7,21.725
87
+ 86,TA_3,TA_4,10.0,11.0,6.75,27.75,12.0,10.75,7.5,30.25,29.0
88
+ 87,TA_3,TA_4,0.5,0.0,2.0,2.5,1.2,0.0,2.0,3.2,2.85
89
+ 88,TA_3,TA_4,20.0,10.5,5.75,36.25,21.0,8.75,5.5,35.25,35.75
90
+ 89,TA_5,TA_6,4.0,10.5,9.5,24.0,2.5,10.0,8.75,21.25,22.625
91
+ 90,TA_5,TA_6,0.5,0.0,0.0,0.5,2.75,0.0,3.5,6.25,3.375
92
+ 91,TA_5,TA_6,13.0,3.0,2.0,18.0,15.0,3.5,2.0,20.5,19.25
93
+ 92,TA_5,TA_6,1.0,5.0,1.25,7.25,5.75,6.0,2.5,14.25,10.75
94
+ 93,TA_5,TA_6,7.0,2.0,2.0,11.0,9.0,2.0,2.0,13.0,12.0
95
+ 94,TA_5,TA_6,13.5,9.0,0.0,22.5,16.0,7.5,0.0,23.5,23.0
96
+ 95,TA_5,TA_6,11.0,2.0,5.25,18.25,11.0,2.0,5.5,18.5,18.375
97
+ 96,TA_5,TA_6,3.0,0.0,3.0,6.0,6.0,0.5,3.0,9.5,7.75
98
+ 97,TA_5,TA_6,3.25,0.0,0.0,3.25,3.0,0.0,0.0,3.0,3.125
99
+ 98,TA_5,TA_6,3.0,8.5,4.0,15.5,5.5,9.0,4.25,18.75,17.125
100
+ 99,TA_5,TA_6,20.0,16.0,17.5,53.5,20.5,16.75,19.25,56.5,55.0
101
+ 100,TA_5,TA_6,6.0,7.0,5.5,18.5,5.5,6.5,5.5,17.5,18.0
102
+ 101,TA_5,TA_6,10.0,10.0,16.5,36.5,9.5,10.5,16.5,36.5,36.5
103
+ 102,TA_5,TA_6,11.0,0.0,15.0,26.0,11.5,0.0,13.75,25.25,25.625
104
+ 103,TA_5,TA_6,6.0,0.0,4.0,10.0,9.0,0.0,4.75,13.75,11.875
105
+ 104,TA_5,TA_6,5.0,11.0,8.25,24.25,6.5,10.5,7.25,24.25,24.25
106
+ 105,TA_5,TA_6,5.0,10.5,2.0,17.5,5.5,9.0,2.25,16.75,17.125
107
+ 106,TA_5,TA_6,17.0,11.75,10.5,39.25,17.0,11.0,9.5,37.5,38.375
108
+ 107,TA_5,TA_6,20.5,10.5,0.0,31.0,20.5,8.5,0.0,29.0,30.0
109
+ 108,TA_5,TA_6,-1.0,5.0,0.0,4.0,1.0,3.5,0.0,4.5,4.25
110
+ 109,TA_5,TA_6,11.5,11.0,5.0,27.5,6.0,11.0,5.0,22.0,24.75
111
+ 110,TA_5,TA_6,5.5,10.0,14.0,29.5,6.5,8.5,14.0,29.0,29.25
112
+ 111,TA_5,TA_6,11.5,11.5,3.75,26.75,14.5,10.0,4.0,28.5,27.625
113
+ 112,TA_5,TA_6,16.0,11.0,3.75,30.75,16.5,10.0,4.0,30.5,30.625
114
+ 113,TA_5,TA_6,22.0,17.0,18.5,57.5,22.0,17.0,16.5,55.5,56.5
115
+ 114,TA_5,TA_6,5.0,12.0,9.0,26.0,7.5,9.5,8.5,25.5,25.75
116
+ 115,TA_5,TA_6,3.25,7.75,4.0,15.0,3.0,7.0,3.0,13.0,14.0
117
+ 116,TA_5,TA_6,0.0,0.0,1.5,1.5,0.0,0.0,1.5,1.5,1.5
118
+ 117,TA_5,TA_6,-0.5,4.25,0.0,3.75,2.5,3.5,1.0,7.0,5.375
119
+ 118,TA_5,TA_6,2.0,6.75,3.25,12.0,3.5,8.0,4.0,15.5,13.75
120
+ 119,TA_5,TA_6,26.0,15.0,22.0,63.0,26.0,15.5,22.5,64.0,63.5
121
+ 120,TA_5,TA_6,0.5,3.5,2.0,6.0,2.0,4.0,2.0,8.0,7.0
122
+ 121,TA_5,TA_6,3.5,0.0,4.0,7.5,6.5,0.0,5.25,11.75,9.625
123
+ 122,TA_5,TA_6,7.0,10.75,0.0,17.75,6.0,9.0,0.0,15.0,16.375
124
+ 123,TA_5,TA_6,0.5,2.0,2.5,5.0,0.0,1.75,2.75,4.5,4.75
125
+ 124,TA_5,TA_6,10.0,11.0,5.75,26.75,9.0,8.75,5.25,23.0,24.875
126
+ 125,TA_5,TA_6,8.5,0.0,0.0,8.5,9.0,0.0,0.0,9.0,8.75
127
+ 126,TA_5,TA_6,5.0,12.0,0.0,17.0,6.0,11.5,0.0,17.5,17.25
128
+ 127,TA_5,TA_6,12.5,10.5,3.5,26.5,14.0,10.0,4.25,28.25,27.375
129
+ 128,TA_5,TA_6,8.5,9.5,3.0,21.0,10.0,8.5,3.0,21.5,21.25
130
+ 129,TA_5,TA_6,21.0,14.0,22.0,57.0,19.5,14.0,21.0,54.5,55.75
131
+ 130,TA_5,TA_6,9.0,10.5,8.0,27.5,10.0,9.0,2.0,21.0,24.25
132
+ 131,TA_5,TA_6,6.5,11.0,4.5,22.0,7.0,9.0,4.5,20.5,21.25
133
+ 132,TA_5,TA_6,9.5,8.0,9.25,26.75,9.0,7.0,10.25,26.25,26.5
134
+ 133,TA_5,TA_6,8.0,10.5,10.5,29.0,6.0,12.5,12.0,30.5,29.75
135
+ 134,TA_7,TA_8,13.0,11.75,2.25,27.0,10.5,10.55,2.0,23.05,25.025
136
+ 135,TA_7,TA_8,25.0,16.0,17.5,58.5,23.0,13.0,16.0,52.0,55.25
137
+ 136,TA_7,TA_8,7.5,10.0,6.0,23.5,4.75,10.5,5.5,20.75,22.125
138
+ 137,TA_7,TA_8,12.0,7.25,6.0,25.25,7.5,9.55,5.5,22.55,23.9
139
+ 138,TA_7,TA_8,18.5,12.5,2.25,33.25,17.75,12.5,2.0,32.25,32.75
140
+ 139,TA_7,TA_8,6.0,10.5,6.5,23.0,6.65,11.1,11.5,29.25,26.125
141
+ 140,TA_7,TA_8,22.0,12.5,19.0,53.5,20.25,13.0,19.0,52.25,52.875
142
+ 141,TA_7,TA_8,17.5,11.0,19.0,47.5,13.5,12.5,19.0,45.0,46.25
143
+ 142,TA_7,TA_8,16.5,11.5,3.0,31.0,19.0,12.25,4.0,35.25,33.125
144
+ 143,TA_7,TA_8,17.5,11.5,13.0,42.0,16.0,12.1,16.5,44.6,43.3
145
+ 144,TA_7,TA_8,9.0,0.0,3.5,12.5,9.5,0.0,3.25,12.75,12.625
146
+ 145,TA_7,TA_8,5.5,0.0,9.0,14.5,3.5,0.0,7.5,11.0,12.75
147
+ 146,TA_7,TA_8,3.5,0.0,3.5,7.0,3.0,0.0,4.0,7.0,7.0
148
+ 147,TA_7,TA_8,9.0,10.0,9.0,28.0,9.25,11.65,10.0,30.9,29.45
149
+ 148,TA_7,TA_8,11.0,8.5,12.5,32.0,4.8,7.5,13.0,25.3,28.65
150
+ 149,TA_7,TA_8,8.5,7.25,9.5,25.25,7.75,8.5,11.0,27.25,26.25
151
+ 150,TA_7,TA_8,10.0,6.5,11.0,27.5,8.5,8.75,13.5,30.75,29.125
152
+ 151,TA_7,TA_8,4.5,10.5,4.0,19.0,4.75,11.75,3.5,20.0,19.5
153
+ 152,TA_7,TA_8,12.0,6.5,8.5,27.0,13.5,10.25,8.5,32.25,29.625
154
+ 153,TA_7,TA_8,19.5,6.5,6.0,32.0,16.5,9.55,6.5,32.55,32.275
155
+ 154,TA_7,TA_8,26.0,16.0,22.0,64.0,21.0,15.0,21.0,57.0,60.5
156
+ 155,TA_7,TA_8,0.0,2.0,0.0,2.0,0.0,3.75,0.0,3.75,2.875
157
+ 156,TA_7,TA_8,5.5,7.75,3.5,16.75,4.5,12.5,4.5,21.5,19.125
158
+ 157,TA_7,TA_8,19.5,2.5,3.0,25.0,15.0,4.0,3.0,22.0,23.5
159
+ 158,TA_7,TA_8,0.5,0.5,0.0,1.0,0.0,0.0,4.0,4.0,2.5
160
+ 159,TA_7,TA_8,8.5,8.5,7.5,24.5,7.5,10.35,12.0,29.85,27.175
161
+ 160,TA_7,TA_8,10.5,4.5,10.0,25.0,13.5,10.85,10.2,34.55,29.775
162
+ 161,TA_7,TA_8,2.5,9.0,4.5,16.0,6.75,10.6,5.0,22.35,19.175
163
+ 162,TA_7,TA_8,14.0,16.0,20.0,50.0,19.75,16.0,22.0,57.75,53.875
164
+ 163,TA_7,TA_8,13.0,9.5,6.5,29.0,12.4,10.6,7.0,30.0,29.5
165
+ 164,TA_7,TA_8,14.0,9.5,5.5,29.0,6.75,10.75,7.5,25.0,27.0
166
+ 165,TA_7,TA_8,19.0,11.0,13.0,43.0,9.5,13.4,14.5,37.4,40.2
167
+ 166,TA_7,TA_8,8.0,10.0,6.5,24.5,4.15,10.65,5.25,20.05,22.275
168
+ 167,TA_7,TA_8,5.0,7.5,5.5,18.0,7.0,10.75,6.5,24.25,21.125
169
+ 168,TA_7,TA_8,26.0,16.0,22.0,64.0,23.0,16.0,20.5,59.5,61.75
170
+ 169,TA_7,TA_8,2.5,0.0,0.0,2.5,2.0,0.0,0.0,2.0,2.25
171
+ 170,TA_7,TA_8,10.5,0.0,11.0,21.5,10.5,0.0,12.5,23.0,22.25
172
+ 171,TA_7,TA_8,6.5,1.5,2.0,10.0,4.5,2.0,1.0,7.5,8.75
173
+ 172,TA_7,TA_8,8.5,8.5,5.0,22.0,13.5,9.55,5.5,28.55,25.275
174
+ 173,TA_7,TA_8,5.0,8.5,8.5,22.0,5.5,12.5,8.25,26.25,24.125
175
+ 174,TA_7,TA_8,9.0,0.0,3.0,12.0,10.0,0.0,2.5,12.5,12.25
176
+ 175,TA_7,TA_8,16.0,7.5,6.0,29.5,13.0,7.55,7.5,28.05,28.775
177
+ 176,TA_7,TA_8,20.0,10.5,11.0,41.5,15.5,10.75,13.5,39.75,40.625
178
+ 177,TA_9,TA_10,14.5,10.0,0.0,24.5,15.0,8.0,0.0,23.0,23.75
179
+ 178,TA_9,TA_10,11.5,3.0,2.0,16.5,11.5,3.0,3.0,17.5,17.0
180
+ 179,TA_9,TA_10,1.5,0.0,0.5,2.0,0.0,0.0,0.0,0.0,1.0
181
+ 180,TA_9,TA_10,9.5,0.0,5.5,15.0,10.0,0.0,4.0,14.0,14.5
182
+ 181,TA_9,TA_10,8.5,11.0,6.0,25.5,6.0,11.0,4.0,21.0,23.25
183
+ 182,TA_9,TA_10,21.0,12.5,20.5,54.0,18.5,14.0,17.0,49.5,51.75
184
+ 183,TA_9,TA_10,18.0,10.5,13.0,41.5,14.0,13.0,12.0,39.0,40.25
185
+ 184,TA_9,TA_10,21.0,17.0,21.0,59.0,18.0,12.0,18.0,48.0,53.5
186
+ 185,TA_9,TA_10,23.0,10.5,11.0,44.5,22.0,11.0,8.0,41.0,42.75
187
+ 186,TA_9,TA_10,11.0,8.0,4.5,23.5,13.0,5.0,8.0,26.0,24.75
188
+ 187,TA_9,TA_10,20.0,17.0,22.0,59.0,19.0,14.0,19.0,52.0,55.5
189
+ 188,TA_9,TA_10,2.0,8.0,0.0,10.0,3.0,7.0,0.0,10.0,10.0
190
+ 189,TA_9,TA_10,19.5,15.5,20.5,55.5,17.0,14.0,17.0,48.0,51.75
191
+ 190,TA_9,TA_10,19.25,15.5,18.25,53.0,12.0,14.0,6.0,32.0,42.5
192
+ 191,TA_9,TA_10,10.0,10.5,14.0,34.5,6.0,6.0,7.0,19.0,26.75
193
+ 192,TA_9,TA_10,13.0,10.5,9.0,32.5,4.0,6.0,4.0,14.0,23.25
194
+ 193,TA_9,TA_10,7.5,6.5,8.0,22.0,10.0,5.0,6.0,21.0,21.5
195
+ 194,TA_9,TA_10,7.0,12.0,8.5,27.5,3.0,4.0,4.0,11.0,19.25
196
+ 195,TA_9,TA_10,5.5,6.0,6.5,18.0,3.5,0.5,4.0,8.0,13.0
197
+ 196,TA_9,TA_10,25.0,17.0,19.0,61.0,25.0,16.0,19.0,60.0,60.5
198
+ 197,TA_9,TA_10,6.5,9.5,10.5,26.5,11.0,10.5,6.5,28.0,27.25
199
+ 198,TA_9,TA_10,10.5,9.5,13.0,33.0,9.0,10.5,9.5,29.0,31.0
200
+ 199,TA_9,TA_10,8.0,2.5,5.5,16.0,7.5,0.5,4.5,12.5,14.25
201
+ 200,TA_9,TA_10,9.0,5.5,12.5,27.0,6.0,3.0,11.0,20.0,23.5
202
+ 201,TA_9,TA_10,12.5,5.5,9.0,27.0,10.0,5.0,8.0,23.0,25.0
203
+ 202,TA_9,TA_10,12.5,0.0,0.0,12.5,11.0,0.0,0.0,11.0,11.75
204
+ 203,TA_9,TA_10,11.5,11.0,5.5,28.0,10.0,14.0,5.0,29.0,28.5
205
+ 204,TA_9,TA_10,10.5,12.5,6.0,29.0,7.5,16.0,5.0,28.5,28.75
206
+ 205,TA_9,TA_10,13.5,10.0,9.5,33.0,8.0,9.0,6.0,23.0,28.0
207
+ 206,TA_9,TA_10,15.0,11.5,19.0,45.5,12.5,13.0,18.5,44.0,44.75
208
+ 207,TA_9,TA_10,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0
209
+ 208,TA_9,TA_10,11.5,12.5,12.5,36.5,8.5,9.0,14.0,31.5,34.0
210
+ 209,TA_9,TA_10,20.5,17.0,17.5,55.0,20.0,15.0,15.0,50.0,52.5
211
+ 210,TA_9,TA_10,17.5,13.5,19.5,50.5,16.0,11.0,17.0,44.0,47.25
212
+ 211,TA_9,TA_10,14.0,11.0,15.0,40.0,9.0,5.0,13.0,27.0,33.5
213
+ 212,TA_9,TA_10,5.0,3.0,5.0,13.0,4.0,3.0,4.0,11.0,12.0
214
+ 213,TA_9,TA_10,17.0,11.5,2.0,30.5,16.0,14.0,2.0,32.0,31.25
215
+ 214,TA_9,TA_10,17.0,0.0,0.0,17.0,17.0,0.0,0.0,17.0,17.0
216
+ 215,TA_9,TA_10,19.5,14.0,18.5,52.0,17.0,14.0,18.0,49.0,50.5
217
+ 216,TA_9,TA_10,15.5,12.5,18.5,46.5,16.0,13.0,19.0,48.0,47.25
218
+ 217,TA_9,TA_10,19.5,10.0,4.5,34.0,16.0,11.0,2.5,29.5,31.75
219
+ 218,TA_9,TA_10,12.5,7.0,6.0,25.5,12.0,7.0,4.0,23.0,24.25
220
+ 219,TA_9,TA_10,23.5,15.0,16.0,54.5,21.0,14.0,17.0,52.0,53.25
221
+ 220,TA_9,TA_10,23.0,11.0,20.0,54.0,22.0,12.0,18.0,52.0,53.0
222
+ 221,TA_11,TA_12,10.5,13.5,11.5,35.5,10.0,11.0,7.0,28.0,31.75
223
+ 222,TA_11,TA_12,12.5,11.75,12.5,36.75,16.0,10.0,12.0,38.0,37.375
224
+ 223,TA_11,TA_12,13.0,11.75,11.0,35.75,13.0,8.0,10.0,31.0,33.375
225
+ 224,TA_11,TA_12,13.5,0.0,10.0,23.5,6.0,0.0,10.0,16.0,19.75
226
+ 225,TA_11,TA_12,10.5,5.0,8.75,24.25,3.0,4.0,8.0,15.0,19.625
227
+ 226,TA_11,TA_12,8.75,10.25,9.5,28.5,3.0,8.0,9.0,20.0,24.25
228
+ 227,TA_11,TA_12,10.0,9.25,0.0,19.25,10.0,10.0,0.0,20.0,19.625
229
+ 228,TA_11,TA_12,11.5,7.5,9.75,28.75,11.0,8.0,12.0,31.0,29.875
230
+ 229,TA_11,TA_12,13.5,9.5,11.5,34.5,7.0,0.0,6.0,13.0,23.75
231
+ 230,TA_11,TA_12,13.0,12.5,9.0,34.5,8.0,0.0,4.0,12.0,23.25
232
+ 231,TA_11,TA_12,16.0,10.25,12.5,38.75,16.0,11.0,13.5,40.5,39.625
233
+ 232,TA_11,TA_12,11.0,10.5,9.0,30.5,11.0,11.0,6.0,28.0,29.25
234
+ 233,TA_11,TA_12,12.0,0.0,10.0,22.0,9.0,0.0,9.0,18.0,20.0
235
+ 234,TA_11,TA_12,9.5,9.0,5.5,24.0,4.0,0.0,5.0,9.0,16.5
236
+ 235,TA_11,TA_12,24.5,12.0,18.5,55.0,22.0,8.0,20.0,50.0,52.5
237
+ 236,TA_11,TA_12,10.5,11.25,15.0,36.75,9.5,10.0,16.0,35.5,36.125
238
+ 237,TA_11,TA_12,6.25,10.0,0.0,16.25,6.0,8.0,0.0,14.0,15.125
239
+ 238,TA_11,TA_12,18.0,16.0,14.5,48.5,9.5,17.0,8.0,34.5,41.5
240
+ 239,TA_11,TA_12,4.0,12.5,9.0,25.5,3.0,8.0,7.0,18.0,21.75
241
+ 240,TA_11,TA_12,15.5,8.75,18.5,42.75,15.0,0.0,15.0,30.0,36.375
242
+ 241,TA_11,TA_12,16.5,8.5,10.0,35.0,7.0,2.0,5.0,14.0,24.5
243
+ 242,TA_11,TA_12,15.0,12.5,16.0,43.5,13.0,11.0,17.5,41.5,42.5
244
+ 243,TA_11,TA_12,7.0,11.25,11.5,29.75,7.0,10.0,9.0,26.0,27.875
245
+ 244,TA_11,TA_12,19.0,13.0,14.0,46.0,19.0,13.0,12.0,44.0,45.0
246
+ 245,TA_11,TA_12,11.0,11.25,12.5,34.75,6.5,8.0,7.0,21.5,28.125
247
+ 246,TA_11,TA_12,9.0,11.25,9.0,29.25,7.0,10.0,9.0,26.0,27.625
248
+ 247,TA_11,TA_12,13.0,10.0,10.0,33.0,10.0,10.0,6.0,26.0,29.5
249
+ 248,TA_11,TA_12,6.0,0.0,3.5,9.5,5.0,0.0,3.0,8.0,8.75
250
+ 249,TA_11,TA_12,8.25,0.0,6.0,14.25,8.0,0.0,5.0,13.0,13.625
251
+ 250,TA_11,TA_12,2.0,5.75,7.0,14.75,2.0,0.0,4.0,6.0,10.375
252
+ 251,TA_11,TA_12,8.0,9.5,7.0,24.5,0.0,0.0,2.0,2.0,13.25
253
+ 252,TA_11,TA_12,6.25,0.0,2.5,8.75,9.0,0.0,2.0,11.0,9.875
254
+ 253,TA_11,TA_12,8.0,6.0,6.0,20.0,2.0,0.0,5.0,7.0,13.5
255
+ 254,TA_11,TA_12,6.0,8.5,8.0,22.5,3.0,0.0,10.0,13.0,17.75
256
+ 255,TA_11,TA_12,9.0,9.25,9.0,27.25,9.0,9.0,9.0,27.0,27.125
257
+ 256,TA_11,TA_12,2.5,4.0,4.5,11.0,3.0,0.0,2.0,5.0,8.0
258
+ 257,TA_11,TA_12,0.0,0.5,0.0,0.5,0.0,0.0,0.0,0.0,0.25
259
+ 258,TA_11,TA_12,10.5,12.0,0.0,22.5,3.0,4.0,0.0,7.0,14.75
260
+ 259,TA_11,TA_12,8.5,8.75,8.0,25.25,4.0,0.0,5.0,9.0,17.125
261
+ 260,TA_11,TA_12,12.0,0.0,10.0,22.0,9.0,0.0,8.0,17.0,19.5
262
+ 261,TA_11,TA_12,12.0,9.75,10.0,31.75,7.0,9.0,8.0,24.0,27.875
263
+ 262,TA_11,TA_12,9.0,11.0,7.0,27.0,7.0,14.0,3.0,24.0,25.5
264
+ 263,TA_11,TA_12,11.5,4.0,6.5,22.0,6.0,4.0,5.0,15.0,18.5
265
+ 264,TA_11,TA_12,20.0,17.0,22.0,59.0,19.0,17.0,21.0,57.0,58.0
266
+ 265,TA_11,TA_12,11.0,11.0,14.0,36.0,9.0,8.0,15.0,32.0,34.0
267
+ 266,TA_11,TA_12,22.0,17.0,21.0,60.0,26.0,17.0,21.0,64.0,62.0
268
+ 267,TA_11,TA_12,21.0,11.25,18.0,50.25,21.0,12.0,14.0,47.0,48.625
269
+ 268,TA_11,TA_12,17.0,13.5,20.0,50.5,16.0,13.0,17.0,46.0,48.25
270
+ 269,TA_13,TA_14,10.0,0.0,0.0,10.0,28.0,0.0,0.0,28.0,19.0
271
+ 270,TA_13,TA_14,10.0,7.0,5.0,22.0,21.0,13.0,5.0,39.0,30.5
272
+ 271,TA_13,TA_14,10.0,7.0,0.0,17.0,11.5,11.5,2.5,25.5,21.25
273
+ 272,TA_13,TA_14,23.0,8.0,23.0,54.0,22.0,14.5,22.0,58.5,56.25
274
+ 273,TA_13,TA_14,20.0,16.0,0.0,36.0,12.5,17.0,10.5,40.0,38.0
275
+ 274,TA_13,TA_14,17.0,14.0,23.0,54.0,18.5,17.0,22.0,57.5,55.75
276
+ 275,TA_13,TA_14,15.0,9.0,20.0,44.0,14.0,13.0,19.5,46.5,45.25
277
+ 276,TA_13,TA_14,23.0,16.0,0.0,39.0,24.5,16.0,0.0,40.5,39.75
278
+ 277,TA_13,TA_14,23.0,10.0,8.0,41.0,21.0,10.5,10.0,41.5,41.25
279
+ 278,TA_13,TA_14,25.0,14.0,22.0,61.0,24.0,17.0,19.0,60.0,60.5
280
+ 279,TA_13,TA_14,12.0,0.0,12.0,24.0,10.5,7.5,5.0,23.0,23.5
281
+ 280,TA_13,TA_14,15.0,7.0,5.0,27.0,14.5,8.5,3.0,26.0,26.5
282
+ 281,TA_13,TA_14,10.0,5.0,10.0,25.0,11.5,7.0,5.0,23.5,24.25
283
+ 282,TA_13,TA_14,13.0,7.0,15.0,35.0,12.5,4.0,17.0,33.5,34.25
284
+ 283,TA_13,TA_14,25.0,16.0,23.0,64.0,23.0,17.0,22.0,62.0,63.0
285
+ 284,TA_13,TA_14,22.0,13.0,8.0,43.0,16.5,17.0,7.0,40.5,41.75
286
+ 285,TA_13,TA_14,20.0,0.0,0.0,20.0,10.5,0.0,6.5,17.0,18.5
287
+ 286,TA_13,TA_14,8.0,5.0,10.0,23.0,8.5,8.5,2.0,19.0,21.0
288
+ 287,TA_13,TA_14,23.0,16.0,16.0,55.0,15.0,17.0,19.0,51.0,53.0
289
+ 288,TA_13,TA_14,20.0,10.0,7.0,37.0,15.0,11.5,5.5,32.0,34.5
290
+ 289,TA_13,TA_14,12.0,0.0,0.0,12.0,5.0,1.0,1.0,7.0,9.5
291
+ 290,TA_13,TA_14,22.0,16.0,23.0,61.0,19.5,17.0,19.0,55.5,58.25
292
+ 291,TA_13,TA_14,23.0,8.0,0.0,31.0,18.0,7.5,0.0,25.5,28.25
293
+ 292,TA_13,TA_14,14.0,12.0,23.0,49.0,14.5,13.0,15.5,43.0,46.0
294
+ 293,TA_13,TA_14,15.0,5.0,7.0,27.0,9.5,7.0,4.0,20.5,23.75
295
+ 294,TA_13,TA_14,15.0,0.0,20.0,35.0,7.0,7.0,14.0,28.0,31.5
296
+ 295,TA_13,TA_14,20.0,8.0,23.0,51.0,16.0,9.5,18.5,44.0,47.5
297
+ 296,TA_13,TA_14,25.0,16.0,22.0,63.0,20.0,14.0,22.0,56.0,59.5
298
+ 297,TA_13,TA_14,22.0,16.0,15.0,53.0,21.0,14.0,10.5,45.5,49.25
299
+ 298,TA_13,TA_14,15.0,12.0,17.0,44.0,17.0,11.0,6.5,34.5,39.25
300
+ 299,TA_13,TA_14,20.0,10.0,8.0,38.0,10.0,9.0,9.5,28.5,33.25
301
+ 300,TA_13,TA_14,10.0,0.0,10.0,20.0,3.0,5.0,2.0,10.0,15.0
302
+ 301,TA_13,TA_14,10.0,8.0,15.0,33.0,15.0,2.0,4.5,21.5,27.25
303
+ 302,TA_13,TA_14,7.0,8.0,12.0,27.0,4.5,5.0,5.5,15.0,21.0
304
+ 303,TA_13,TA_14,23.0,16.0,15.0,54.0,21.0,5.5,12.0,38.5,46.25
305
+ 304,TA_13,TA_14,15.0,8.0,12.0,35.0,10.0,0.0,8.0,18.0,26.5
306
+ 305,TA_13,TA_14,16.0,5.0,8.0,29.0,7.5,0.0,4.0,11.5,20.25
307
+ 306,TA_13,TA_14,15.0,10.0,10.0,35.0,7.5,9.0,0.0,16.5,25.75
308
+ 307,TA_13,TA_14,7.0,12.0,8.0,27.0,3.0,0.0,0.0,3.0,15.0
309
+ 308,TA_13,TA_14,19.0,6.0,16.0,41.0,6.0,0.0,5.0,11.0,26.0
310
+ 309,TA_13,TA_14,15.0,16.0,16.0,47.0,8.0,3.0,4.0,15.0,31.0
311
+ 310,TA_13,TA_14,23.0,12.0,10.0,45.0,4.0,0.0,0.0,4.0,24.5
312
+ 311,TA_15,TA_16,18.0,9.5,5.0,32.5,14.0,6.25,4.0,24.25,28.375
313
+ 312,TA_15,TA_16,10.5,13.5,7.0,31.0,0.0,6.5,6.25,12.75,21.875
314
+ 313,TA_15,TA_16,17.5,13.0,13.5,44.0,15.5,14.0,16.5,46.0,45.0
315
+ 314,TA_15,TA_16,17.5,13.0,6.0,36.5,12.0,9.5,7.0,28.5,32.5
316
+ 315,TA_15,TA_16,19.5,10.5,17.0,47.0,13.5,7.0,18.5,39.0,43.0
317
+ 316,TA_15,TA_16,17.5,13.0,7.0,37.5,16.0,12.5,6.0,34.5,36.0
318
+ 317,TA_15,TA_16,14.0,5.0,10.0,29.0,9.0,0.0,18.0,27.0,28.0
319
+ 318,TA_15,TA_16,22.0,11.0,18.5,51.5,21.5,8.75,18.0,48.25,49.875
320
+ 319,TA_15,TA_16,6.5,0.0,9.0,15.5,12.0,3.0,12.5,27.5,21.5
321
+ 320,TA_15,TA_16,11.5,12.0,9.5,33.0,20.5,0.0,13.0,33.5,33.25
322
+ 321,TA_15,TA_16,19.5,11.0,9.5,40.0,16.5,9.0,11.5,37.0,38.5
323
+ 322,TA_15,TA_16,19.0,13.0,11.0,43.0,15.0,14.0,13.25,42.25,42.625
324
+ 323,TA_15,TA_16,22.5,17.0,21.5,61.0,23.0,15.5,21.0,59.5,60.25
325
+ 324,TA_15,TA_16,15.0,12.0,11.5,38.5,12.0,9.0,12.5,33.5,36.0
326
+ 325,TA_15,TA_16,13.5,17.0,19.5,50.0,22.5,16.0,21.5,60.0,55.0
327
+ 326,TA_15,TA_16,6.5,1.0,3.0,10.5,15.5,3.0,4.0,22.5,16.5
328
+ 327,TA_15,TA_16,8.0,9.5,7.5,25.0,7.0,2.0,16.5,25.5,25.25
329
+ 328,TA_15,TA_16,11.0,8.0,9.5,28.5,9.75,8.5,5.0,23.25,25.875
330
+ 329,TA_15,TA_16,8.5,10.5,0.0,19.0,8.0,8.0,0.0,16.0,17.5
331
+ 330,TA_15,TA_16,19.0,11.5,6.5,37.0,21.5,4.0,6.0,31.5,34.25
332
+ 331,TA_15,TA_16,23.0,12.0,13.0,48.0,22.0,6.0,0.0,28.0,38.0
333
+ 332,TA_15,TA_16,13.5,11.5,7.5,32.5,11.0,8.5,17.0,36.5,34.5
334
+ 333,TA_15,TA_16,14.0,10.5,2.0,26.5,21.0,9.0,2.0,32.0,29.25
335
+ 334,TA_15,TA_16,15.5,12.5,6.0,34.0,19.0,10.0,4.0,33.0,33.5
336
+ 335,TA_15,TA_16,7.5,0.0,3.0,10.5,12.5,1.0,4.0,17.5,14.0
337
+ 336,TA_15,TA_16,18.5,12.5,13.0,44.0,22.75,10.5,11.25,44.5,44.25
338
+ 337,TA_15,TA_16,12.5,0.0,11.0,23.5,14.0,1.0,7.0,22.0,22.75
339
+ 338,TA_15,TA_16,17.5,12.0,8.5,38.0,12.5,9.0,3.0,24.5,31.25
340
+ 339,TA_15,TA_16,9.0,9.0,0.0,18.0,12.25,4.5,0.0,16.75,17.375
341
+ 340,TA_15,TA_16,10.0,0.5,6.0,16.5,15.5,4.0,7.0,26.5,21.5
342
+ 341,TA_15,TA_16,14.5,11.5,4.5,30.5,15.0,8.0,5.0,28.0,29.25
343
+ 342,TA_15,TA_16,10.0,10.5,4.5,25.0,12.0,6.5,6.0,24.5,24.75
344
+ 343,TA_15,TA_16,17.0,9.5,11.5,38.0,20.5,9.0,0.0,29.5,33.75
345
+ 344,TA_15,TA_16,12.0,7.5,5.0,24.5,11.0,5.0,4.5,20.5,22.5
346
+ 345,TA_15,TA_16,12.0,5.5,5.0,22.5,10.0,5.0,5.0,20.0,21.25
347
+ 346,TA_15,TA_16,7.0,6.0,7.5,20.5,16.0,10.0,13.5,39.5,30.0
348
+ 347,TA_15,TA_16,16.0,10.5,4.5,31.0,14.0,9.5,5.0,28.5,29.75
349
+ 348,TA_15,TA_16,24.0,12.0,19.0,55.0,18.0,9.0,18.0,45.0,50.0
350
+ 349,TA_15,TA_16,13.0,11.0,7.5,31.5,14.5,7.25,12.5,34.25,32.875
351
+ 350,TA_15,TA_16,13.5,7.0,6.5,27.0,18.5,9.5,9.0,37.0,32.0
352
+ 351,TA_15,TA_16,20.0,17.0,17.5,54.5,17.0,16.5,17.5,51.0,52.75
353
+ 352,TA_15,TA_16,14.5,10.0,2.0,26.5,13.0,4.0,6.0,23.0,24.75
354
+ 353,TA_15,TA_16,21.5,15.5,15.0,52.0,19.5,16.0,13.5,49.0,50.5
355
+ 354,TA_15,TA_16,18.5,11.5,9.0,39.0,10.5,11.5,10.5,32.5,35.75
356
+ 355,TA_15,TA_16,12.5,11.5,0.0,24.0,9.0,9.0,0.0,18.0,21.0
357
+ 356,TA_15,TA_16,8.0,9.5,7.5,25.0,10.5,9.5,0.0,20.0,22.5
358
+ 357,TA_17,TA_18,19.0,10.5,12.0,41.5,21.3,11.3,11.0,43.6,42.55
359
+ 358,TA_17,TA_18,6.0,11.5,2.0,19.5,14.3,11.8,2.0,28.1,23.8
360
+ 359,TA_17,TA_18,11.5,13.0,11.0,35.5,12.7,13.3,12.5,38.5,37.0
361
+ 360,TA_17,TA_18,10.0,7.5,4.25,21.75,12.9,9.2,5.0,27.1,24.425
362
+ 361,TA_17,TA_18,3.0,11.0,5.5,19.5,4.2,12.3,5.1,21.6,20.55
363
+ 362,TA_17,TA_18,12.0,11.0,0.0,23.0,11.5,10.5,0.0,22.0,22.5
364
+ 363,TA_17,TA_18,5.0,10.0,0.0,15.0,12.0,10.3,0.0,22.3,18.65
365
+ 364,TA_17,TA_18,1.0,7.0,4.0,12.0,3.2,5.3,5.4,13.9,12.95
366
+ 365,TA_17,TA_18,13.0,12.25,6.25,31.5,19.0,10.8,5.6,35.4,33.45
367
+ 366,TA_17,TA_18,8.0,9.0,3.0,20.0,10.0,9.6,2.3,21.900000000000002,20.950000000000003
368
+ 367,TA_17,TA_18,13.5,12.5,18.0,44.0,15.0,12.0,12.5,39.5,41.75
369
+ 368,TA_17,TA_18,10.0,12.0,11.5,33.5,8.5,13.3,4.3,26.1,29.8
370
+ 369,TA_17,TA_18,3.0,5.5,10.0,18.5,5.0,7.5,10.0,22.5,20.5
371
+ 370,TA_17,TA_18,8.0,10.5,10.0,28.5,8.6,9.9,6.8,25.3,26.9
372
+ 371,TA_17,TA_18,15.0,0.0,14.0,29.0,15.5,0.0,16.0,31.5,30.25
373
+ 372,TA_17,TA_18,9.5,0.0,9.0,18.5,10.0,0.0,8.0,18.0,18.25
374
+ 373,TA_17,TA_18,13.5,0.0,10.5,24.0,11.5,0.0,9.8,21.3,22.65
375
+ 374,TA_17,TA_18,11.0,9.5,9.0,29.5,13.5,10.5,10.0,34.0,31.75
376
+ 375,TA_17,TA_18,10.0,10.0,9.0,29.0,13.0,11.3,10.0,34.3,31.65
377
+ 376,TA_17,TA_18,1.5,7.0,6.0,14.5,5.2,8.1,6.0,19.3,16.9
378
+ 377,TA_17,TA_18,16.0,10.0,0.0,26.0,17.0,7.3,0.0,24.3,25.15
379
+ 378,TA_17,TA_18,0.0,6.5,2.0,8.5,4.0,9.1,2.0,15.1,11.8
380
+ 379,TA_17,TA_18,14.0,0.0,0.0,14.0,14.0,0.0,0.0,14.0,14.0
381
+ 380,TA_17,TA_18,4.0,0.0,1.5,5.5,4.0,0.0,2.0,6.0,5.75
382
+ 381,TA_17,TA_18,7.0,6.0,3.5,16.5,7.0,8.3,3.4,18.7,17.6
383
+ 382,TA_17,TA_18,5.5,8.5,8.0,22.0,6.0,11.8,5.5,23.3,22.65
384
+ 383,TA_17,TA_18,18.0,13.5,11.5,43.0,19.0,16.0,0.0,35.0,39.0
385
+ 384,TA_17,TA_18,11.5,12.5,7.0,31.0,12.6,13.5,8.0,34.1,32.55
386
+ 385,TA_17,TA_18,11.0,14.0,14.5,39.5,12.0,14.0,10.8,36.8,38.15
387
+ 386,TA_17,TA_18,11.0,2.5,10.0,23.5,14.0,3.0,5.8,22.8,23.15
388
+ 387,TA_17,TA_18,13.0,14.5,10.0,37.5,14.2,15.0,7.5,36.7,37.1
389
+ 388,TA_17,TA_18,4.5,4.5,5.0,14.0,7.8,4.8,3.3,15.899999999999999,14.95
390
+ 389,TA_17,TA_18,4.0,8.0,9.0,21.0,6.5,0.0,7.5,14.0,17.5
391
+ 390,TA_17,TA_18,11.5,10.0,2.0,23.5,10.5,9.7,2.0,22.2,22.85
392
+ 391,TA_17,TA_18,11.0,9.5,4.5,25.0,14.0,11.8,5.5,31.3,28.15
393
+ 392,TA_17,TA_18,10.5,12.0,9.5,32.0,12.7,13.0,6.3,32.0,32.0
394
+ 393,TA_17,TA_18,6.5,0.0,8.5,15.0,7.0,0.0,5.5,12.5,13.75
395
+ 394,TA_17,TA_18,10.0,7.0,2.0,19.0,10.5,8.8,2.0,21.3,20.15
396
+ 395,TA_17,TA_18,8.0,11.0,4.0,23.0,7.5,11.5,4.5,23.5,23.25
397
+ 396,TA_17,TA_18,8.5,9.0,2.0,19.5,11.7,12.0,2.2,25.9,22.7
398
+ 397,TA_17,TA_18,9.0,8.0,10.0,27.0,9.3,7.6,8.2,25.099999999999998,26.049999999999997
399
+ 398,TA_17,TA_18,8.0,7.5,4.0,19.5,9.4,7.0,5.0,21.4,20.45
400
+ 399,TA_17,TA_18,13.0,6.0,5.0,24.0,9.0,9.0,5.0,23.0,23.5
401
+ 400,TA_17,TA_18,16.0,14.5,10.5,41.0,17.0,13.0,8.5,38.5,39.75
402
+ 401,TA_17,TA_18,2.5,0.0,0.0,2.5,4.0,0.0,0.0,4.0,3.25
403
+ 402,TA_19,TA_20,15.0,14.0,17.0,46.0,11.0,13.5,15.5,40.0,43.0
404
+ 403,TA_19,TA_20,9.5,9.0,4.0,22.5,11.5,8.5,5.0,25.0,23.75
405
+ 404,TA_19,TA_20,10.5,13.5,18.0,42.0,14.0,14.0,19.0,47.0,44.5
406
+ 405,TA_19,TA_20,13.0,11.5,14.5,39.0,17.0,11.5,14.0,42.5,40.75
407
+ 406,TA_19,TA_20,15.0,13.0,20.5,48.5,18.0,13.5,19.0,50.5,49.5
408
+ 407,TA_19,TA_20,23.5,16.0,19.0,58.5,25.0,12.5,16.0,53.5,56.0
409
+ 408,TA_19,TA_20,7.5,12.5,18.0,38.0,12.0,13.0,15.5,40.5,39.25
410
+ 409,TA_19,TA_20,11.5,10.0,5.5,27.0,11.5,10.5,5.0,27.0,27.0
411
+ 410,TA_19,TA_20,5.5,11.0,2.5,19.0,8.0,13.0,3.5,24.5,21.75
412
+ 411,TA_19,TA_20,15.5,14.5,15.0,45.0,21.0,15.0,15.5,51.5,48.25
413
+ 412,TA_19,TA_20,16.0,0.0,16.0,32.0,16.0,0.0,13.5,29.5,30.75
414
+ 413,TA_19,TA_20,21.0,11.5,17.0,49.5,21.5,13.0,13.0,47.5,48.5
415
+ 414,TA_19,TA_20,13.0,8.0,7.0,28.0,10.0,9.0,6.0,25.0,26.5
416
+ 415,TA_19,TA_20,21.0,17.0,15.5,53.5,25.0,17.0,15.5,57.5,55.5
417
+ 416,TA_19,TA_20,13.0,6.5,5.0,24.5,9.0,9.0,11.0,29.0,26.75
418
+ 417,TA_19,TA_20,19.0,17.0,15.5,51.5,23.0,17.0,17.0,57.0,54.25
419
+ 418,TA_19,TA_20,13.0,8.0,13.0,34.0,14.0,9.0,13.0,36.0,35.0
420
+ 419,TA_19,TA_20,19.0,12.0,9.5,40.5,18.5,12.0,11.0,41.5,41.0
421
+ 420,TA_19,TA_20,22.5,8.0,18.0,48.5,21.5,9.5,18.0,49.0,48.75
422
+ 421,TA_19,TA_20,16.5,9.5,3.0,29.0,16.5,10.0,2.5,29.0,29.0
423
+ 422,TA_19,TA_20,10.0,9.5,0.0,19.5,14.0,9.0,0.0,23.0,21.25
424
+ 423,TA_19,TA_20,13.5,11.5,5.0,30.0,12.0,11.0,1.0,24.0,27.0
425
+ 424,TA_19,TA_20,10.5,6.5,15.0,32.0,10.0,7.5,14.0,31.5,31.75
426
+ 425,TA_19,TA_20,10.0,10.0,6.5,26.5,13.5,9.5,9.5,32.5,29.5
427
+ 426,TA_19,TA_20,7.0,9.0,8.5,24.5,9.0,9.0,7.5,25.5,25.0
428
+ 427,TA_19,TA_20,3.5,8.0,3.0,14.5,1.0,10.0,4.0,15.0,14.75
429
+ 428,TA_19,TA_20,1.0,1.0,0.0,2.0,2.0,4.0,0.0,6.0,4.0
430
+ 429,TA_19,TA_20,10.0,4.0,5.0,19.0,12.5,4.5,6.5,23.5,21.25
431
+ 430,TA_19,TA_20,3.0,4.0,3.0,10.0,3.5,5.5,5.0,14.0,12.0
432
+ 431,TA_19,TA_20,12.5,13.0,17.5,43.0,15.0,13.5,14.5,43.0,43.0
433
+ 432,TA_19,TA_20,3.0,0.5,2.0,5.5,-1.0,1.0,2.0,2.0,3.75
434
+ 433,TA_19,TA_20,10.0,12.5,15.0,37.5,14.0,12.5,13.5,40.0,38.75
435
+ 434,TA_19,TA_20,18.0,16.0,5.5,39.5,21.0,16.5,6.5,44.0,41.75
436
+ 435,TA_19,TA_20,4.0,7.0,1.0,12.0,1.0,4.0,1.0,6.0,9.0
437
+ 436,TA_19,TA_20,20.0,17.0,21.0,58.0,26.0,16.5,22.0,64.5,61.25
438
+ 437,TA_19,TA_20,18.5,12.0,18.0,48.5,19.0,11.5,16.5,47.0,47.75
439
+ 438,TA_19,TA_20,15.0,11.5,19.0,45.5,18.5,12.5,20.0,51.0,48.25
440
+ 439,TA_19,TA_20,20.0,16.5,22.0,58.5,24.0,17.0,22.0,63.0,60.75
441
+ 440,TA_19,TA_20,18.0,0.0,5.5,23.5,19.0,0.0,7.5,26.5,25.0
442
+ 441,TA_19,TA_20,14.0,4.0,14.0,32.0,13.5,4.0,12.5,30.0,31.0
443
+ 442,TA_19,TA_20,17.5,9.5,17.0,44.0,14.0,10.0,15.0,39.0,41.5
444
+ 443,TA_19,TA_20,15.5,9.5,5.0,30.0,12.5,9.0,5.0,26.5,28.25
445
+ 444,TA_19,TA_20,11.0,14.0,9.5,34.5,14.5,14.0,8.5,37.0,35.75
446
+ 445,TA_19,TA_20,15.0,11.0,9.0,35.0,12.0,10.0,10.5,32.5,33.75
447
+ 446,TA_19,TA_20,14.5,11.0,15.5,41.0,18.0,11.5,16.0,45.5,43.25
448
+ 447,TA_19,TA_20,14.5,10.0,3.0,27.5,15.5,11.0,3.5,30.0,28.75
449
+ 448,TA_19,TA_20,7.0,8.5,8.0,23.5,4.0,9.5,7.5,21.0,22.25
450
+ 449,TA_46,TA_22,10.5,0.0,10.0,20.5,10.0,0.0,10.0,20.0,20.25
451
+ 450,TA_49+TA_50,TA_22,14.0,6.5,0.0,20.5,15.0,5.0,0.0,20.0,20.25
452
+ 451,TA_51,TA_22,0.0,6.0,9.0,15.0,1.0,7.0,4.0,12.0,13.5
453
+ 452,TA_47,TA_22,10.5,12.0,3.0,25.5,11.0,13.0,3.0,27.0,26.25
454
+ 453,TA_46,TA_22,16.0,13.0,12.0,41.0,13.0,13.0,10.0,36.0,38.5
455
+ 454,TA_49+TA_50,TA_22,15.0,11.5,8.0,34.5,16.0,12.0,12.0,40.0,37.25
456
+ 455,TA_51,TA_22,14.0,12.0,10.75,36.75,13.0,10.0,12.0,35.0,35.875
457
+ 456,TA_47,TA_22,3.0,10.0,2.0,15.0,2.0,5.0,2.0,9.0,12.0
458
+ 457,TA_46,TA_22,10.0,13.0,4.0,27.0,10.0,11.0,4.0,25.0,26.0
459
+ 458,TA_49+TA_50,TA_22,8.5,6.5,0.0,15.0,8.0,5.0,0.0,13.0,14.0
460
+ 459,TA_51,TA_22,18.0,11.0,15.75,44.75,14.0,7.0,17.0,38.0,41.375
461
+ 460,TA_47,TA_22,11.0,11.0,10.0,32.0,8.0,14.0,11.0,33.0,32.5
462
+ 461,TA_46,TA_22,4.0,2.0,0.0,6.0,9.0,1.0,0.0,10.0,8.0
463
+ 462,TA_49+TA_50,TA_22,21.0,17.0,18.0,56.0,16.0,17.0,19.0,52.0,54.0
464
+ 463,TA_51,TA_22,4.0,12.0,8.75,24.75,6.0,7.0,9.0,22.0,23.375
465
+ 464,TA_47,TA_22,16.0,11.0,18.5,45.5,16.0,13.0,17.0,46.0,45.75
466
+ 465,TA_46,TA_22,13.0,11.5,11.0,35.5,14.0,9.0,11.0,34.0,34.75
467
+ 466,TA_49+TA_50,TA_22,14.0,13.0,9.0,36.0,16.0,11.0,10.0,37.0,36.5
468
+ 467,TA_51,TA_22,16.0,17.0,17.75,50.75,19.0,17.0,16.0,52.0,51.375
469
+ 468,TA_47,TA_22,16.0,7.0,7.0,30.0,16.0,9.0,14.0,39.0,34.5
470
+ 469,TA_46,TA_22,20.0,13.0,11.0,44.0,20.0,14.0,10.0,44.0,44.0
471
+ 470,TA_49+TA_50,TA_22,19.0,17.0,15.0,51.0,19.0,17.0,18.0,54.0,52.5
472
+ 471,TA_51,TA_22,17.0,13.0,14.75,44.75,18.0,8.0,18.0,44.0,44.375
473
+ 472,TA_47,TA_22,2.0,0.0,2.0,4.0,5.0,4.0,6.0,15.0,9.5
474
+ 473,TA_46,TA_22,16.5,14.0,14.0,44.5,17.0,14.0,17.0,48.0,46.25
475
+ 474,TA_49+TA_50,TA_22,14.0,14.0,1.0,29.0,14.0,10.0,4.0,28.0,28.5
476
+ 475,TA_51,TA_22,12.0,9.0,9.5,30.5,18.0,8.0,12.0,38.0,34.25
477
+ 476,TA_47,TA_22,0.0,7.0,4.0,11.0,3.0,5.0,5.0,13.0,12.0
478
+ 477,TA_46,TA_22,7.0,11.5,10.0,28.5,5.0,6.0,13.0,24.0,26.25
479
+ 478,TA_49+TA_50,TA_22,24.0,17.0,17.0,58.0,21.0,16.0,20.0,57.0,57.5
480
+ 479,TA_51,TA_22,9.0,0.0,5.5,14.5,7.0,0.0,8.0,15.0,14.75
481
+ 480,TA_47,TA_22,0.0,0.0,11.0,11.0,0.0,0.0,13.0,13.0,12.0
482
+ 481,TA_46,TA_22,7.0,1.0,3.0,11.0,10.0,0.0,4.0,14.0,12.5
483
+ 482,TA_49+TA_50,TA_22,5.0,4.75,2.0,11.75,7.0,2.0,4.0,13.0,12.375
484
+ 483,TA_51,TA_22,12.0,11.0,6.75,29.75,10.0,11.0,7.0,28.0,28.875
485
+ 484,TA_47,TA_22,16.0,17.0,12.0,45.0,18.0,17.0,17.0,52.0,48.5
486
+ 485,TA_46,TA_22,5.0,10.5,0.0,15.5,4.0,5.0,0.0,9.0,12.25
487
+ 486,TA_49+TA_50,TA_22,9.0,17.0,7.0,33.0,7.0,17.0,10.0,34.0,33.5
488
+ 487,TA_51,TA_22,5.0,14.0,2.5,21.5,11.0,12.0,2.0,25.0,23.25
489
+ 488,TA_47,TA_22,16.0,10.0,13.5,39.5,18.0,10.0,15.0,43.0,41.25
490
+ 489,TA_46,TA_22,4.0,3.0,5.0,12.0,8.0,3.0,5.0,16.0,14.0
491
+ 490,TA_49+TA_50,TA_22,14.0,13.0,8.5,35.5,12.0,12.0,11.0,35.0,35.25
492
+ 491,TA_51,TA_22,14.0,13.0,12.75,39.75,12.0,12.0,14.0,38.0,38.875
493
+ 492,TA_47,TA_22,10.0,9.0,9.5,28.5,11.0,10.0,13.0,34.0,31.25
494
+ 493,TA_46,TA_22,16.0,14.0,10.0,40.0,15.0,11.0,12.0,38.0,39.0
495
+ 494,TA_49+TA_50,TA_22,5.0,0.25,3.0,8.25,5.0,2.0,5.0,12.0,10.125
496
+ 495,TA_51,TA_22,10.0,0.0,8.75,18.75,12.0,0.0,10.0,22.0,20.375
497
+ 496,TA_47,TA_22,16.0,13.0,18.5,47.5,13.0,14.0,20.0,47.0,47.25
498
+ 497,TA_23,TA_24,12.0,11.0,4.0,27.0,8.0,11.0,4.0,23.0,25.0
499
+ 498,TA_23,TA_24,5.0,11.0,6.0,22.0,6.0,9.0,5.0,20.0,21.0
500
+ 499,TA_23,TA_24,4.5,11.0,11.0,26.5,14.0,13.0,11.0,38.0,32.25
501
+ 500,TA_23,TA_24,10.0,10.0,5.0,25.0,12.0,13.0,11.0,36.0,30.5
502
+ 501,TA_23,TA_24,15.0,10.0,3.0,28.0,2.0,11.0,3.0,16.0,22.0
503
+ 502,TA_23,TA_24,12.0,10.0,13.0,35.0,12.0,10.0,13.0,35.0,35.0
504
+ 503,TA_23,TA_24,12.0,10.0,8.0,30.0,8.0,11.0,6.0,25.0,27.5
505
+ 504,TA_23,TA_24,7.0,7.0,3.0,17.0,2.0,8.0,3.0,13.0,15.0
506
+ 505,TA_23,TA_24,5.0,12.0,10.0,27.0,5.0,13.0,10.0,28.0,27.5
507
+ 506,TA_23,TA_24,13.0,14.0,13.0,40.0,15.0,15.0,14.0,44.0,42.0
508
+ 507,TA_23,TA_24,18.0,14.0,9.0,41.0,15.0,14.0,9.0,38.0,39.5
509
+ 508,TA_23,TA_24,2.0,2.0,6.0,10.0,3.0,2.0,5.0,10.0,10.0
510
+ 509,TA_23,TA_24,11.0,12.0,7.0,30.0,11.0,6.0,6.0,23.0,26.5
511
+ 510,TA_23,TA_24,10.0,10.0,11.0,31.0,9.0,13.0,11.0,33.0,32.0
512
+ 511,TA_23,TA_24,4.0,11.0,6.0,21.0,10.0,10.0,9.0,29.0,25.0
513
+ 512,TA_23,TA_24,14.0,14.0,8.0,36.0,9.0,14.0,13.0,36.0,36.0
514
+ 513,TA_23,TA_24,22.0,17.0,18.0,57.0,23.0,16.0,24.0,63.0,60.0
515
+ 514,TA_23,TA_24,7.0,8.0,9.0,24.0,10.0,0.0,8.0,18.0,21.0
516
+ 515,TA_23,TA_24,19.0,17.0,25.0,61.0,17.0,13.0,22.0,52.0,56.5
517
+ 516,TA_23,TA_24,18.0,17.0,17.0,52.0,18.0,16.0,18.0,52.0,52.0
518
+ 517,TA_23,TA_24,13.5,12.0,12.0,37.5,16.0,8.0,18.0,42.0,39.75
519
+ 518,TA_23,TA_24,9.0,10.0,12.0,31.0,8.0,14.0,17.0,39.0,35.0
520
+ 519,TA_23,TA_24,18.0,7.0,0.0,25.0,1.0,3.0,4.0,8.0,16.5
521
+ 520,TA_23,TA_24,16.0,17.0,12.0,45.0,17.5,16.0,14.0,47.5,46.25
522
+ 521,TA_23,TA_24,18.0,12.0,2.0,32.0,14.0,11.0,10.0,35.0,33.5
523
+ 522,TA_23,TA_24,15.0,17.0,15.0,47.0,14.0,12.0,10.0,36.0,41.5
524
+ 523,TA_23,TA_24,7.0,10.0,7.0,24.0,8.0,11.0,14.0,33.0,28.5
525
+ 524,TA_23,TA_24,7.0,11.0,11.0,29.0,4.0,9.0,11.0,24.0,26.5
526
+ 525,TA_23,TA_24,7.0,8.0,5.0,20.0,2.5,3.0,2.0,7.5,13.75
527
+ 526,TA_23,TA_24,13.0,12.0,9.0,34.0,14.0,12.0,8.0,34.0,34.0
528
+ 527,TA_23,TA_24,11.0,10.0,7.0,28.0,11.0,14.0,12.0,37.0,32.5
529
+ 528,TA_23,TA_24,8.0,8.0,10.0,26.0,9.0,6.0,6.0,21.0,23.5
530
+ 529,TA_23,TA_24,21.0,17.0,22.0,60.0,18.0,15.0,23.0,56.0,58.0
531
+ 530,TA_23,TA_24,20.0,13.0,19.0,52.0,18.0,15.0,19.0,52.0,52.0
532
+ 531,TA_23,TA_24,7.0,13.0,10.0,30.0,4.0,14.0,10.0,28.0,29.0
533
+ 532,TA_23,TA_24,11.0,12.0,0.0,23.0,14.0,12.0,0.0,26.0,24.5
534
+ 533,TA_23,TA_24,13.0,5.0,3.0,21.0,9.0,7.0,3.0,19.0,20.0
535
+ 534,TA_23,TA_24,9.0,11.0,8.0,28.0,7.0,11.0,9.0,27.0,27.5
536
+ 535,TA_23,TA_24,7.0,9.0,8.0,24.0,5.0,9.0,9.0,23.0,23.5
537
+ 536,TA_23,TA_24,14.0,11.0,3.0,28.0,8.0,11.0,2.0,21.0,24.5
538
+ 537,TA_23,TA_24,7.0,6.0,11.0,24.0,5.0,8.0,5.0,18.0,21.0
539
+ 538,TA_23,TA_24,15.0,11.0,16.0,42.0,11.0,11.0,17.0,39.0,40.5
540
+ 539,TA_23,TA_24,13.0,14.0,8.0,35.0,0.0,0.0,6.0,6.0,20.5
541
+ 540,TA_23,TA_24,11.0,9.0,8.0,28.0,10.0,10.0,9.0,29.0,28.5
542
+ 541,TA_23,TA_24,6.0,11.0,6.0,23.0,3.0,9.0,7.0,19.0,21.0
543
+ 542,TA_23,TA_24,10.0,8.0,6.0,24.0,12.0,0.0,4.0,16.0,20.0
544
+ 543,TA_23,TA_24,7.0,3.0,0.0,10.0,8.5,13.0,7.0,28.5,19.25
545
+ 544,TA_23,TA_24,12.0,13.0,4.0,29.0,5.0,9.0,8.0,22.0,25.5
546
+ 545,TA_25,TA_26,23.0,13.5,3.5,40.0,20.0,11.5,6.25,37.75,38.875
547
+ 546,TA_25,TA_26,19.0,14.0,9.5,42.5,18.0,13.0,11.0,42.0,42.25
548
+ 547,TA_25,TA_26,0.0,1.0,2.5,3.5,0.0,0.0,2.5,2.5,3.0
549
+ 548,TA_25,TA_26,9.0,1.0,2.0,12.0,4.0,1.0,2.0,7.0,9.5
550
+ 549,TA_25,TA_26,3.0,0.0,4.0,7.0,4.5,0.0,6.0,10.5,8.75
551
+ 550,TA_25,TA_26,5.0,10.0,13.0,28.0,14.0,9.5,11.0,34.5,31.25
552
+ 551,TA_25,TA_26,1.0,8.0,2.5,11.5,0.0,3.0,0.0,3.0,7.25
553
+ 552,TA_25,TA_26,13.5,13.0,14.0,40.5,13.5,14.0,13.5,41.0,40.75
554
+ 553,TA_25,TA_26,12.5,11.0,5.0,28.5,3.25,8.0,5.5,16.75,22.625
555
+ 554,TA_25,TA_26,8.0,2.0,0.0,10.0,9.0,2.5,0.0,11.5,10.75
556
+ 555,TA_25,TA_26,13.0,8.0,13.5,34.5,10.5,4.0,15.0,29.5,32.0
557
+ 556,TA_25,TA_26,16.0,9.0,2.0,27.0,16.5,5.5,2.0,24.0,25.5
558
+ 557,TA_25,TA_26,17.5,17.0,6.0,40.5,18.5,17.0,6.0,41.5,41.0
559
+ 558,TA_25,TA_26,19.0,10.0,17.0,46.0,17.5,11.0,16.0,44.5,45.25
560
+ 559,TA_25,TA_26,13.0,12.5,6.0,31.5,11.0,11.5,6.0,28.5,30.0
561
+ 560,TA_25,TA_26,20.0,0.0,20.0,40.0,18.0,0.0,21.5,39.5,39.75
562
+ 561,TA_25,TA_26,18.0,14.0,11.0,43.0,18.0,14.0,9.0,41.0,42.0
563
+ 562,TA_25,TA_26,19.5,12.5,19.0,51.0,19.0,12.5,18.5,50.0,50.5
564
+ 563,TA_25,TA_26,20.0,17.0,20.0,57.0,17.5,17.0,22.0,56.5,56.75
565
+ 564,TA_25,TA_26,14.0,9.0,8.0,31.0,6.0,8.5,6.5,21.0,26.0
566
+ 565,TA_25,TA_26,17.0,14.0,18.0,49.0,19.0,17.0,19.0,55.0,52.0
567
+ 566,TA_25,TA_26,12.5,9.0,3.5,25.0,7.0,6.0,3.75,16.75,20.875
568
+ 567,TA_25,TA_26,14.0,14.0,15.5,43.5,12.5,15.0,16.0,43.5,43.5
569
+ 568,TA_25,TA_26,11.5,11.0,8.0,30.5,10.5,11.0,6.0,27.5,29.0
570
+ 569,TA_25,TA_26,17.0,14.5,17.5,49.0,18.0,13.5,17.0,48.5,48.75
571
+ 570,TA_25,TA_26,15.0,15.0,12.0,42.0,16.0,15.5,11.5,43.0,42.5
572
+ 571,TA_25,TA_26,7.5,1.0,8.0,16.5,8.25,1.5,5.0,14.75,15.625
573
+ 572,TA_25,TA_26,18.0,15.0,0.0,33.0,23.0,17.0,0.0,40.0,36.5
574
+ 573,TA_25,TA_26,11.0,15.0,0.0,26.0,14.0,13.0,0.0,27.0,26.5
575
+ 574,TA_25,TA_26,16.5,17.0,20.0,53.5,16.5,17.0,20.5,54.0,53.75
576
+ 575,TA_25,TA_26,19.0,13.0,11.0,43.0,18.5,14.0,12.5,45.0,44.0
577
+ 576,TA_25,TA_26,18.0,11.0,8.0,37.0,20.5,12.25,12.0,44.75,40.875
578
+ 577,TA_25,TA_26,18.5,14.0,21.0,53.5,22.5,17.0,22.0,61.5,57.5
579
+ 578,TA_25,TA_26,13.5,13.0,10.0,36.5,17.0,13.0,10.0,40.0,38.25
580
+ 579,TA_25,TA_26,16.0,11.5,4.0,31.5,18.5,12.0,2.0,32.5,32.0
581
+ 580,TA_25,TA_26,18.0,14.0,11.5,43.5,18.0,15.0,14.0,47.0,45.25
582
+ 581,TA_25,TA_26,7.1,1.0,5.0,13.1,6.0,0.0,3.0,9.0,11.05
583
+ 582,TA_25,TA_26,24.0,14.0,20.0,58.0,22.5,14.0,20.0,56.5,57.25
584
+ 583,TA_25,TA_26,10.5,3.5,7.0,21.0,5.0,7.5,6.5,19.0,20.0
585
+ 584,TA_25,TA_26,14.5,12.5,17.0,44.0,17.0,13.0,19.5,49.5,46.75
586
+ 585,TA_25,TA_26,8.0,4.0,18.0,30.0,6.5,4.0,12.0,22.5,26.25
587
+ 586,TA_25,TA_26,12.5,11.0,7.0,30.5,16.5,10.0,8.5,35.0,32.75
588
+ 587,TA_25,TA_26,16.0,12.0,17.0,45.0,16.5,12.5,15.0,44.0,44.5
589
+ 588,TA_25,TA_26,5.5,11.0,7.0,23.5,4.75,9.5,7.5,21.75,22.625
590
+ 589,TA_25,TA_26,21.0,14.0,19.0,54.0,26.0,15.5,19.0,60.5,57.25
591
+ 590,TA_25,TA_26,11.0,12.0,5.0,28.0,10.5,9.0,4.0,23.5,25.75
592
+ 591,TA_25,TA_26,17.0,16.0,21.0,54.0,15.5,16.25,22.0,53.75,53.875
593
+ 592,TA_25,TA_26,17.0,14.0,19.5,50.5,17.5,17.0,19.5,54.0,52.25
594
+ 593,TA_25,TA_26,13.0,14.0,17.0,44.0,17.0,14.0,18.5,49.5,46.75
595
+ 594,TA_25,TA_26,16.5,10.5,15.0,42.0,14.0,10.5,16.0,40.5,41.25
596
+ 595,TA_25,TA_26,17.0,12.0,13.5,42.5,16.0,14.0,14.5,44.5,43.5
597
+ 596,TA_27,TA_28,6.0,0.0,4.0,10.0,9.0,0.0,6.0,15.0,12.5
598
+ 597,TA_27,TA_28,2.0,0.0,0.0,2.0,5.0,0.0,0.0,5.0,3.5
599
+ 598,TA_27,TA_28,6.5,11.0,9.5,27.0,10.0,11.0,12.0,33.0,30.0
600
+ 599,TA_27,TA_28,23.0,13.0,9.5,45.5,23.0,13.0,9.0,45.0,45.25
601
+ 600,TA_27,TA_28,13.0,8.5,12.0,33.5,14.5,11.5,13.5,39.5,36.5
602
+ 601,TA_27,TA_28,13.5,0.0,0.0,13.5,17.0,1.5,0.0,18.5,16.0
603
+ 602,TA_27,TA_28,7.5,6.5,5.0,19.0,9.5,9.5,4.0,23.0,21.0
604
+ 603,TA_27,TA_28,20.0,11.5,6.5,38.0,21.0,13.0,14.0,48.0,43.0
605
+ 604,TA_27,TA_28,13.0,10.0,0.0,23.0,13.5,12.0,0.0,25.5,24.25
606
+ 605,TA_27,TA_28,12.0,11.5,0.0,23.5,12.5,16.0,0.0,28.5,26.0
607
+ 606,TA_27,TA_28,3.5,2.5,2.0,8.0,7.5,7.0,6.5,21.0,14.5
608
+ 607,TA_27,TA_28,15.0,11.0,11.0,37.0,20.0,13.5,15.0,48.5,42.75
609
+ 608,TA_27,TA_28,10.0,0.0,8.0,18.0,10.0,2.5,10.0,22.5,20.25
610
+ 609,TA_27,TA_28,14.0,7.5,8.0,29.5,14.0,11.5,10.0,35.5,32.5
611
+ 610,TA_27,TA_28,8.0,9.5,3.0,20.5,14.0,11.0,4.5,29.5,25.0
612
+ 611,TA_27,TA_28,8.0,7.5,5.0,20.5,12.5,11.0,5.5,29.0,24.75
613
+ 612,TA_27,TA_28,8.5,10.0,14.0,32.5,9.0,12.5,16.5,38.0,35.25
614
+ 613,TA_27,TA_28,17.5,15.0,22.0,54.5,17.5,15.0,22.0,54.5,54.5
615
+ 614,TA_27,TA_28,13.0,10.0,17.5,40.5,17.5,13.5,18.5,49.5,45.0
616
+ 615,TA_27,TA_28,14.0,0.0,3.0,17.0,16.5,0.0,3.0,19.5,18.25
617
+ 616,TA_27,TA_28,13.5,17.0,0.0,30.5,15.0,17.0,0.0,32.0,31.25
618
+ 617,TA_27,TA_28,8.0,14.0,8.0,30.0,11.5,14.0,9.0,34.5,32.25
619
+ 618,TA_27,TA_28,15.0,10.5,9.0,34.5,16.0,13.0,17.0,46.0,40.25
620
+ 619,TA_27,TA_28,19.0,17.0,19.0,55.0,19.5,17.0,20.0,56.5,55.75
621
+ 620,TA_27,TA_28,7.5,8.0,8.0,23.5,15.0,11.0,9.0,35.0,29.25
622
+ 621,TA_27,TA_28,8.5,10.5,18.0,37.0,11.5,12.5,15.0,39.0,38.0
623
+ 622,TA_27,TA_28,18.5,14.5,16.0,49.0,19.0,17.0,20.0,56.0,52.5
624
+ 623,TA_27,TA_28,9.0,8.0,5.5,22.5,9.5,11.0,10.0,30.5,26.5
625
+ 624,TA_27,TA_28,11.5,10.0,4.0,25.5,12.5,11.5,9.5,33.5,29.5
626
+ 625,TA_27,TA_28,14.0,7.5,15.5,37.0,22.0,11.5,17.0,50.5,43.75
627
+ 626,TA_27,TA_28,17.5,3.0,0.0,20.5,20.0,3.0,0.0,23.0,21.75
628
+ 627,TA_27,TA_28,10.0,11.5,6.0,27.5,14.5,12.5,7.5,34.5,31.0
629
+ 628,TA_27,TA_28,10.0,8.5,3.0,21.5,14.0,11.5,4.5,30.0,25.75
630
+ 629,TA_27,TA_28,7.5,6.0,8.0,21.5,13.5,9.0,13.5,36.0,28.75
631
+ 630,TA_27,TA_28,1.5,0.0,0.0,1.5,1.5,0.0,0.0,1.5,1.5
632
+ 631,TA_27,TA_28,13.5,6.5,0.0,20.0,17.0,11.0,0.0,28.0,24.0
633
+ 632,TA_27,TA_28,9.0,10.5,10.5,30.0,10.0,12.0,12.0,34.0,32.0
634
+ 633,TA_27,TA_28,17.5,10.0,15.0,42.5,18.0,11.0,15.0,44.0,43.25
635
+ 634,TA_27,TA_28,0.0,0.0,0.0,0.0,14.5,16.0,20.5,51.0,25.5
636
+ 635,TA_27,TA_28,8.0,4.5,4.5,17.0,11.0,10.0,7.0,28.0,22.5
637
+ 636,TA_27,TA_28,18.5,17.0,18.0,53.5,22.5,17.0,20.0,59.5,56.5
638
+ 637,TA_27,TA_28,20.5,10.5,18.0,49.0,21.5,10.5,18.0,50.0,49.5
639
+ 638,TA_27,TA_28,20.0,12.0,17.0,49.0,20.5,12.5,17.5,50.5,49.75
640
+ 639,TA_27,TA_28,13.5,12.5,18.5,44.5,14.0,12.5,20.0,46.5,45.5
641
+ 640,TA_27,TA_28,15.5,7.0,13.5,36.0,17.0,11.5,16.5,45.0,40.5
642
+ 641,TA_27,TA_28,12.0,16.0,18.5,46.5,13.5,16.5,19.0,49.0,47.75
643
+ 642,TA_27,TA_28,10.0,8.5,15.5,34.0,18.0,13.5,18.0,49.5,41.75
644
+ 643,TA_27,TA_28,21.5,14.0,17.0,52.5,22.0,14.0,18.0,54.0,53.25
645
+ 644,TA_46,TA_30,9.0,7.5,4.0,20.5,8.5,9.5,4.5,22.5,21.5
646
+ 645,TA_49+TA_50,TA_30,18.0,0.0,0.0,18.0,18.0,0.0,2.5,20.5,19.25
647
+ 646,TA_51,TA_30,15.0,13.0,7.75,35.75,15.0,10.5,7.5,33.0,34.375
648
+ 647,TA_47,TA_30,17.5,12.0,3.0,32.5,18.0,14.0,3.0,35.0,33.75
649
+ 648,TA_46,TA_30,17.5,12.5,13.0,43.0,18.5,8.5,17.5,44.5,43.75
650
+ 649,TA_49+TA_50,TA_30,3.6,4.0,0.0,7.6,2.5,8.5,0.0,11.0,9.3
651
+ 650,TA_51,TA_30,12.0,9.0,9.5,30.5,12.0,10.0,9.5,31.5,31.0
652
+ 651,TA_47,TA_30,24.0,17.0,21.5,62.5,24.0,16.0,21.5,61.5,62.0
653
+ 652,TA_46,TA_30,20.0,17.0,16.0,53.0,18.5,16.5,16.5,51.5,52.25
654
+ 653,TA_49+TA_50,TA_30,15.0,13.5,1.0,29.5,19.0,12.0,4.5,35.5,32.5
655
+ 654,TA_51,TA_30,15.0,10.0,0.0,25.0,14.5,7.5,0.0,22.0,23.5
656
+ 655,TA_47,TA_30,17.5,13.0,3.0,33.5,17.0,11.5,12.0,40.5,37.0
657
+ 656,TA_46,TA_30,11.0,14.0,5.0,30.0,16.0,14.0,4.5,34.5,32.25
658
+ 657,TA_49+TA_50,TA_30,15.0,11.0,2.0,28.0,15.0,8.75,6.0,29.75,28.875
659
+ 658,TA_51,TA_30,6.0,8.0,6.75,20.75,6.5,11.0,8.5,26.0,23.375
660
+ 659,TA_47,TA_30,9.0,8.0,9.0,26.0,13.0,15.5,10.5,39.0,32.5
661
+ 660,TA_46,TA_30,16.5,13.0,5.0,34.5,16.5,12.5,6.0,35.0,34.75
662
+ 661,TA_49+TA_50,TA_30,5.5,9.0,8.0,22.5,11.5,9.5,12.0,33.0,27.75
663
+ 662,TA_51,TA_30,16.0,8.0,13.0,37.0,17.0,10.5,12.5,40.0,38.5
664
+ 663,TA_47,TA_30,15.0,11.0,19.0,45.0,17.0,14.5,19.75,51.25,48.125
665
+ 664,TA_46,TA_30,19.0,9.0,12.0,40.0,18.5,10.0,13.0,41.5,40.75
666
+ 665,TA_49+TA_50,TA_30,13.0,11.0,3.0,27.0,11.5,11.5,7.0,30.0,28.5
667
+ 666,TA_51,TA_30,12.0,14.0,9.5,35.5,16.5,13.5,13.0,43.0,39.25
668
+ 667,TA_47,TA_30,2.0,0.0,3.0,5.0,2.5,0.5,4.0,7.0,6.0
669
+ 668,TA_46,TA_30,10.0,0.0,0.0,10.0,8.0,0.0,0.0,8.0,9.0
670
+ 669,TA_48,TA_30,17.0,10.0,8.0,35.0,15.5,10.5,10.0,36.0,35.5
671
+ 670,TA_51,TA_30,19.5,11.0,13.0,43.5,22.0,16.0,12.0,50.0,46.75
672
+ 671,TA_47,TA_30,12.0,14.0,18.5,44.5,13.0,14.0,20.5,47.5,46.0
673
+ 672,TA_46,TA_30,21.0,14.0,9.0,44.0,21.0,13.0,12.0,46.0,45.0
674
+ 673,TA_48,TA_30,6.0,9.0,4.0,19.0,10.0,11.5,4.0,25.5,22.25
675
+ 674,TA_51,TA_30,5.0,13.0,12.0,30.0,15.5,11.5,13.0,40.0,35.0
676
+ 675,TA_47,TA_30,12.5,17.0,16.5,46.0,13.75,16.5,18.25,48.5,47.25
677
+ 676,TA_46,TA_30,14.0,14.0,15.0,43.0,18.0,13.5,15.5,47.0,45.0
678
+ 677,TA_48,TA_30,4.0,9.0,0.0,13.0,9.0,12.0,0.0,21.0,17.0
679
+ 678,TA_51,TA_30,7.0,0.0,0.0,7.0,9.0,0.0,0.0,9.0,8.0
680
+ 679,TA_47,TA_30,10.0,11.0,0.0,21.0,9.5,14.0,0.0,23.5,22.25
681
+ 680,TA_46,TA_30,8.0,12.5,6.0,26.5,9.0,13.5,9.0,31.5,29.0
682
+ 681,TA_48,TA_30,9.5,7.0,2.0,18.5,13.5,12.0,2.0,27.5,23.0
683
+ 682,TA_51,TA_30,2.0,10.0,7.5,19.5,7.5,14.5,11.5,33.5,26.5
684
+ 683,TA_47,TA_30,15.0,15.0,15.0,45.0,15.0,15.0,17.3,47.3,46.15
685
+ 684,TA_46,TA_30,7.0,13.0,14.0,34.0,10.0,11.5,13.0,34.5,34.25
686
+ 685,TA_48,TA_30,3.5,0.0,4.0,7.5,5.75,0.5,4.75,11.0,9.25
687
+ 686,TA_51,TA_30,22.5,12.0,20.5,55.0,25.0,12.5,21.0,58.5,56.75
688
+ 687,TA_47,TA_30,6.0,14.0,6.0,26.0,7.0,13.0,6.0,26.0,26.0
689
+ 688,TA_46,TA_30,12.0,14.0,6.0,32.0,18.5,13.5,6.0,38.0,35.0
690
+ 689,TA_48,TA_30,16.0,10.0,18.0,44.0,17.5,12.0,16.5,46.0,45.0
691
+ 690,TA_51,TA_30,20.0,12.0,22.0,54.0,18.0,11.5,22.0,51.5,52.75
692
+ 691,TA_47,TA_30,13.0,8.0,13.5,34.5,11.0,10.0,13.0,34.0,34.25
693
+ 692,TA_46,TA_30,19.0,14.0,15.0,48.0,22.5,11.0,12.5,46.0,47.0
694
+ 693,TA_48,TA_30,4.0,4.0,4.0,12.0,5.0,12.5,8.0,25.5,18.75
695
+ 694,TA_31,TA_32,20.0,13.5,12.0,45.5,19.5,14.0,14.0,47.5,46.5
696
+ 695,TA_31,TA_32,3.0,0.0,6.0,9.0,10.0,0.5,7.0,17.5,13.25
697
+ 696,TA_31,TA_32,9.5,7.0,5.0,21.5,10.5,10.5,6.5,27.5,24.5
698
+ 697,TA_31,TA_32,5.5,0.0,7.0,12.5,9.0,0.0,11.0,20.0,16.25
699
+ 698,TA_31,TA_32,12.0,12.5,14.0,38.5,13.5,13.0,16.0,42.5,40.5
700
+ 699,TA_31,TA_32,15.0,8.0,15.5,38.5,13.0,11.5,16.0,40.5,39.5
701
+ 700,TA_31,TA_32,4.0,8.5,8.0,20.5,8.0,12.5,13.5,34.0,27.25
702
+ 701,TA_31,TA_32,8.0,16.0,14.0,38.0,8.0,17.0,17.0,42.0,40.0
703
+ 702,TA_31,TA_32,13.0,9.0,14.5,36.5,14.0,12.0,15.0,41.0,38.75
704
+ 703,TA_31,TA_32,14.0,9.5,7.5,31.0,16.5,13.0,11.5,41.0,36.0
705
+ 704,TA_31,TA_32,11.0,8.0,2.0,21.0,15.0,10.5,2.0,27.5,24.25
706
+ 705,TA_31,TA_32,0.5,0.0,0.0,0.5,1.0,0.0,0.0,1.0,0.75
707
+ 706,TA_31,TA_32,22.0,17.0,18.0,57.0,22.5,17.0,18.5,58.0,57.5
708
+ 707,TA_31,TA_32,7.0,6.0,10.5,23.5,14.0,12.5,15.5,42.0,32.75
709
+ 708,TA_31,TA_32,16.0,14.0,9.0,39.0,16.0,14.0,10.5,40.5,39.75
710
+ 709,TA_31,TA_32,8.5,6.0,2.0,16.5,13.5,9.5,3.0,26.0,21.25
711
+ 710,TA_31,TA_32,14.5,9.5,7.5,31.5,18.0,11.5,13.5,43.0,37.25
712
+ 711,TA_31,TA_32,12.0,7.5,0.5,20.0,13.0,12.0,0.0,25.0,22.5
713
+ 712,TA_31,TA_32,9.0,1.0,5.0,15.0,12.0,2.0,10.0,24.0,19.5
714
+ 713,TA_31,TA_32,5.5,6.0,3.0,14.5,8.0,8.0,6.0,22.0,18.25
715
+ 714,TA_31,TA_32,13.0,7.5,12.0,32.5,13.0,10.0,15.0,38.0,35.25
716
+ 715,TA_31,TA_33,3.0,4.0,5.0,12.0,2.0,6.0,5.0,13.0,12.5
717
+ 716,TA_31,TA_32,8.0,1.0,7.5,16.5,13.5,1.5,13.5,28.5,22.5
718
+ 717,TA_31,TA_32,11.0,8.0,13.0,32.0,12.0,13.0,16.5,41.5,36.75
719
+ 718,TA_31,TA_32,13.0,8.5,10.0,31.5,15.0,10.5,14.0,39.5,35.5
720
+ 719,TA_31,TA_33,16.5,9.0,12.0,37.5,17.5,16.0,11.0,44.5,41.0
721
+ 720,TA_31,TA_32,8.0,10.0,11.5,29.5,12.0,13.0,13.0,38.0,33.75
722
+ 721,TA_31,TA_32,5.0,5.0,5.0,15.0,8.0,7.5,5.5,21.0,18.0
723
+ 722,TA_31,TA_32,8.5,0.0,4.0,12.5,10.5,0.0,6.0,16.5,14.5
724
+ 723,TA_31,TA_32,9.5,13.0,8.0,30.5,10.0,13.5,12.0,35.5,33.0
725
+ 724,TA_31,TA_32,6.0,2.0,5.0,13.0,9.0,1.5,9.0,19.5,16.25
726
+ 725,TA_31,TA_32,10.0,0.0,6.5,16.5,11.5,0.0,11.0,22.5,19.5
727
+ 726,TA_31,TA_32,12.0,9.0,9.5,30.5,12.0,11.0,12.5,35.5,33.0
728
+ 727,TA_31,TA_32,11.0,11.5,7.5,30.0,15.0,13.5,11.0,39.5,34.75
729
+ 728,TA_31,TA_32,5.0,7.5,2.0,14.5,7.0,10.5,4.5,22.0,18.25
730
+ 729,TA_31,TA_32,6.0,10.0,10.0,26.0,8.0,13.0,13.0,34.0,30.0
731
+ 730,TA_31,TA_32,20.0,10.0,11.0,41.0,20.0,12.0,13.5,45.5,43.25
732
+ 731,TA_31,TA_32,19.0,11.5,13.0,43.5,17.0,15.0,15.0,47.0,45.25
733
+ 732,TA_31,TA_32,8.0,5.0,3.0,16.0,9.5,7.5,5.0,22.0,19.0
734
+ 733,TA_31,TA_32,15.5,14.0,11.0,40.5,14.5,14.0,15.0,43.5,42.0
735
+ 734,TA_31,TA_32,13.0,10.0,8.5,31.5,15.0,15.0,11.5,41.5,36.5
736
+ 735,TA_31,TA_32,18.0,12.0,15.0,45.0,17.5,14.0,17.0,48.5,46.75
737
+ 736,TA_31,TA_32,5.0,10.0,7.0,22.0,8.0,12.5,8.0,28.5,25.25
738
+ 737,TA_31,TA_32,3.5,3.0,1.5,8.0,1.5,7.5,3.0,12.0,10.0
739
+ 738,TA_31,TA_32,19.0,10.0,15.0,44.0,19.5,11.5,14.0,45.0,44.5
740
+ 739,TA_31,TA_32,4.0,5.0,4.5,13.5,6.5,10.5,5.5,22.5,18.0
741
+ 740,TA_31,TA_32,4.0,8.0,5.0,17.0,5.5,12.0,9.0,26.5,21.75
742
+ 741,TA_34,TA_35,0.0,0.0,8.5,8.5,0.0,0.0,10.0,10.0,9.25
743
+ 742,TA_34,TA_35,17.0,13.0,18.0,48.0,7.0,8.5,13.5,29.0,38.5
744
+ 743,TA_34,TA_35,26.0,16.0,14.5,56.5,21.0,14.0,3.0,38.0,47.25
745
+ 744,TA_34,TA_33,4.0,3.0,4.0,11.0,6.0,5.0,5.0,16.0,13.5
746
+ 745,TA_34,TA_35,10.0,10.0,12.0,32.0,9.75,11.5,10.0,31.25,31.625
747
+ 746,TA_34,TA_35,10.5,7.5,6.5,24.5,12.0,10.0,15.0,37.0,30.75
748
+ 747,TA_34,TA_35,16.5,9.5,11.5,37.5,17.0,11.5,9.5,38.0,37.75
749
+ 748,TA_34,TA_35,22.5,9.5,13.5,45.5,15.5,13.5,11.5,40.5,43.0
750
+ 749,TA_34,TA_35,12.5,7.5,9.5,29.5,5.0,9.5,3.5,18.0,23.75
751
+ 750,TA_34,TA_35,28.0,16.0,20.0,64.0,15.0,12.5,13.5,41.0,52.5
752
+ 751,TA_34,TA_35,14.5,7.5,13.5,35.5,20.0,14.0,18.0,52.0,43.75
753
+ 752,TA_34,TA_35,21.0,16.0,14.5,51.5,15.0,14.0,7.0,36.0,43.75
754
+ 753,TA_34,TA_35,27.0,16.0,22.0,65.0,20.0,13.0,18.0,51.0,58.0
755
+ 754,TA_34,TA_35,14.0,0.0,10.0,24.0,7.0,0.0,11.0,18.0,21.0
756
+ 755,TA_34,TA_35,20.0,8.0,10.0,38.0,19.0,13.0,8.0,40.0,39.0
757
+ 756,TA_34,TA_35,20.0,5.5,11.5,37.0,14.0,9.0,13.0,36.0,36.5
758
+ 757,TA_34,TA_33,12.5,6.0,9.5,28.0,12.0,12.0,9.5,33.5,30.75
759
+ 758,TA_34,TA_35,15.0,7.5,12.5,35.0,5.5,3.5,8.5,17.5,26.25
760
+ 759,TA_34,TA_35,28.0,15.0,20.0,63.0,17.5,12.5,7.0,37.0,50.0
761
+ 760,TA_34,TA_35,13.5,16.0,6.5,36.0,12.0,14.0,4.5,30.5,33.25
762
+ 761,TA_34,TA_33,16.0,3.0,5.0,24.0,13.0,9.0,14.0,36.0,30.0
763
+ 762,TA_34,TA_35,7.5,10.0,13.5,31.0,6.0,8.0,15.0,29.0,30.0
764
+ 763,TA_34,TA_35,12.5,6.5,9.5,28.5,3.5,0.0,3.0,6.5,17.5
765
+ 764,TA_34,TA_35,8.5,6.5,4.0,19.0,16.0,8.0,3.5,27.5,23.25
766
+ 765,TA_34,TA_35,25.0,8.0,13.0,46.0,21.0,10.0,10.0,41.0,43.5
767
+ 766,TA_34,TA_35,11.0,5.5,6.5,23.0,5.5,11.0,3.5,20.0,21.5
768
+ 767,TA_34,TA_35,24.0,10.0,17.0,51.0,20.0,16.0,19.0,55.0,53.0
769
+ 768,TA_34,TA_35,12.0,12.5,10.0,34.5,5.0,8.0,7.5,20.5,27.5
770
+ 769,TA_34,TA_33,17.5,9.0,19.0,45.5,10.0,13.0,17.0,40.0,42.75
771
+ 770,TA_34,TA_35,21.5,12.5,16.5,50.5,18.0,14.0,17.0,49.0,49.75
772
+ 771,TA_34,TA_35,15.0,13.0,11.5,39.5,15.0,16.0,20.0,51.0,45.25
773
+ 772,TA_34,TA_35,17.0,8.0,15.0,40.0,10.5,11.0,12.0,33.5,36.75
774
+ 773,TA_34,TA_35,11.5,7.0,9.5,28.0,13.0,12.0,10.0,35.0,31.5
775
+ 774,TA_34,TA_35,17.0,13.0,17.0,47.0,18.0,15.0,20.0,53.0,50.0
776
+ 775,TA_34,TA_35,21.0,13.0,20.0,54.0,8.0,12.0,14.0,34.0,44.0
777
+ 776,TA_34,TA_35,15.0,9.0,14.0,38.0,4.0,5.5,5.5,15.0,26.5
778
+ 777,TA_34,TA_35,18.5,10.0,2.5,31.0,13.5,12.0,3.0,28.5,29.75
779
+ 778,TA_34,TA_35,20.0,14.0,14.0,48.0,20.5,14.0,18.0,52.5,50.25
780
+ 779,TA_34,TA_35,12.5,14.0,22.0,48.5,18.5,13.5,19.0,51.0,49.75
781
+ 780,TA_34,TA_35,13.5,7.5,10.5,31.5,5.5,14.0,4.0,23.5,27.5
782
+ 781,TA_34,TA_35,14.5,8.0,11.0,33.5,13.0,11.5,13.0,37.5,35.5
783
+ 782,TA_34,TA_35,22.5,9.5,10.5,42.5,14.0,8.5,7.5,30.0,36.25
784
+ 783,TA_34,TA_35,21.0,16.0,13.0,50.0,16.0,14.0,2.0,32.0,41.0
785
+ 784,TA_34,TA_35,23.5,14.5,18.5,56.5,17.0,14.0,14.0,45.0,50.75
786
+ 785,TA_34,TA_35,16.0,12.0,16.0,44.0,6.0,13.0,6.0,25.0,34.5
787
+ 786,TA_34,TA_35,23.5,16.0,21.0,60.5,20.5,14.0,19.0,53.5,57.0
788
+ 787,TA_34,TA_35,25.0,5.0,17.0,47.0,18.0,2.0,13.0,33.0,40.0
789
+ 788,TA_34,TA_35,24.0,13.0,19.0,56.0,17.0,0.0,1.0,18.0,37.0
790
+ 789,TA_34,TA_35,13.5,12.5,14.5,40.5,7.0,13.0,15.5,35.5,38.0
791
+ 790,TA_34,TA_35,26.0,15.5,19.5,61.0,23.0,16.0,22.0,61.0,61.0
792
+ 791,TA_36,TA_37,12.0,9.5,3.5,25.0,14.0,10.0,8.0,32.0,28.5
793
+ 792,TA_36,TA_37,5.0,6.0,5.0,16.0,11.0,5.0,7.5,23.5,19.75
794
+ 793,TA_36,TA_37,8.5,8.0,8.0,24.5,14.5,9.5,13.0,37.0,30.75
795
+ 794,TA_36,TA_37,13.0,8.5,8.5,30.0,14.0,12.5,10.0,36.5,33.25
796
+ 795,TA_36,TA_37,7.5,9.0,14.5,31.0,9.0,10.0,12.0,31.0,31.0
797
+ 796,TA_36,TA_37,10.0,0.0,0.0,10.0,8.0,0.0,0.0,8.0,9.0
798
+ 797,TA_36,TA_37,9.0,8.0,9.5,26.5,10.0,9.0,11.0,30.0,28.25
799
+ 798,TA_36,TA_37,8.0,1.5,5.5,15.0,11.0,1.0,4.0,16.0,15.5
800
+ 799,TA_36,TA_37,11.0,11.5,13.0,35.5,11.0,12.0,13.0,36.0,35.75
801
+ 800,TA_36,TA_37,15.0,9.0,3.5,27.5,20.0,10.0,6.0,36.0,31.75
802
+ 801,TA_36,TA_37,17.5,11.0,18.75,47.25,18.0,12.0,18.0,48.0,47.625
803
+ 802,TA_36,TA_37,15.5,12.0,17.0,44.5,20.5,14.0,15.5,50.0,47.25
804
+ 803,TA_36,TA_37,1.5,2.5,0.5,4.5,2.0,5.0,0.5,7.5,6.0
805
+ 804,TA_36,TA_37,13.0,14.0,4.5,31.5,12.0,14.0,5.5,31.5,31.5
806
+ 805,TA_36,TA_37,14.0,10.5,8.5,33.0,16.0,11.5,10.5,38.0,35.5
807
+ 806,TA_36,TA_37,17.5,8.0,18.0,43.5,18.0,7.5,17.0,42.5,43.0
808
+ 807,TA_36,TA_37,18.0,17.0,4.5,39.5,18.0,17.0,7.0,42.0,40.75
809
+ 808,TA_36,TA_37,9.0,7.0,7.0,23.0,13.0,9.5,13.0,35.5,29.25
810
+ 809,TA_36,TA_37,8.0,8.5,5.0,21.5,10.5,10.0,8.0,28.5,25.0
811
+ 810,TA_36,TA_37,11.5,10.0,4.0,25.5,13.0,10.5,5.0,28.5,27.0
812
+ 811,TA_36,TA_37,9.0,9.0,0.0,18.0,10.5,10.0,0.0,20.5,19.25
813
+ 812,TA_36,TA_37,10.5,5.0,0.0,15.5,14.0,6.0,0.0,20.0,17.75
814
+ 813,TA_36,TA_37,8.5,0.0,0.0,8.5,10.0,0.0,0.0,10.0,9.25
815
+ 814,TA_36,TA_33,7.5,6.0,8.0,21.5,10.0,4.0,12.0,26.0,23.75
816
+ 815,TA_36,TA_37,24.0,17.0,21.0,62.0,23.5,17.0,19.0,59.5,60.75
817
+ 816,TA_36,TA_37,16.0,9.5,10.0,35.5,18.0,10.5,17.0,45.5,40.5
818
+ 817,TA_36,TA_37,15.0,1.0,2.0,18.0,13.5,1.0,2.0,16.5,17.25
819
+ 818,TA_36,TA_37,6.5,14.0,7.0,27.5,6.5,14.0,7.5,28.0,27.75
820
+ 819,TA_36,TA_37,17.0,4.0,15.5,36.5,19.0,4.0,18.0,41.0,38.75
821
+ 820,TA_36,TA_37,8.0,9.5,6.0,23.5,10.0,9.5,8.0,27.5,25.5
822
+ 821,TA_36,TA_37,11.5,11.0,2.5,25.0,14.0,9.5,3.0,26.5,25.75
823
+ 822,TA_36,TA_37,7.0,9.0,6.0,22.0,7.5,10.5,7.0,25.0,23.5
824
+ 823,TA_36,TA_37,13.5,10.5,7.5,31.5,18.0,11.5,14.0,43.5,37.5
825
+ 824,TA_36,TA_37,16.0,0.0,16.0,32.0,16.0,1.0,16.0,33.0,32.5
826
+ 825,TA_36,TA_37,14.5,13.0,9.5,37.0,15.0,14.0,12.5,41.5,39.25
827
+ 826,TA_36,TA_37,13.0,12.0,12.0,37.0,13.0,12.5,12.0,37.5,37.25
828
+ 827,TA_36,TA_37,17.0,12.0,4.0,33.0,17.0,12.0,5.0,34.0,33.5
829
+ 828,TA_36,TA_37,11.0,16.0,10.0,37.0,15.0,17.0,11.5,43.5,40.25
830
+ 829,TA_36,TA_33,19.0,9.0,18.0,46.0,21.0,9.0,17.0,47.0,46.5
831
+ 830,TA_36,TA_37,9.5,8.0,2.0,19.5,6.0,10.0,2.0,18.0,18.75
832
+ 831,TA_36,TA_37,6.5,13.0,6.0,25.5,9.5,14.0,7.0,30.5,28.0
833
+ 832,TA_36,TA_37,11.0,3.5,3.0,17.5,11.5,6.0,4.0,21.5,19.5
834
+ 833,TA_36,TA_37,12.0,9.0,2.0,23.0,13.0,11.5,2.0,26.5,24.75
835
+ 834,TA_36,TA_37,5.5,9.0,6.5,21.0,6.0,9.5,13.0,28.5,24.75
836
+ 835,TA_36,TA_37,16.0,11.0,6.0,33.0,21.0,12.5,7.0,40.5,36.75
837
+ 836,TA_36,TA_37,21.5,0.0,0.0,21.5,16.0,0.0,0.0,16.0,18.75
838
+ 837,TA_36,TA_37,4.5,6.5,5.0,16.0,8.0,5.0,6.0,19.0,17.5
839
+ 838,TA_36,TA_37,20.5,12.5,17.5,50.5,23.5,12.0,20.0,55.5,53.0
840
+ 839,TA_36,TA_37,18.0,12.5,9.0,39.5,17.0,14.0,12.5,43.5,41.5
841
+ 840,TA_36,TA_37,16.0,7.5,9.5,33.0,15.5,9.5,10.0,35.0,34.0
842
+ 841,TA_38,TA_51,12.5,13.5,11.0,37.0,8.0,11.0,4.75,23.75,30.375
843
+ 842,TA_38,TA_47,6.0,0.0,3.0,9.0,5.0,0.0,4.0,9.0,9.0
844
+ 843,TA_38,TA_46,6.5,8.5,6.0,21.0,3.0,7.5,5.0,15.5,18.25
845
+ 844,TA_38,TA_48,19.5,13.5,13.0,46.0,17.5,11.0,12.0,40.5,43.25
846
+ 845,TA_38,TA_51,10.5,12.5,3.0,26.0,10.0,13.0,4.5,27.5,26.75
847
+ 846,TA_38,TA_48,13.5,0.0,4.0,17.5,12.0,0.0,3.0,15.0,16.25
848
+ 847,TA_38,TA_33,8.0,9.5,9.5,27.0,6.0,9.0,5.0,20.0,23.5
849
+ 848,TA_38,TA_46,13.5,10.5,7.5,31.5,13.0,11.5,7.0,31.5,31.5
850
+ 849,TA_38,TA_48,18.0,11.5,2.5,32.0,17.0,9.0,2.0,28.0,30.0
851
+ 850,TA_38,TA_51,15.0,10.0,6.5,31.5,13.5,10.0,7.0,30.5,31.0
852
+ 851,TA_38,TA_48,20.0,0.0,18.5,38.5,16.0,0.0,16.0,32.0,35.25
853
+ 852,TA_38,TA_46,7.5,11.5,8.5,27.5,8.0,12.5,4.0,24.5,26.0
854
+ 853,TA_38,TA_48,9.0,12.5,5.5,27.0,4.0,11.0,2.0,17.0,22.0
855
+ 854,TA_38,TA_51,20.0,12.5,19.0,51.5,19.5,15.0,19.75,54.25,52.875
856
+ 855,TA_38,TA_48,0.0,11.0,9.5,20.5,0.0,6.0,9.0,15.0,17.75
857
+ 856,TA_38,TA_46,14.0,0.0,4.0,18.0,12.0,0.0,3.0,15.0,16.5
858
+ 857,TA_38,TA_33,15.0,12.0,7.0,34.0,13.0,13.0,6.0,32.0,33.0
859
+ 858,TA_38,TA_48,11.5,13.0,6.5,31.0,10.0,12.0,10.0,32.0,31.5
860
+ 859,TA_38,TA_51,12.5,13.5,8.0,34.0,10.0,12.0,8.75,30.75,32.375
861
+ 860,TA_38,TA_48,16.5,15.0,10.0,41.5,13.0,14.0,10.0,37.0,39.25
862
+ 861,TA_38,TA_46,21.0,9.0,21.0,51.0,19.0,9.5,17.0,45.5,48.25
863
+ 862,TA_38,TA_48,19.0,14.0,15.0,48.0,18.0,14.0,16.0,48.0,48.0
864
+ 863,TA_38,TA_51,9.5,13.0,2.0,24.5,5.5,12.0,2.0,19.5,22.0
865
+ 864,TA_38,TA_48,19.0,11.5,14.0,44.5,13.0,9.0,10.0,32.0,38.25
866
+ 865,TA_38,TA_46,20.0,10.5,5.0,35.5,17.0,10.0,5.0,32.0,33.75
867
+ 866,TA_38,TA_48,13.0,10.5,9.5,33.0,11.0,8.0,5.0,24.0,28.5
868
+ 867,TA_38,TA_51,16.5,1.0,2.0,19.5,16.0,1.0,2.0,19.0,19.25
869
+ 868,TA_38,TA_33,20.0,11.0,10.0,41.0,19.5,12.0,9.0,40.5,40.75
870
+ 869,TA_38,TA_48,13.5,13.0,5.5,32.0,13.0,13.5,4.0,30.5,31.25
871
+ 870,TA_38,TA_46,15.0,14.0,20.5,49.5,13.0,12.5,15.0,40.5,45.0
872
+ 871,TA_38,TA_48,16.5,11.5,6.0,34.0,11.0,12.0,6.0,29.0,31.5
873
+ 872,TA_38,TA_51,12.0,12.5,17.0,41.5,12.0,14.0,10.75,36.75,39.125
874
+ 873,TA_38,TA_48,11.5,9.5,0.0,21.0,7.0,7.0,0.0,14.0,17.5
875
+ 874,TA_38,TA_46,11.5,13.0,18.0,42.5,10.0,13.0,14.0,37.0,39.75
876
+ 875,TA_38,TA_48,8.5,8.5,7.5,24.5,8.0,8.0,6.0,22.0,23.25
877
+ 876,TA_38,TA_51,16.0,12.5,11.5,40.0,15.0,14.0,5.0,34.0,37.0
878
+ 877,TA_38,TA_48,18.0,12.5,19.5,50.0,16.0,12.0,16.0,44.0,47.0
879
+ 878,TA_38,TA_46,12.0,11.5,7.5,31.0,16.0,12.5,7.0,35.5,33.25
880
+ 879,TA_38,TA_48,12.5,15.5,15.0,43.0,10.0,13.0,16.0,39.0,41.0
881
+ 880,TA_38,TA_51,14.0,10.5,21.0,45.5,13.0,14.0,21.25,48.25,46.875
882
+ 881,TA_38,TA_48,9.0,7.5,10.0,26.5,2.0,0.0,12.0,14.0,20.25
883
+ 882,TA_38,TA_46,20.0,14.0,19.0,53.0,14.0,14.0,15.0,43.0,48.0
884
+ 883,TA_38,TA_33,19.0,14.0,14.0,47.0,18.0,13.0,15.0,46.0,46.5
885
+ 884,TA_38,TA_48,16.5,14.0,18.0,48.5,18.0,14.0,16.0,48.0,48.25
886
+ 885,TA_40,TA_41,14.0,12.0,5.0,31.0,17.0,13.5,6.5,37.0,34.0
887
+ 886,TA_40,TA_41,9.0,8.75,0.0,17.75,9.0,8.5,0.5,18.0,17.875
888
+ 887,TA_40,TA_41,25.0,17.0,8.5,50.5,25.5,17.0,7.5,50.0,50.25
889
+ 888,TA_40,TA_41,5.0,0.0,4.0,9.0,9.0,0.0,6.5,15.5,12.25
890
+ 889,TA_40,TA_41,15.0,0.0,15.0,30.0,18.5,0.0,15.5,34.0,32.0
891
+ 890,TA_40,TA_41,14.0,9.0,3.0,26.0,16.5,10.0,3.5,30.0,28.0
892
+ 891,TA_40,TA_41,9.0,7.0,0.0,16.0,13.5,5.5,0.5,19.5,17.75
893
+ 892,TA_40,TA_41,25.5,17.0,12.0,54.5,23.5,17.0,13.0,53.5,54.0
894
+ 893,TA_40,TA_41,10.0,6.75,0.0,16.75,10.5,5.5,0.0,16.0,16.375
895
+ 894,TA_40,TA_41,22.0,17.0,17.5,56.5,23.0,17.0,16.5,56.5,56.5
896
+ 895,TA_40,TA_41,11.5,12.5,18.0,42.0,14.5,10.5,19.0,44.0,43.0
897
+ 896,TA_40,TA_41,20.0,14.0,17.0,51.0,19.0,14.0,17.5,50.5,50.75
898
+ 897,TA_40,TA_33,11.0,10.75,5.5,27.25,12.0,12.0,9.0,33.0,30.125
899
+ 898,TA_40,TA_41,8.5,13.0,4.0,25.5,11.0,11.5,4.5,27.0,26.25
900
+ 899,TA_40,TA_41,13.0,13.0,12.5,38.5,18.0,6.0,13.5,37.5,38.0
901
+ 900,TA_40,TA_41,9.0,8.25,6.0,23.25,11.0,6.5,11.5,29.0,26.125
902
+ 901,TA_40,TA_41,14.5,0.0,10.5,25.0,15.0,0.0,15.0,30.0,27.5
903
+ 902,TA_40,TA_41,13.5,11.0,10.0,34.5,15.5,13.5,13.0,42.0,38.25
904
+ 903,TA_40,TA_33,4.5,3.0,5.5,13.0,8.5,1.0,8.0,17.5,15.25
905
+ 904,TA_40,TA_41,16.5,8.5,3.0,28.0,19.5,9.0,6.5,35.0,31.5
906
+ 905,TA_40,TA_41,12.5,8.5,7.0,28.0,11.0,8.5,10.0,29.5,28.75
907
+ 906,TA_40,TA_41,17.0,8.0,11.0,36.0,17.0,7.5,12.0,36.5,36.25
908
+ 907,TA_40,TA_41,15.5,13.0,16.0,44.5,19.0,13.0,16.0,48.0,46.25
909
+ 908,TA_40,TA_41,6.5,11.25,5.5,23.25,11.5,11.5,10.5,33.5,28.375
910
+ 909,TA_40,TA_41,17.0,17.0,6.0,40.0,16.5,16.0,7.5,40.0,40.0
911
+ 910,TA_40,TA_41,10.0,12.25,2.0,24.25,15.0,13.0,2.0,30.0,27.125
912
+ 911,TA_40,TA_41,11.5,12.5,14.0,38.0,16.0,12.0,12.0,40.0,39.0
913
+ 912,TA_40,TA_41,11.0,6.75,5.5,23.25,16.0,6.5,7.0,29.5,26.375
914
+ 913,TA_40,TA_41,9.0,9.5,2.0,20.5,11.0,7.5,2.5,21.0,20.75
915
+ 914,TA_40,TA_41,3.0,4.0,10.0,17.0,9.0,4.0,12.5,25.5,21.25
916
+ 915,TA_40,TA_41,12.5,12.0,11.0,35.5,17.5,10.5,10.5,38.5,37.0
917
+ 916,TA_40,TA_41,3.0,5.5,2.5,11.0,3.0,5.5,4.5,13.0,12.0
918
+ 917,TA_40,TA_41,4.5,11.0,12.0,27.5,9.0,11.0,14.0,34.0,30.75
919
+ 918,TA_40,TA_41,14.0,13.5,10.5,38.0,16.5,14.0,14.5,45.0,41.5
920
+ 919,TA_40,TA_41,12.5,14.0,8.0,34.5,15.5,14.0,8.0,37.5,36.0
921
+ 920,TA_40,TA_41,20.0,11.75,10.0,41.75,20.0,11.5,10.0,41.5,41.625
922
+ 921,TA_40,TA_41,24.0,16.25,20.5,60.75,25.5,15.5,21.5,62.5,61.625
923
+ 922,TA_40,TA_41,13.0,17.0,19.0,49.0,15.0,17.0,20.0,52.0,50.5
924
+ 923,TA_40,TA_41,4.0,5.5,4.0,13.5,7.0,10.5,8.0,25.5,19.5
925
+ 924,TA_40,TA_41,2.5,0.0,2.0,4.5,4.25,2.0,1.5,7.75,6.125
926
+ 925,TA_40,TA_41,7.0,6.25,10.5,23.75,9.0,7.0,15.0,31.0,27.375
927
+ 926,TA_40,TA_41,8.0,10.0,12.5,30.5,10.0,14.0,12.5,36.5,33.5
928
+ 927,TA_40,TA_41,11.5,8.75,6.0,26.25,9.5,9.0,7.0,25.5,25.875
929
+ 928,TA_40,TA_41,19.0,12.75,18.0,49.75,17.0,13.5,14.5,45.0,47.375
930
+ 929,TA_40,TA_41,12.5,0.0,0.0,12.5,10.5,0.0,0.0,10.5,11.5
931
+ 930,TA_40,TA_41,20.0,13.0,18.0,51.0,20.5,11.5,18.0,50.0,50.5
932
+ 931,TA_42,TA_43,20.0,14.0,6.0,40.0,20.0,12.5,12.0,44.5,42.25
933
+ 932,TA_42,TA_43,11.5,9.0,2.0,22.5,14.5,9.5,3.0,27.0,24.75
934
+ 933,TA_42,TA_43,0.0,1.0,0.0,1.0,1.5,4.0,0.0,5.5,3.25
935
+ 934,TA_42,TA_43,2.0,4.0,0.5,6.5,6.0,6.5,1.0,13.5,10.0
936
+ 935,TA_42,TA_43,3.0,5.0,2.0,10.0,9.0,5.0,2.0,16.0,13.0
937
+ 936,TA_42,TA_43,3.0,0.0,4.0,7.0,5.5,6.5,7.0,19.0,13.0
938
+ 937,TA_42,TA_43,9.0,0.0,5.0,14.0,13.5,0.0,7.0,20.5,17.25
939
+ 938,TA_42,TA_43,9.0,13.0,16.0,38.0,10.5,12.0,17.5,40.0,39.0
940
+ 939,TA_42,TA_43,5.0,9.0,6.0,20.0,8.0,11.0,5.0,24.0,22.0
941
+ 940,TA_42,TA_43,8.0,5.0,0.0,13.0,15.5,4.5,0.0,20.0,16.5
942
+ 941,TA_42,TA_43,6.0,17.0,10.0,33.0,9.5,17.0,21.5,48.0,40.5
943
+ 942,TA_42,TA_43,7.0,12.0,6.0,25.0,6.0,12.0,5.0,23.0,24.0
944
+ 943,TA_42,TA_43,3.5,1.5,2.0,7.0,2.5,1.0,2.0,5.5,6.25
945
+ 944,TA_42,TA_43,4.0,4.0,0.0,8.0,5.0,8.5,0.0,13.5,10.75
946
+ 945,TA_42,TA_43,0.0,0.0,0.0,0.0,0.0,5.0,0.0,5.0,2.5
947
+ 946,TA_42,TA_43,6.0,5.0,0.0,11.0,4.0,6.5,0.0,10.5,10.75
948
+ 947,TA_42,TA_43,6.0,12.0,8.0,26.0,5.5,11.5,8.5,25.5,25.75
949
+ 948,TA_42,TA_43,5.0,4.0,0.0,9.0,11.0,8.0,17.5,36.5,22.75
950
+ 949,TA_42,TA_43,9.0,7.0,5.0,21.0,16.0,7.0,7.0,30.0,25.5
951
+ 950,TA_42,TA_43,13.0,9.0,5.0,27.0,16.5,8.5,5.0,30.0,28.5
952
+ 951,TA_42,TA_43,0.0,0.0,0.0,0.0,0.0,1.0,0.0,1.0,0.5
953
+ 952,TA_42,TA_43,2.0,5.0,0.0,7.0,2.0,6.0,0.0,8.0,7.5
954
+ 953,TA_42,TA_43,21.0,12.0,15.0,48.0,16.0,12.0,18.0,46.0,47.0
955
+ 954,TA_42,TA_43,15.0,4.0,4.0,23.0,15.0,3.5,4.0,22.5,22.75
956
+ 955,TA_42,TA_43,8.0,7.0,0.0,15.0,13.0,7.0,0.0,20.0,17.5
957
+ 956,TA_42,TA_43,15.0,12.0,5.0,32.0,12.5,10.0,10.0,32.5,32.25
958
+ 957,TA_42,TA_43,7.0,5.0,4.0,16.0,13.0,13.0,17.0,43.0,29.5
959
+ 958,TA_42,TA_43,6.0,6.0,11.0,23.0,5.5,3.5,14.0,23.0,23.0
960
+ 959,TA_42,TA_43,9.0,11.5,16.0,36.5,11.0,14.0,19.0,44.0,40.25
961
+ 960,TA_42,TA_43,9.0,0.0,2.5,11.5,10.0,8.5,2.0,20.5,16.0
962
+ 961,TA_42,TA_43,0.0,17.0,20.0,37.0,2.0,17.0,20.5,39.5,38.25
963
+ 962,TA_42,TA_43,4.0,2.0,2.0,8.0,13.0,5.0,18.0,36.0,22.0
964
+ 963,TA_42,TA_43,20.0,11.5,19.0,50.5,17.5,13.5,16.0,47.0,48.75
965
+ 964,TA_42,TA_43,18.0,12.0,3.0,33.0,17.0,12.0,3.0,32.0,32.5
966
+ 965,TA_42,TA_43,2.0,8.0,2.0,12.0,1.0,5.0,3.0,9.0,10.5
967
+ 966,TA_42,TA_43,6.0,8.0,7.0,21.0,10.0,10.0,8.0,28.0,24.5
968
+ 967,TA_42,TA_43,24.0,17.0,9.0,50.0,25.0,17.0,10.0,52.0,51.0
969
+ 968,TA_42,TA_43,9.0,0.0,0.0,9.0,11.5,0.0,2.0,13.5,11.25
970
+ 969,TA_44,TA_33,21.0,0.0,8.5,29.5,21.0,17.0,12.0,50.0,39.75
971
+ 970,TA_44,TA_41,20.0,13.5,11.0,44.5,16.0,14.0,12.5,42.5,43.5
972
+ 971,TA_44,TA_43,0.0,0.0,0.0,0.0,1.0,0.0,1.0,2.0,1.0
973
+ 972,TA_44,TA_33,6.0,0.0,3.5,9.5,3.0,0.0,4.0,7.0,8.25
974
+ 973,TA_44,TA_33,18.5,17.0,20.0,55.5,21.0,17.0,17.0,55.0,55.25
975
+ 974,TA_44,TA_33,12.5,9.0,4.5,26.0,13.0,9.0,4.0,26.0,26.0
976
+ 975,TA_44,TA_33,9.5,8.5,7.5,25.5,18.0,9.5,11.0,38.5,32.0
977
+ 976,TA_44,TA_41,5.5,0.0,0.0,5.5,4.0,0.0,0.0,4.0,4.75
978
+ 977,TA_44,TA_33,8.5,1.0,11.0,20.5,7.0,0.0,9.0,16.0,18.25
979
+ 978,TA_44,TA_43,10.5,6.0,10.5,27.0,9.0,8.5,8.0,25.5,26.25
980
+ 979,TA_44,TA_33,9.5,8.5,6.5,24.5,8.0,11.0,6.0,25.0,24.75
981
+ 980,TA_44,TA_33,14.0,0.0,0.0,14.0,11.0,0.0,0.0,11.0,12.5
982
+ 981,TA_44,TA_33,17.5,13.0,19.0,49.5,18.0,17.0,17.0,52.0,50.75
983
+ 982,TA_44,TA_33,5.5,4.0,0.5,10.0,2.5,4.0,1.5,8.0,9.0
984
+ 983,TA_44,TA_51,15.0,12.5,11.5,39.0,12.5,12.0,11.75,36.25,37.625
985
+ 984,TA_44,TA_41,8.5,10.0,11.5,30.0,7.5,10.0,12.0,29.5,29.75
986
+ 985,TA_44,TA_33,10.0,9.0,12.5,31.5,11.5,13.0,11.0,35.5,33.5
987
+ 986,TA_44,TA_33,16.0,9.0,13.5,38.5,10.0,11.5,9.0,30.5,34.5
988
+ 987,TA_44,TA_33,15.5,10.5,8.5,34.5,16.0,12.5,9.0,37.5,36.0
989
+ 988,TA_44,TA_33,19.0,14.0,0.0,33.0,23.5,14.0,0.0,37.5,35.25
990
+ 989,TA_44,TA_33,16.0,9.5,0.0,25.5,20.0,11.5,0.0,31.5,28.5
991
+ 990,TA_44,TA_33,7.5,8.5,10.0,26.0,5.0,8.5,11.0,24.5,25.25
992
+ 991,TA_44,TA_33,9.0,7.5,3.5,20.0,13.0,10.0,3.0,26.0,23.0
993
+ 992,TA_44,TA_33,19.5,15.0,19.0,53.5,19.0,16.0,17.0,52.0,52.75
994
+ 993,TA_44,TA_33,8.0,6.0,11.0,25.0,5.0,8.5,11.0,24.5,24.75
995
+ 994,TA_44,TA_33,23.0,13.5,17.5,54.0,23.0,17.0,19.0,59.0,56.5
996
+ 995,TA_44,TA_48,15.5,12.5,25.0,53.0,19.0,13.0,19.0,51.0,52.0
997
+ 996,TA_44,TA_46,11.5,12.0,12.0,35.5,15.5,14.0,8.0,37.5,36.5
998
+ 997,TA_44,TA_33,13.0,10.0,17.0,40.0,20.0,10.0,10.5,40.5,40.25
999
+ 998,TA_45,TA_16,21.588,12.736,13.846,48.17,6.5,8.0,13.0,27.5,37.835
1000
+ 999,TA_45,TA_2,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0
1001
+ 1000,TA_45,TA_8,20.72,8.896,15.87,45.486,14.0,12.45,12.75,39.2,42.343
1002
+ 1001,TA_45,TA_8,11.48,4.48,0.0,15.96,3.0,0.0,0.0,3.0,9.48
1003
+ 1002,TA_45,TA_14,17.304,11.2,15.295,43.799,8.0,0.0,8.5,16.5,30.1495
1004
+ 1003,TA_45,TA_6,20.02,0.0,0.0,20.02,10.0,0.0,0.0,10.0,15.01
1005
+ 1004,TA_45,TA_4,29.4,16.0,23.046,68.446,22.0,17.0,17.75,56.75,62.598
1006
+ 1005,TA_45,TA_20,17.864,9.856,0.0,27.72,15.0,11.5,0.0,26.5,27.11
1007
+ 1006,TA_45,TA_8,28.0,4.48,15.272,47.752,8.25,1.0,7.5,16.75,32.251000000000005
1008
+ 1007,TA_45,TA_10,25.48,11.776,21.712,58.968,14.0,12.0,16.0,42.0,50.484
1009
+ 1008,TA_45,TA_4,29.4,0.0,10.12,39.519999999999996,16.0,0.0,5.5,21.5,30.509999999999998
1010
+ 1009,TA_45,TA_6,14.84,0.0,0.0,14.84,7.0,0.0,0.0,7.0,10.92
1011
+ 1010,TA_45,TA_10,15.68,16.0,16.79,48.47,10.5,14.0,5.0,29.5,38.985
1012
+ 1011,TA_45,TA_14,25.2,11.2,16.1,52.5,18.0,0.0,2.0,20.0,36.25
1013
+ 1012,TA_45,TA_14,26.6,8.896,12.282,47.778000000000006,16.0,9.5,11.0,36.5,42.139
1014
+ 1013,TA_45,TA_14,10.976,6.24,0.0,17.216,11.0,7.0,0.0,18.0,17.608
1015
+ 1014,TA_45,TA_4,22.4,13.12,22.77,58.28999999999999,17.0,16.0,16.5,49.5,53.894999999999996
1016
+ 1015,TA_45,TA_16,17.668,12.736,12.88,43.284,14.5,8.5,7.0,30.0,36.641999999999996
1017
+ 1016,TA_45,TA_6,24.64,15.04,20.7,60.379999999999995,21.0,13.5,15.75,50.25,55.315
1018
+ 1017,TA_45,TA_8,28.0,11.2,24.15,63.35,20.0,16.0,20.5,56.5,59.925
1019
+ 1018,TA_45,TA_4,25.48,16.0,22.54,64.02000000000001,24.0,17.0,21.0,62.0,63.010000000000005
1020
+ 1019,TA_45,TA_14,24.976,12.736,12.558,50.27,14.5,12.0,6.0,32.5,41.385000000000005
1021
+ 1020,TA_45,TA_14,17.192,11.2,0.0,28.392,14.0,12.5,0.0,26.5,27.445999999999998
1022
+ 1021,TA_45,TA_2,0.0,2.944,0.0,2.944,0.0,0.0,0.0,0.0,1.472
1023
+ 1022,TA_45,TA_14,26.32,12.736,8.74,47.796,10.0,11.0,6.0,27.0,37.397999999999996
1024
+ 1023,TA_45,TA_16,16.184,11.776,16.744,44.704,16.5,9.5,13.5,39.5,42.102000000000004
1025
+ 1024,TA_45,TA_10,20.02,8.576,4.6,33.196,5.0,1.0,2.0,8.0,20.598
1026
+ 1025,TA_45,TA_8,29.4,9.856,5.98,45.236000000000004,22.5,10.9,4.0,37.4,41.318
1027
+ 1026,TA_45,TA_8,17.64,11.2,7.084,35.924,5.0,11.75,4.5,21.25,28.587
1028
+ 1027,TA_45,TA_6,15.68,12.64,17.02,45.34,8.5,6.75,13.25,28.5,36.92
1029
+ 1028,TA_45,TA_10,19.712,10.368,12.328,42.408,5.0,5.0,4.0,14.0,28.204
1030
+ 1029,TA_45,TA_20,28.0,10.24,15.939,54.179,14.5,10.0,9.0,33.5,43.8395
1031
+ 1030,TA_45,TA_16,23.52,3.136,15.18,41.836,0.0,8.5,12.0,20.5,31.168
1032
+ 1031,TA_45,TA_20,24.92,9.856,13.846,48.622,14.5,12.0,8.0,34.5,41.561
1033
+ 1032,TA_45,TA_8,24.92,0.0,8.05,32.97,10.25,0.0,3.0,13.25,23.11
1034
+ 1033,TA_45,TA_10,28.0,14.4,19.32,61.72,22.0,14.0,16.0,52.0,56.86
1035
+ 1034,TA_45,TA_10,26.32,11.2,19.412,56.931999999999995,21.0,14.0,18.0,53.0,54.965999999999994
1036
+ 1035,TA_39,TA_2,14.5,14.0,13.0,41.5,13.5,10.0,10.5,34.0,37.75
1037
+ 1036,TA_39,TA_2,13.0,10.0,6.5,29.5,14.5,6.5,6.0,27.0,28.25
1038
+ 1037,TA_39,TA_2,18.0,11.25,14.5,43.75,14.5,10.0,11.5,36.0,39.875
1039
+ 1038,TA_39,TA_2,4.0,12.0,4.0,20.0,5.5,11.0,5.5,22.0,21.0
README.md ADDED
@@ -0,0 +1,159 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Introduction to AI — Practical Exam Grading Dataset (Stage 2)
2
+
3
+ 1,038 anonymized student submissions to a university-level practical AI exam,
4
+ each independently graded by **two** teaching assistants, plus the rubric and
5
+ the instructor reference solutions.
6
+
7
+ The 18 LLM grading runs measured on this data, the graders that produced them,
8
+ and the analysis code all live in the project repository alongside the
9
+ equivalent Computer Vision dataset; this folder is the data itself.
10
+
11
+ The dataset was built to test how sensitive LLM graders are to the *prompt* they
12
+ are given — specifically, what happens when an instructor adds a plausible
13
+ "be strict" instruction to an otherwise well-behaved grading prompt.
14
+
15
+ ## What is here
16
+
17
+ | path | contents |
18
+ |---|---|
19
+ | `Practical_AI_exam_grades.csv` | ground truth: two TA grades per student, per question and total |
20
+ | `submissions_extracted/<n>/Q{1,2,3}.ipynb` | the anonymized student notebooks |
21
+ | `Solutions/` | instructor reference solution per question |
22
+ | `stage_2_rubrics_ta.md` | the marking scheme the TAs graded against |
23
+
24
+ Students are identified only by a number (1–1038) that is stable across every
25
+ file. Notebook `submissions_extracted/7/Q2.ipynb` belongs to the student in row
26
+ `Number == 7` of the grades CSV.
27
+
28
+ ## The exam and its scale
29
+
30
+ Three questions: **Q1** tabular regression (predict food delivery time),
31
+ **Q2** PyTorch (predict age from face images), **Q3** classification (find the
32
+ most predictive feature in an anonymized dataset).
33
+
34
+ Marks come from the rubric's task tables, not its header totals — the two
35
+ disagree in the distributed PDF, which is preserved here as `stage_2_rubrics_ta.md`:
36
+
37
+ | question | base | bonus |
38
+ |---|---|---|
39
+ | Q1 Regression | 23 | 3 |
40
+ | Q2 PyTorch | 14 | 3 |
41
+ | Q3 Classification | 19 | 3 |
42
+
43
+ Two instructor corrections were issued by email *during* grading, both affecting
44
+ Q3 only (Part 1 dropped a task and became 2 marks; Part 4 dropped a task and
45
+ became 5). Both are folded into the rubric file and marked ⚠.
46
+
47
+ ## Ground truth quality
48
+
49
+ Every student is graded by two TAs, so the dataset carries its own noise floor:
50
+
51
+ | statistic | value |
52
+ |---|---|
53
+ | TA-vs-TA mean absolute difference (totals) | 5.13 |
54
+ | **floor: \|TA − TA mean\|**, the quantity an AI grader is scored against | **2.57** (95% CI 2.41–2.74) |
55
+ | inter-TA correlation (totals) | 0.871 |
56
+
57
+ The floor is ~4% of the ~65-point scale. Any AI grader should be read against
58
+ 2.57, not against zero.
59
+
60
+ ## Anonymization
61
+
62
+ Student names, ID numbers, emails, and submission links are absent. Notebooks
63
+ were rebuilt from scratch keeping only code cells: markdown cells, outputs,
64
+ execution counts, and all per-cell metadata were dropped, so Colab
65
+ `executionInfo` blocks (which embed a Google account name and user id) do not
66
+ survive. Remaining identifiers inside code — names in variable names or
67
+ comments, emails, ID numbers, phone numbers, filesystem usernames — were
68
+ replaced with `ANON` (identifier-safe) or `[REDACTED]`.
69
+
70
+ Scrubbing was verified two ways: an exhaustive scan against the full roster
71
+ (every student and TA name, email and ID, plus generic email/ID/phone patterns
72
+ and notebook-format regressions), and an LLM review of all ~25k comment and
73
+ string literals looking for identifiers the roster could not know about. The
74
+ second pass is what caught a reference to an instructor by first name and one
75
+ student who had loaded the exam data from a personal account.
76
+
77
+ TAs appear only as pseudonyms (`TA_1`, `TA_2`, …). One slot carries the
78
+ composite id `TA_49+TA_50`: those 18 students had Q1 and Q2 graded by one TA and
79
+ Q3 by another. The pseudonym-to-person mapping is **not** published, so grading
80
+ behaviour cannot be attributed to any individual.
81
+
82
+ One deliberate difference between the released grader and the script that
83
+ produced `results/`: the prompt's opening sentence named the institution and
84
+ programme running the course, and reads *"an introductory AI practical exam"*
85
+ here instead. That phrase is the only difference, and it changes no grading
86
+ rule — but a run reproduced from this bundle sends a prompt one phrase
87
+ different from the published one.
88
+
89
+ ## Known gaps, stated plainly
90
+
91
+ - 24 students from the original cohort are absent: they uploaded nothing, an
92
+ unreadable archive, or files that were not the exam. The remaining 1,038 are
93
+ numbered contiguously.
94
+ - Roughly 96 students are missing a notebook for at least one question — they
95
+ did not submit that question. An absent `Q<n>.ipynb` means exactly that, and
96
+ the grading code scores it 0.
97
+ - The rubric's header totals contradict its own task tables in all three
98
+ questions. This is preserved rather than corrected; it is part of what a real
99
+ grading prompt has to cope with.
100
+ - A handful of TA grades exceed the rubric maximum for a question.
101
+ - Two TA grades awarded credit for a question the student never submitted
102
+ (8.0 and 10.0, each contradicted by the paired TA's 0). Both were set to 0
103
+ and the totals recomputed: ground truth that credits work no grader can see
104
+ would penalise every grader, human or machine.
105
+
106
+ ## The LLM runs in `results/`
107
+
108
+ Nine open-weights models, each run twice over the full cohort with an identical
109
+ prompt except for one leading persona sentence:
110
+
111
+ - **neutral** — "You are a strict but fair teaching assistant."
112
+ - **strict** — "You are a HARSH teaching assistant. Award the MINIMUM defensible
113
+ score for any task that is incomplete, buggy, or deviates from the rubric.
114
+ Never give partial credit if the task does not run correctly."
115
+
116
+ Everything else is held fixed: reference solution included, per-task breakdown
117
+ requested, no chain-of-thought, temperature 0, one sample per question. Each
118
+ workbook holds the AI score, bonus, and reasoning per question alongside the TA
119
+ columns. `runs_summary.csv` carries MAE against the TA average with a
120
+ 2,000-resample bootstrap CI.
121
+
122
+ `behaviour` classes: `refusal` (≥90% of students zeroed, awarded-total std
123
+ < 0.5), `near-refusal` (≥90% zeroed but still varying), `collapse` (MAE ≥ 8,
124
+ i.e. ≥3× the human floor, while still discriminating between students),
125
+ `graded` otherwise.
126
+
127
+ ## Reproducing
128
+
129
+ The grading and analysis code lives in the project repository, which expects
130
+ this folder at `introduction_to_ai_dataset/`:
131
+
132
+ ```bash
133
+ # serve a model with vLLM, then:
134
+ python introduction_to_ai_grade_with_local.py --all \
135
+ --model <hf-model-id> --api-base http://localhost:8000/v1 \
136
+ --with-solution --no-reasoning --with-breakdown \
137
+ --strictness strict --temperature 0.0 --runs 1 \
138
+ --tag IA02_m-<model_tag>_sol1_gd0_rs0_bd1_str-strict_t00_n1
139
+
140
+ python introduction_to_ai_analyze_run.py <model_tag> # MAE, CI, behaviour class
141
+ ```
142
+
143
+ `introduction_to_ai_submit_persona_sweep.sbatch` is the SLURM launcher: an
144
+ array job, one task per persona (`--array=0,1` gives the published
145
+ neutral+strict pair). `STUDENTS=1-5` turns it into a smoke run that writes
146
+ outside the results tree. It also supports splitting one persona across
147
+ `SHARDS=K` concurrent jobs, reassembled with
148
+ `introduction_to_ai_merge_shards.py`.
149
+ Shards must never share an output workbook — the grader holds the whole workbook
150
+ in memory and rewrites it after every question, so two writers silently destroy
151
+ each other's grades.
152
+
153
+ The published runs used vLLM 0.19.1. Grading is not bitwise reproducible:
154
+ generation is unconstrained, and JSON is parsed leniently.
155
+
156
+ ## Licence and intended use
157
+
158
+ The student work belongs to its authors and is released for research on
159
+ automated grading. Do not attempt to re-identify students or TAs.
Solutions/Q1_Regression_Solution.ipynb ADDED
@@ -0,0 +1,331 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "markdown",
5
+ "metadata": {},
6
+ "source": [
7
+ "## Question 1 SOLUTION: Predict Food Delivery Time\n",
8
+ "\n",
9
+ "You are provided with a food delivery dataset that includes features such as delivery distance, restaurant preparation time, traffic conditions, and order details. Your objective is to develop a regression model that accurately predicts the delivery time in minutes.\n",
10
+ "\n",
11
+ "Your target is the column: \"delivery_time\".\n",
12
+ "\n",
13
+ "You are provided with the code to download and load the csv file.\n",
14
+ "\n",
15
+ "Your work will be evaluated based on the completion of the following tasks:\n"
16
+ ]
17
+ },
18
+ {
19
+ "cell_type": "markdown",
20
+ "metadata": {},
21
+ "source": [
22
+ "# Part 1: Read Data\n",
23
+ "\n",
24
+ "**Tasks:**\n",
25
+ "\n",
26
+ "1. Read the dataset using `read_csv()`\n",
27
+ "2. Inspect the first few rows using `head()`\n",
28
+ "3. Display dataset information using `info()`\n",
29
+ "4. Show statistical description using `describe()`\n",
30
+ "5. Plot the target distribution (delivery_time)"
31
+ ]
32
+ },
33
+ {
34
+ "cell_type": "code",
35
+ "metadata": {},
36
+ "source": [
37
+ "import kagglehub\n",
38
+ "\n",
39
+ "# Download latest version\n",
40
+ "path = kagglehub.dataset_download(\"ANON_OWNER/q1-exam-data\")\n",
41
+ "\n",
42
+ "print(\"Path to dataset files:\", path)"
43
+ ],
44
+ "execution_count": null,
45
+ "outputs": []
46
+ },
47
+ {
48
+ "cell_type": "code",
49
+ "metadata": {},
50
+ "source": [
51
+ "import pandas as pd\n",
52
+ "import os\n",
53
+ "df = pd.read_csv(os.path.join(path, 'Q1_data.csv'))\n",
54
+ "df.head()"
55
+ ],
56
+ "execution_count": null,
57
+ "outputs": []
58
+ },
59
+ {
60
+ "cell_type": "code",
61
+ "metadata": {},
62
+ "source": [
63
+ "df.head()"
64
+ ],
65
+ "execution_count": null,
66
+ "outputs": []
67
+ },
68
+ {
69
+ "cell_type": "code",
70
+ "metadata": {},
71
+ "source": [
72
+ "df.info()"
73
+ ],
74
+ "execution_count": null,
75
+ "outputs": []
76
+ },
77
+ {
78
+ "cell_type": "code",
79
+ "metadata": {},
80
+ "source": [
81
+ "df.describe()"
82
+ ],
83
+ "execution_count": null,
84
+ "outputs": []
85
+ },
86
+ {
87
+ "cell_type": "code",
88
+ "metadata": {},
89
+ "source": [
90
+ "df['Delivery_Time'].hist(bins=30)"
91
+ ],
92
+ "execution_count": null,
93
+ "outputs": []
94
+ },
95
+ {
96
+ "cell_type": "markdown",
97
+ "metadata": {},
98
+ "source": [
99
+ "# Part 2: Data Cleaning\n",
100
+ "\n",
101
+ "**Tasks:**\n",
102
+ "\n",
103
+ "Inspect and fix the following when needed:\n",
104
+ "\n",
105
+ "1. **Drop the 'Order_ID' column from the data** \n",
106
+ "2. **Handle missing values appropriately** (Hint: I guess you want to have a closer look at the columns with missing values :) )\n",
107
+ "3. **Check and remove duplicates** if any exist\n",
108
+ "4. **Encode categorical variables** if needed\n",
109
+ "5. **Apply feature scaling** to numerical features (Use StandardScaler)\n",
110
+ "6. **Check for target imbalance and state if it is imbalanced or not** (keep this cell empty if not needed)"
111
+ ]
112
+ },
113
+ {
114
+ "cell_type": "code",
115
+ "metadata": {},
116
+ "source": [
117
+ "# Task 1\n",
118
+ "df = df.drop('Order_ID', axis=1)"
119
+ ],
120
+ "execution_count": null,
121
+ "outputs": []
122
+ },
123
+ {
124
+ "cell_type": "code",
125
+ "metadata": {},
126
+ "source": [
127
+ "# Task 2\n",
128
+ "# Drop rows with missing target\n",
129
+ "df = df.dropna(subset=['Delivery_Time'])\n",
130
+ "# Fill missing values\n",
131
+ "df = df.fillna(df.median(numeric_only=True))\n",
132
+ "df = df.fillna(df.mode().iloc[0])"
133
+ ],
134
+ "execution_count": null,
135
+ "outputs": []
136
+ },
137
+ {
138
+ "cell_type": "code",
139
+ "metadata": {},
140
+ "source": [
141
+ "# Task 3\n",
142
+ "df = df.drop_duplicates()"
143
+ ],
144
+ "execution_count": null,
145
+ "outputs": []
146
+ },
147
+ {
148
+ "cell_type": "code",
149
+ "metadata": {},
150
+ "source": [
151
+ "# Task 4\n",
152
+ "from sklearn.preprocessing import LabelEncoder\n",
153
+ "categorical_cols = df.select_dtypes(\"object\").columns\n",
154
+ "for col in categorical_cols:\n",
155
+ " le = LabelEncoder()\n",
156
+ " df[col] = le.fit_transform(df[col])"
157
+ ],
158
+ "execution_count": null,
159
+ "outputs": []
160
+ },
161
+ {
162
+ "cell_type": "code",
163
+ "metadata": {},
164
+ "source": [
165
+ "# Task 5\n",
166
+ "from sklearn.preprocessing import StandardScaler\n",
167
+ "scaler = StandardScaler()\n",
168
+ "X_cols = [col for col in df.columns if col != 'Delivery_Time']\n",
169
+ "df[X_cols] = scaler.fit_transform(df[X_cols])"
170
+ ],
171
+ "execution_count": null,
172
+ "outputs": []
173
+ },
174
+ {
175
+ "cell_type": "code",
176
+ "metadata": {},
177
+ "source": [
178
+ "# Task 6\n",
179
+ "# Not applicable for regression"
180
+ ],
181
+ "execution_count": null,
182
+ "outputs": []
183
+ },
184
+ {
185
+ "cell_type": "markdown",
186
+ "metadata": {},
187
+ "source": [
188
+ "# Part 3: Modeling\n",
189
+ "\n",
190
+ "**Tasks:**\n",
191
+ "\n",
192
+ "1. Split the dataset into features (X) and target (y)\n",
193
+ "2. Use the correct split: **KFold** OR **StratifiedKFold**\n",
194
+ "3. Train a **RandomForest** model\n",
195
+ "4. Evaluate using **MAE (Mean Absolute Error) ONLY**\n",
196
+ "5. Print the averaged score across all folds"
197
+ ]
198
+ },
199
+ {
200
+ "cell_type": "code",
201
+ "metadata": {},
202
+ "source": [
203
+ "X = df.drop('Delivery_Time', axis=1)\n",
204
+ "y = df['Delivery_Time']"
205
+ ],
206
+ "execution_count": null,
207
+ "outputs": []
208
+ },
209
+ {
210
+ "cell_type": "code",
211
+ "metadata": {},
212
+ "source": [
213
+ "from sklearn.model_selection import KFold\n",
214
+ "from sklearn.ensemble import RandomForestRegressor\n",
215
+ "from sklearn.metrics import mean_absolute_error\n",
216
+ "import numpy as np\n",
217
+ "\n",
218
+ "kf = KFold(n_splits=5, shuffle=True, random_state=42)\n",
219
+ "model = RandomForestRegressor(random_state=42)\n",
220
+ "scores = []\n",
221
+ "\n",
222
+ "for train_idx, val_idx in kf.split(X):\n",
223
+ " X_train, X_val = X.iloc[train_idx], X.iloc[val_idx]\n",
224
+ " y_train, y_val = y.iloc[train_idx], y.iloc[val_idx]\n",
225
+ " model.fit(X_train, y_train)\n",
226
+ " y_pred = model.predict(X_val)\n",
227
+ " scores.append(mean_absolute_error(y_val, y_pred))\n",
228
+ "\n",
229
+ "print(f'Average MAE: {np.mean(scores):.2f}')"
230
+ ],
231
+ "execution_count": null,
232
+ "outputs": []
233
+ },
234
+ {
235
+ "cell_type": "markdown",
236
+ "metadata": {},
237
+ "source": [
238
+ "# Part 4: Plots\n",
239
+ "\n",
240
+ "**Tasks:**\n",
241
+ "\n",
242
+ "1. Plot feature importance from your trained model\n",
243
+ "2. Plot predicted delivery time histogram"
244
+ ]
245
+ },
246
+ {
247
+ "cell_type": "code",
248
+ "metadata": {},
249
+ "source": [
250
+ "import matplotlib.pyplot as plt\n",
251
+ "plt.barh(X.columns, model.feature_importances_)\n",
252
+ "plt.xlabel('Importance')\n",
253
+ "plt.tight_layout()\n",
254
+ "plt.show()"
255
+ ],
256
+ "execution_count": null,
257
+ "outputs": []
258
+ },
259
+ {
260
+ "cell_type": "code",
261
+ "metadata": {},
262
+ "source": [
263
+ "y_pred = model.predict(X)\n",
264
+ "plt.hist(y_pred, bins=30)\n",
265
+ "plt.xlabel('Predicted Delivery Time')\n",
266
+ "plt.show()"
267
+ ],
268
+ "execution_count": null,
269
+ "outputs": []
270
+ },
271
+ {
272
+ "cell_type": "markdown",
273
+ "metadata": {},
274
+ "source": [
275
+ "# Part 5: Bonus - Ensemble\n",
276
+ "\n",
277
+ "**Task:**\n",
278
+ "\n",
279
+ "Why use one model? Let's use 2 then merge!\n",
280
+ "\n",
281
+ "Rewrite the KFold loop such that you:\n",
282
+ "1. Train **2 different models** inside the loop at the same time in each iteration\n",
283
+ "2. Average their predictions\n",
284
+ "3. Calculate the MAE metric on the averaged predictions\n",
285
+ "\n",
286
+ "Use RandomForestRegressor and CatBoostRegressor."
287
+ ]
288
+ },
289
+ {
290
+ "cell_type": "code",
291
+ "metadata": {},
292
+ "source": [
293
+ "from sklearn.ensemble import RandomForestRegressor\n",
294
+ "from catboost import CatBoostRegressor\n",
295
+ "\n",
296
+ "kf = KFold(n_splits=5, shuffle=True, random_state=42)\n",
297
+ "model1 = RandomForestRegressor(random_state=42)\n",
298
+ "model2 = CatBoostRegressor(verbose=0, random_state=42)\n",
299
+ "scores = []\n",
300
+ "\n",
301
+ "for train_idx, val_idx in kf.split(X):\n",
302
+ " X_train, X_val = X.iloc[train_idx], X.iloc[val_idx]\n",
303
+ " y_train, y_val = y.iloc[train_idx], y.iloc[val_idx]\n",
304
+ " \n",
305
+ " model1.fit(X_train, y_train)\n",
306
+ " model2.fit(X_train, y_train)\n",
307
+ " \n",
308
+ " y_pred1 = model1.predict(X_val)\n",
309
+ " y_pred2 = model2.predict(X_val)\n",
310
+ " y_pred_avg = (y_pred1 + y_pred2) / 2\n",
311
+ " \n",
312
+ " scores.append(mean_absolute_error(y_val, y_pred_avg))\n",
313
+ "\n",
314
+ "print(f'Average MAE (Ensemble): {np.mean(scores):.2f}')"
315
+ ],
316
+ "execution_count": null,
317
+ "outputs": []
318
+ }
319
+ ],
320
+ "metadata": {
321
+ "kernelspec": {
322
+ "display_name": "Python 3",
323
+ "name": "python3"
324
+ },
325
+ "language_info": {
326
+ "name": "python"
327
+ }
328
+ },
329
+ "nbformat": 4,
330
+ "nbformat_minor": 0
331
+ }
Solutions/Q2_Pytorch_Solution.ipynb ADDED
@@ -0,0 +1,396 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "markdown",
5
+ "metadata": {},
6
+ "source": [
7
+ "## Question 2: Predict Age from Face Images\n",
8
+ "\n",
9
+ "You are provided with a face image dataset containing 2000 images of human faces. Your objective is to develop a regression model using PyTorch that accurately predicts the age of a person based on their face image.\n",
10
+ "\n",
11
+ "You are provided with the code to download and load the dataset.\n",
12
+ "\n",
13
+ "Your work will be evaluated based on the completion of the following tasks:\n"
14
+ ]
15
+ },
16
+ {
17
+ "cell_type": "markdown",
18
+ "metadata": {},
19
+ "source": [
20
+ "# 1. Load and Process Data (Provided)"
21
+ ]
22
+ },
23
+ {
24
+ "cell_type": "markdown",
25
+ "metadata": {},
26
+ "source": [
27
+ "### **1. Load and Process Data (Provided)**\n",
28
+ "\n",
29
+ "The code below is provided for you. It:\n",
30
+ "1. Loads images from the `images` folder.\n",
31
+ "2. Loads labels from `labels.csv`.\n",
32
+ "3. Splits the data into training and testing sets (`X_train`, `X_test`, `y_train`, `y_test`).\n",
33
+ "\n",
34
+ "**Just run these cell to load the data.**"
35
+ ]
36
+ },
37
+ {
38
+ "cell_type": "code",
39
+ "metadata": {},
40
+ "source": [
41
+ "import kagglehub\n",
42
+ "\n",
43
+ "# Download latest version\n",
44
+ "path = kagglehub.dataset_download(\"ANON_OWNER/q2-exam-data\")\n",
45
+ "\n",
46
+ "print(\"Path to dataset files:\", path)"
47
+ ],
48
+ "execution_count": null,
49
+ "outputs": []
50
+ },
51
+ {
52
+ "cell_type": "code",
53
+ "metadata": {},
54
+ "source": [
55
+ "import os\n",
56
+ "import pandas as pd\n",
57
+ "import numpy as np\n",
58
+ "from PIL import Image\n",
59
+ "from sklearn.model_selection import train_test_split\n",
60
+ "\n",
61
+ "# Load Labels\n",
62
+ "labels_df = pd.read_csv(os.path.join(path, \"labels.csv\"))\n",
63
+ "img_dir = os.path.join(path, \"images\")\n",
64
+ "\n",
65
+ "images = []\n",
66
+ "ages = []\n",
67
+ "\n",
68
+ "# Load Images and Resize\n",
69
+ "print(\"Loading images...\")\n",
70
+ "for index, row in labels_df.iterrows():\n",
71
+ " img_name = row.iloc[0]\n",
72
+ " age = row.iloc[1]\n",
73
+ " img_path = os.path.join(img_dir, img_name)\n",
74
+ " \n",
75
+ " if os.path.exists(img_path):\n",
76
+ " img = Image.open(img_path).convert('RGB')\n",
77
+ " img_array = np.array(img) / 255.0 # Normalize pixel values to [0, 1]\n",
78
+ " images.append(img_array)\n",
79
+ " ages.append(age)\n",
80
+ "\n",
81
+ "X = np.array(images)\n",
82
+ "y = np.array(ages)\n",
83
+ "\n",
84
+ "# Transpose image dimensions to match PyTorch format (N, C, H, W)\n",
85
+ "X = np.transpose(X, (0, 3, 1, 2))\n",
86
+ "\n",
87
+ "# Split Data\n",
88
+ "X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)\n",
89
+ "\n",
90
+ "print(f\"X_train shape: {X_train.shape}\")\n",
91
+ "print(f\"X_test shape: {X_test.shape}\")\n",
92
+ "print(f\"y_train shape: {y_train.shape}\")\n",
93
+ "print(f\"y_test shape: {y_test.shape}\")"
94
+ ],
95
+ "execution_count": null,
96
+ "outputs": []
97
+ },
98
+ {
99
+ "cell_type": "markdown",
100
+ "metadata": {},
101
+ "source": [
102
+ "## **Part 1: Prepare Data for PyTorch**\n",
103
+ "\n",
104
+ "**Tasks:**\n",
105
+ "1. **Convert to Tensors:** Convert the numpy arrays (`X_train`, `X_test`, `y_train`, `y_test`) into PyTorch tensors.\n",
106
+ "2. **Create Datasets:** Use `TensorDataset` to create `train_dataset` and `test_dataset` from the tensors.\n",
107
+ "3. **Create DataLoaders:** Create `train_loader` and `test_loader` with a batch size of 32. \n",
108
+ "4. **Inspect Data:** Print the shape of one batch from the train loader and \n",
109
+ "5. **Display a few images:** Use matplotlib to display a few images."
110
+ ]
111
+ },
112
+ {
113
+ "cell_type": "code",
114
+ "metadata": {},
115
+ "source": [
116
+ "import torch\n",
117
+ "\n",
118
+ "X_train_tensor = torch.tensor(X_train, dtype=torch.float32)\n",
119
+ "X_test_tensor = torch.tensor(X_test, dtype=torch.float32)\n",
120
+ "y_train_tensor = torch.tensor(y_train, dtype=torch.float32)\n",
121
+ "y_test_tensor = torch.tensor(y_test, dtype=torch.float32)"
122
+ ],
123
+ "execution_count": null,
124
+ "outputs": []
125
+ },
126
+ {
127
+ "cell_type": "code",
128
+ "metadata": {},
129
+ "source": [
130
+ "from torch.utils.data import TensorDataset\n",
131
+ "\n",
132
+ "train_dataset = TensorDataset(X_train_tensor, y_train_tensor)\n",
133
+ "test_dataset = TensorDataset(X_test_tensor, y_test_tensor)"
134
+ ],
135
+ "execution_count": null,
136
+ "outputs": []
137
+ },
138
+ {
139
+ "cell_type": "code",
140
+ "metadata": {},
141
+ "source": [
142
+ "from torch.utils.data import DataLoader\n",
143
+ "\n",
144
+ "train_loader = DataLoader(train_dataset, batch_size=32, shuffle=True)\n",
145
+ "test_loader = DataLoader(test_dataset, batch_size=32, shuffle=False)"
146
+ ],
147
+ "execution_count": null,
148
+ "outputs": []
149
+ },
150
+ {
151
+ "cell_type": "code",
152
+ "metadata": {},
153
+ "source": [
154
+ "images, labels = next(iter(train_loader))\n",
155
+ "print(f\"Batch images shape: {images.shape}\")\n",
156
+ "print(f\"Batch labels shape: {labels.shape}\")"
157
+ ],
158
+ "execution_count": null,
159
+ "outputs": []
160
+ },
161
+ {
162
+ "cell_type": "code",
163
+ "metadata": {},
164
+ "source": [
165
+ "import matplotlib.pyplot as plt\n",
166
+ "\n",
167
+ "plt.figure(figsize=(10, 5))\n",
168
+ "for i in range(4):\n",
169
+ " plt.subplot(1, 4, i+1)\n",
170
+ " img = images[i].permute(1, 2, 0).numpy()\n",
171
+ " plt.imshow(img)\n",
172
+ " plt.title(f\"Age: {labels[i].item():.0f}\")\n",
173
+ " plt.axis(\"off\")\n",
174
+ "plt.show()"
175
+ ],
176
+ "execution_count": null,
177
+ "outputs": []
178
+ },
179
+ {
180
+ "cell_type": "markdown",
181
+ "metadata": {},
182
+ "source": [
183
+ "# Part 2: Model\n",
184
+ "\n",
185
+ "**Tasks:**\n",
186
+ "\n",
187
+ "1. Create a model class with **4 linear layers**\n",
188
+ "2. Create a training loop function\n",
189
+ "3. Create a validation loop function\n",
190
+ "4. Define the device, model, loss function, and optimizer\n",
191
+ "5. Start training for **20 epochs** and track training and validation losses"
192
+ ]
193
+ },
194
+ {
195
+ "cell_type": "code",
196
+ "metadata": {},
197
+ "source": [
198
+ "import torch.nn as nn\n",
199
+ "\n",
200
+ "class AgeModel(nn.Module):\n",
201
+ " def __init__(self, input_dim, hidden_dim, output_dim):\n",
202
+ " super(AgeModel, self).__init__()\n",
203
+ " self.layer1 = nn.Linear(input_dim, hidden_dim)\n",
204
+ " self.layer2 = nn.Linear(hidden_dim, hidden_dim)\n",
205
+ " self.layer3 = nn.Linear(hidden_dim, hidden_dim)\n",
206
+ " self.layer4 = nn.Linear(hidden_dim, output_dim)\n",
207
+ " self.relu = nn.ReLU()\n",
208
+ "\n",
209
+ " def forward(self, x):\n",
210
+ " x = self.relu(self.layer1(x))\n",
211
+ " x = self.relu(self.layer2(x))\n",
212
+ " x = self.relu(self.layer3(x))\n",
213
+ " x = self.layer4(x)\n",
214
+ " return x.squeeze()"
215
+ ],
216
+ "execution_count": null,
217
+ "outputs": []
218
+ },
219
+ {
220
+ "cell_type": "code",
221
+ "metadata": {},
222
+ "source": [
223
+ "def train_one_epoch(model, optimizer, criterion, train_loader, device):\n",
224
+ " # Set the model to training mode\n",
225
+ " model.train()\n",
226
+ "\n",
227
+ " running_loss = 0.0\n",
228
+ "\n",
229
+ " for X_batch, y_batch in train_loader:\n",
230
+ " # Move batch to the selected device\n",
231
+ " X_batch = X_batch.view(X_batch.size(0), -1).to(device)\n",
232
+ " y_batch = y_batch.to(device)\n",
233
+ "\n",
234
+ " # Forward pass\n",
235
+ " outputs = model(X_batch)\n",
236
+ " loss = criterion(outputs, y_batch)\n",
237
+ "\n",
238
+ " # Backward pass & optimization\n",
239
+ " optimizer.zero_grad() # Clear previous gradients\n",
240
+ " loss.backward() # Compute gradients\n",
241
+ " optimizer.step() # Update model parameters\n",
242
+ "\n",
243
+ " running_loss += loss.item()\n",
244
+ "\n",
245
+ " # Average loss over all batches\n",
246
+ " avg_loss = running_loss / len(train_loader)\n",
247
+ "\n",
248
+ " return avg_loss"
249
+ ],
250
+ "execution_count": null,
251
+ "outputs": []
252
+ },
253
+ {
254
+ "cell_type": "code",
255
+ "metadata": {},
256
+ "source": [
257
+ "def validate(model, criterion, test_loader, device):\n",
258
+ " # Set the model to evaluation mode\n",
259
+ " model.eval()\n",
260
+ "\n",
261
+ " running_loss = 0.0\n",
262
+ "\n",
263
+ " with torch.no_grad():\n",
264
+ " for X_batch, y_batch in test_loader:\n",
265
+ " # Move data to device\n",
266
+ " X_batch = X_batch.view(X_batch.size(0), -1).to(device)\n",
267
+ " y_batch = y_batch.to(device)\n",
268
+ "\n",
269
+ " # Forward pass\n",
270
+ " outputs = model(X_batch)\n",
271
+ " loss = criterion(outputs, y_batch)\n",
272
+ " running_loss += loss.item()\n",
273
+ "\n",
274
+ " avg_loss = running_loss / len(test_loader)\n",
275
+ "\n",
276
+ " return avg_loss"
277
+ ],
278
+ "execution_count": null,
279
+ "outputs": []
280
+ },
281
+ {
282
+ "cell_type": "code",
283
+ "metadata": {},
284
+ "source": [
285
+ "device = torch.device(\"cuda\" if torch.cuda.is_available() else \"cpu\")\n",
286
+ "\n",
287
+ "input_dim = 36 * 36 * 3\n",
288
+ "hidden_dim = 128\n",
289
+ "output_dim = 1\n",
290
+ "\n",
291
+ "model = AgeModel(input_dim, hidden_dim, output_dim).to(device)\n",
292
+ "\n",
293
+ "num_epochs = 20\n",
294
+ "learning_rate = 0.001\n",
295
+ "\n",
296
+ "criterion = nn.MSELoss()\n",
297
+ "optimizer = torch.optim.AdamW(model.parameters(), learning_rate)"
298
+ ],
299
+ "execution_count": null,
300
+ "outputs": []
301
+ },
302
+ {
303
+ "cell_type": "code",
304
+ "metadata": {},
305
+ "source": [
306
+ "# Run Training\n",
307
+ "train_losses = []\n",
308
+ "val_losses = []\n",
309
+ "\n",
310
+ "print('Starting Training...')\n",
311
+ "for epoch in range(num_epochs):\n",
312
+ " # Train one epoch\n",
313
+ " train_loss = train_one_epoch(model, optimizer, criterion, train_loader, device)\n",
314
+ "\n",
315
+ " # Validate\n",
316
+ " val_loss = validate(model, criterion, test_loader, device)\n",
317
+ "\n",
318
+ " train_losses.append(train_loss)\n",
319
+ " val_losses.append(val_loss)\n",
320
+ "\n",
321
+ " print(f'Epoch [{epoch+1}/{num_epochs}], Train Loss: {train_loss:.4f}, Val Loss: {val_loss:.4f}')\n",
322
+ "\n",
323
+ "print('Training Complete!')"
324
+ ],
325
+ "execution_count": null,
326
+ "outputs": []
327
+ },
328
+ {
329
+ "cell_type": "markdown",
330
+ "metadata": {},
331
+ "source": [
332
+ "# Part 3: Plots\n",
333
+ "\n",
334
+ "**Tasks:**\n",
335
+ "\n",
336
+ "1. Plot the training and validation loss over epochs\n",
337
+ "2. **Bonus:** Plot some predictions with their actual images (show predicted age vs actual age)"
338
+ ]
339
+ },
340
+ {
341
+ "cell_type": "code",
342
+ "metadata": {},
343
+ "source": [
344
+ "plt.plot(train_losses, label='Train Loss')\n",
345
+ "plt.plot(val_losses, label='Validation Loss')\n",
346
+ "plt.title('Loss over Epochs')\n",
347
+ "plt.xlabel('Epoch')\n",
348
+ "plt.ylabel('Loss')\n",
349
+ "plt.legend()\n",
350
+ "plt.show()"
351
+ ],
352
+ "execution_count": null,
353
+ "outputs": []
354
+ },
355
+ {
356
+ "cell_type": "code",
357
+ "metadata": {},
358
+ "source": [
359
+ "model.eval()\n",
360
+ "images, labels = next(iter(test_loader))\n",
361
+ "images = images.to(device)\n",
362
+ "with torch.no_grad():\n",
363
+ " preds = model(images.view(images.size(0), -1))\n",
364
+ "\n",
365
+ "plt.figure(figsize=(10, 5))\n",
366
+ "for i in range(4):\n",
367
+ " plt.subplot(1, 4, i+1)\n",
368
+ " img = images[i].cpu().permute(1, 2, 0).numpy()\n",
369
+ " plt.imshow(img)\n",
370
+ " plt.title(f\"Real: {labels[i].item():.0f}\\nPred: {preds[i].item():.0f}\")\n",
371
+ " plt.axis(\"off\")\n",
372
+ "plt.show()"
373
+ ],
374
+ "execution_count": null,
375
+ "outputs": []
376
+ },
377
+ {
378
+ "cell_type": "code",
379
+ "metadata": {},
380
+ "source": [],
381
+ "execution_count": null,
382
+ "outputs": []
383
+ }
384
+ ],
385
+ "metadata": {
386
+ "kernelspec": {
387
+ "display_name": "Python 3",
388
+ "name": "python3"
389
+ },
390
+ "language_info": {
391
+ "name": "python"
392
+ }
393
+ },
394
+ "nbformat": 4,
395
+ "nbformat_minor": 0
396
+ }
Solutions/Q3_Classification_Solution.ipynb ADDED
@@ -0,0 +1,397 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "markdown",
5
+ "metadata": {},
6
+ "source": [
7
+ "## Question 3: Exploring Anonymized Data - Can You Find the Golden Feature?\n",
8
+ "\n",
9
+ "\n",
10
+ "\n",
11
+ "**What is Anonymized Data?**\n",
12
+ "\n",
13
+ "\n",
14
+ "\n",
15
+ "Anonymized data is information that has been processed to remove or obscure personally identifiable details, making it impossible to trace back to specific individuals. In credit risk modeling, features are often anonymized (e.g., `P_2`, `D_39`, `B_1`) to protect customer privacy while still enabling powerful predictive analytics.\n",
16
+ "\n",
17
+ "\n",
18
+ "\n",
19
+ "**The Challenge:**\n",
20
+ "\n",
21
+ "\n",
22
+ "\n",
23
+ "Credit default prediction is central to managing risk in consumer lending. American Express, the world's largest payment card issuer, uses machine learning to predict whether cardholders will default on their payments. This helps optimize lending decisions and creates a better customer experience.\n",
24
+ "\n",
25
+ "\n",
26
+ "\n",
27
+ "You are provided with an anonymized dataset containing behavioral and profile features. Your objective is to build a classification model that predicts credit default (0 = No Default, 1 = Default).\n",
28
+ "\n",
29
+ "\n",
30
+ "\n",
31
+ "**Your Mission:** Can you discover the 'golden feature' - the most powerful predictor hidden in this anonymized data?\n",
32
+ "\n",
33
+ "\n",
34
+ "\n",
35
+ "Your work will be evaluated based on the completion of the following tasks:\n"
36
+ ]
37
+ },
38
+ {
39
+ "cell_type": "markdown",
40
+ "metadata": {},
41
+ "source": [
42
+ "# Part 1: Read Data\n",
43
+ "\n",
44
+ "\n",
45
+ "\n",
46
+ "**Tasks:**\n",
47
+ "\n",
48
+ "\n",
49
+ "\n",
50
+ "1. Read the dataset `Q3_data.csv` using `read_csv()`\n",
51
+ "\n",
52
+ "2. Inspect the first few rows using `head()`\n",
53
+ "\n",
54
+ "3. Display dataset information using `info()`\n",
55
+ "\n",
56
+ "4. Show statistical description using `describe()`\n",
57
+ "\n",
58
+ "5. Plot the target distribution (target column)\"\n"
59
+ ]
60
+ },
61
+ {
62
+ "cell_type": "code",
63
+ "metadata": {},
64
+ "source": [
65
+ "import kagglehub\n",
66
+ "\n",
67
+ "\n",
68
+ "\n",
69
+ "# Download latest version\n",
70
+ "\n",
71
+ "path = kagglehub.dataset_download(\"ANON_OWNER/q3-exam-data\")\n",
72
+ "\n",
73
+ "\n",
74
+ "\n",
75
+ "print(\"Path to dataset files:\", path)"
76
+ ],
77
+ "execution_count": null,
78
+ "outputs": []
79
+ },
80
+ {
81
+ "cell_type": "code",
82
+ "metadata": {},
83
+ "source": [
84
+ "import pandas as pd\n",
85
+ "import numpy as np\n",
86
+ "import matplotlib.pyplot as plt\n",
87
+ "\n",
88
+ "# The 'path' variable is defined in the download cell\n",
89
+ "df = pd.read_csv(os.path.join(path, 'Q3_data.csv'))\n"
90
+ ],
91
+ "execution_count": null,
92
+ "outputs": []
93
+ },
94
+ {
95
+ "cell_type": "code",
96
+ "metadata": {},
97
+ "source": [
98
+ "df.head()\n"
99
+ ],
100
+ "execution_count": null,
101
+ "outputs": []
102
+ },
103
+ {
104
+ "cell_type": "code",
105
+ "metadata": {},
106
+ "source": [
107
+ "df.info()\n"
108
+ ],
109
+ "execution_count": null,
110
+ "outputs": []
111
+ },
112
+ {
113
+ "cell_type": "code",
114
+ "metadata": {},
115
+ "source": [
116
+ "df.describe()\n"
117
+ ],
118
+ "execution_count": null,
119
+ "outputs": []
120
+ },
121
+ {
122
+ "cell_type": "code",
123
+ "metadata": {},
124
+ "source": [
125
+ "df['Target'].value_counts().plot(kind='bar')\n",
126
+ "plt.title('Target Distribution (0: No Default, 1: Default)')\n",
127
+ "plt.xlabel('Target')\n",
128
+ "plt.ylabel('Count')\n",
129
+ "plt.show()\n"
130
+ ],
131
+ "execution_count": null,
132
+ "outputs": []
133
+ },
134
+ {
135
+ "cell_type": "markdown",
136
+ "metadata": {},
137
+ "source": [
138
+ "# Part 2: Data Cleaning\n",
139
+ "\n",
140
+ "\n",
141
+ "\n",
142
+ "**Tasks:**\n",
143
+ "\n",
144
+ "\n",
145
+ "\n",
146
+ "Inspect and fix the following when needed:\n",
147
+ "\n",
148
+ "\n",
149
+ "\n",
150
+ "1. **Handle missing values appropriately**\n",
151
+ "\n",
152
+ "2. **Check and remove duplicates** if any exist\n",
153
+ "\n",
154
+ "3. **Encode categorical variables** if needed\n",
155
+ "\n",
156
+ "4. **Apply feature scaling** to numerical features (Use StandardScaler)\n",
157
+ "\n",
158
+ "5. **Check for target imbalance and state if it is imbalanced or not**"
159
+ ]
160
+ },
161
+ {
162
+ "cell_type": "code",
163
+ "metadata": {},
164
+ "source": [
165
+ "print(df.isnull().sum())\n",
166
+ "df = df.fillna(df.median())\n"
167
+ ],
168
+ "execution_count": null,
169
+ "outputs": []
170
+ },
171
+ {
172
+ "cell_type": "code",
173
+ "metadata": {},
174
+ "source": [
175
+ "print(f'Duplicates: {df.duplicated().sum()}')\n",
176
+ "df = df.drop_duplicates()\n"
177
+ ],
178
+ "execution_count": null,
179
+ "outputs": []
180
+ },
181
+ {
182
+ "cell_type": "code",
183
+ "metadata": {},
184
+ "source": [
185
+ "from sklearn.preprocessing import LabelEncoder\n",
186
+ "\n",
187
+ "categorical_cols = df.select_dtypes(include=['object']).columns\n",
188
+ "if len(categorical_cols) > 0:\n",
189
+ " le = LabelEncoder()\n",
190
+ " for col in categorical_cols:\n",
191
+ " df[col] = le.fit_transform(df[col].astype(str))\n",
192
+ " print(f'Encoded columns: {list(categorical_cols)}')\n"
193
+ ],
194
+ "execution_count": null,
195
+ "outputs": []
196
+ },
197
+ {
198
+ "cell_type": "code",
199
+ "metadata": {},
200
+ "source": [
201
+ "from sklearn.preprocessing import StandardScaler\n",
202
+ "\n",
203
+ "scaler = StandardScaler()\n",
204
+ "X_cols = df.drop(columns=['Target']).columns\n",
205
+ "df[X_cols] = scaler.fit_transform(df[X_cols])\n"
206
+ ],
207
+ "execution_count": null,
208
+ "outputs": []
209
+ },
210
+ {
211
+ "cell_type": "code",
212
+ "metadata": {},
213
+ "source": [
214
+ "df['Target'].value_counts()\n",
215
+ "# there is imbalance"
216
+ ],
217
+ "execution_count": null,
218
+ "outputs": []
219
+ },
220
+ {
221
+ "cell_type": "markdown",
222
+ "metadata": {},
223
+ "source": [
224
+ "# Part 3: Modeling\n",
225
+ "\n",
226
+ "\n",
227
+ "\n",
228
+ "**Tasks:**\n",
229
+ "\n",
230
+ "\n",
231
+ "\n",
232
+ "1. Split the dataset into features (X) and target (y)\n",
233
+ "\n",
234
+ "2. Use the correct split: **KFold** OR **StratifiedKFold**\n",
235
+ "\n",
236
+ "3. Train a **CatBoostClassifier** model\n",
237
+ "\n",
238
+ "4. Evaluate using the appropriate metric only (Accuracy vs. F1 Score).\n",
239
+ "\n",
240
+ "5. Print the averaged score across all folds"
241
+ ]
242
+ },
243
+ {
244
+ "cell_type": "code",
245
+ "metadata": {},
246
+ "source": [
247
+ "X = df.drop(columns=['Target'])\n",
248
+ "y = df['Target']\n"
249
+ ],
250
+ "execution_count": null,
251
+ "outputs": []
252
+ },
253
+ {
254
+ "cell_type": "code",
255
+ "metadata": {},
256
+ "source": [
257
+ "from sklearn.model_selection import StratifiedKFold\n",
258
+ "from sklearn.ensemble import RandomForestClassifier\n",
259
+ "from catboost import CatBoostClassifier\n",
260
+ "from sklearn.metrics import f1_score\n",
261
+ "\n",
262
+ "skf = StratifiedKFold(n_splits=5, shuffle=True, random_state=42)\n",
263
+ "model = CatBoostClassifier(n_estimators=100, random_state=42)\n",
264
+ "\n",
265
+ "f1 = []\n",
266
+ "\n",
267
+ "for train_idx, val_idx in skf.split(X, y):\n",
268
+ " X_train, X_val = X.iloc[train_idx], X.iloc[val_idx]\n",
269
+ " y_train, y_val = y.iloc[train_idx], y.iloc[val_idx]\n",
270
+ " \n",
271
+ " model.fit(X_train, y_train)\n",
272
+ " preds = model.predict(X_val)\n",
273
+ " f1.append(f1_score(y_val, preds))\n",
274
+ "\n",
275
+ "print(f'F1: {np.mean(f1):.4f}')\n"
276
+ ],
277
+ "execution_count": null,
278
+ "outputs": []
279
+ },
280
+ {
281
+ "cell_type": "markdown",
282
+ "metadata": {},
283
+ "source": [
284
+ "# Part 4: Find the Golden Feature!\n",
285
+ "\n",
286
+ "\n",
287
+ "\n",
288
+ "**Tasks:**\n",
289
+ "\n",
290
+ "\n",
291
+ "\n",
292
+ "1. Plot feature importance from your trained model\n",
293
+ "\n",
294
+ "2. Identify and print the name of the most important feature (the 'golden feature')\n",
295
+ "\n",
296
+ "3. Plot the distribution of predictions"
297
+ ]
298
+ },
299
+ {
300
+ "cell_type": "code",
301
+ "metadata": {},
302
+ "source": [
303
+ "importances = model.feature_importances_\n",
304
+ "feat_importances = pd.Series(importances, index=X.columns).sort_values(ascending=False)\n",
305
+ "\n",
306
+ "plt.figure(figsize=(10, 6))\n",
307
+ "feat_importances[:10].plot(kind='barh')\n",
308
+ "plt.gca().invert_yaxis()\n",
309
+ "plt.title('Top 10 Feature Importances')\n",
310
+ "plt.xlabel('Importance')\n",
311
+ "plt.show()\n"
312
+ ],
313
+ "execution_count": null,
314
+ "outputs": []
315
+ },
316
+ {
317
+ "cell_type": "code",
318
+ "metadata": {},
319
+ "source": [
320
+ "golden_feature = feat_importances.index[0]\n",
321
+ "print(f'The Golden Feature is: {golden_feature}')\n",
322
+ "print(f'Importance: {feat_importances.iloc[0]:.4f}')\n"
323
+ ],
324
+ "execution_count": null,
325
+ "outputs": []
326
+ },
327
+ {
328
+ "cell_type": "markdown",
329
+ "metadata": {},
330
+ "source": [
331
+ "# Part 5: Bonus - Retrain with Golden Feature Only\n",
332
+ "\n",
333
+ "\n",
334
+ "\n",
335
+ "**Task:**\n",
336
+ "\n",
337
+ "\n",
338
+ "\n",
339
+ "Now that you've found the golden feature, let's see how powerful it really is!\n",
340
+ "\n",
341
+ "\n",
342
+ "\n",
343
+ "Retrain your CatBoostClassifier using **ONLY the golden feature** and compare its performance to the full model:\n",
344
+ "\n",
345
+ "\n",
346
+ "\n",
347
+ "1. Create new X with only the golden feature\n",
348
+ "\n",
349
+ "2. Run the same KFold loop with this single feature\n",
350
+ "\n",
351
+ "3. Print and compare the accuracy with the full model"
352
+ ]
353
+ },
354
+ {
355
+ "cell_type": "code",
356
+ "metadata": {},
357
+ "source": [
358
+ "from sklearn.model_selection import StratifiedKFold\n",
359
+ "from sklearn.ensemble import RandomForestClassifier\n",
360
+ "from catboost import CatBoostClassifier\n",
361
+ "from sklearn.metrics import f1_score\n",
362
+ "\n",
363
+ "skf = StratifiedKFold(n_splits=5, shuffle=True, random_state=42)\n",
364
+ "model = CatBoostClassifier(n_estimators=100, random_state=42)\n",
365
+ "\n",
366
+ "# Retrain with only the golden feature\n",
367
+ "X_golden = X[[golden_feature]]\n",
368
+ "\n",
369
+ "golden_accuracies = []\n",
370
+ "for train_idx, val_idx in skf.split(X_golden, y):\n",
371
+ " X_train, X_val = X_golden.iloc[train_idx], X_golden.iloc[val_idx]\n",
372
+ " y_train, y_val = y.iloc[train_idx], y.iloc[val_idx]\n",
373
+ " \n",
374
+ " model.fit(X_train, y_train)\n",
375
+ " preds = model.predict(X_val)\n",
376
+ " golden_accuracies.append(f1_score(y_val, preds))\n",
377
+ "\n",
378
+ "print(f'Accuracy with ONLY {golden_feature}: {np.mean(golden_accuracies):.4f}')\n",
379
+ "print(f'Full Model Accuracy: {np.mean(f1):.4f}')\n",
380
+ "print(f'Difference: {np.mean(f1) - np.mean(golden_accuracies):.4f}')\n"
381
+ ],
382
+ "execution_count": null,
383
+ "outputs": []
384
+ }
385
+ ],
386
+ "metadata": {
387
+ "kernelspec": {
388
+ "display_name": "Python 3",
389
+ "name": "python3"
390
+ },
391
+ "language_info": {
392
+ "name": "python"
393
+ }
394
+ },
395
+ "nbformat": 4,
396
+ "nbformat_minor": 0
397
+ }
stage_2_rubrics_ta.md ADDED
@@ -0,0 +1,156 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Stage 2 Practical Exam — Marking Scheme
2
+
3
+ The rubric the TAs graded against, transcribed from the distributed
4
+ `Marking_Scheme.pdf` with the two instructor corrections issued by email
5
+ during grading folded in (both affect Q3 only; they are marked ⚠ below).
6
+ Each student was graded independently by two TAs. Where the PDF's header
7
+ totals disagree with the sum of its own task tables, both numbers are noted.
8
+
9
+ ---
10
+
11
+ ## Q1: Regression — Predict Food Delivery Time
12
+
13
+ Header total: ~25 marks + 3 bonus. Task tables sum to a maximum of 23 + 3 bonus
14
+ (Part 2 is variable, 6–10 nominal).
15
+
16
+ ### Part 1: Read Data (3 marks)
17
+
18
+ | Task | Marks |
19
+ |---|---|
20
+ | 1. Read the dataset using `read_csv()` | 0.5 |
21
+ | 2. Inspect the first few rows using `head()` | 0.5 |
22
+ | 3. Display dataset information using `info()` | 0.5 |
23
+ | 4. Show statistical description using `describe()` | 0.5 |
24
+ | 5. Plot the target distribution (`delivery_time`) | 1.0 |
25
+
26
+ ### Part 2: Data Cleaning (6–10 marks, variable)
27
+
28
+ | Task | Marks | Notes |
29
+ |---|---|---|
30
+ | 1. Drop the `Order_ID` column | 1 | |
31
+ | 2. Handle missing values appropriately | max 4, min −2 | breakdown below |
32
+ | 3. Check and remove duplicates | 1 | |
33
+ | 4. Encode categorical variables | 1–3 | 1 if label encoding, 3 if one-hot |
34
+ | 5. Apply feature scaling (StandardScaler) | 1 | |
35
+ | 6. Check for target imbalance | +1 or −1 | +1 if kept empty / wrote a comment (regression target — imbalance does not apply); −1 if plotted anything |
36
+
37
+ Task 2 breakdown:
38
+
39
+ - Numerical features: filling with mean/median/constant/custom rule **+1**; dropping rows/features with numeric missings **+0.5**
40
+ - Categorical features: filling with mode/constant/custom rule **+1**; dropping rows/features with categorical missings **+0.5**
41
+ - Target: dropping rows with missing target **+2**; not dropping them **−2**
42
+
43
+ ### Part 3: Modeling (6 marks)
44
+
45
+ | Task | Marks |
46
+ |---|---|
47
+ | 1. Split into features (X) and target (y) | 1 |
48
+ | 2. Use the correct split: KFold or StratifiedKFold | 2 |
49
+ | 3. Train a RandomForest model | 1 |
50
+ | 4. Evaluate using MAE only | 1 |
51
+ | 5. Print the averaged score across all folds | 1 |
52
+
53
+ ### Part 4: Plots (3 marks)
54
+
55
+ | Task | Marks |
56
+ |---|---|
57
+ | 1. Plot feature importance from the trained model | 1 |
58
+ | 2. Plot predicted delivery time histogram | 2 |
59
+
60
+ ### Part 5: Bonus — Ensemble (3 marks)
61
+
62
+ Rewrite the KFold loop to train two different models per iteration
63
+ (RandomForestRegressor and CatBoostRegressor), average their predictions,
64
+ and compute MAE on the averaged predictions. **3 marks.**
65
+
66
+ ---
67
+
68
+ ## Q2: PyTorch — Predict Age from Face Images
69
+
70
+ Header total: 16 marks. Task tables sum to 14 + 3 bonus (maximum achievable 17).
71
+ Data loading and preprocessing were provided to students.
72
+
73
+ ### Part 1: Prepare Data for PyTorch (5 marks)
74
+
75
+ | Task | Marks |
76
+ |---|---|
77
+ | 1. Convert the numpy arrays to PyTorch tensors | 1 |
78
+ | 2. Create `train_dataset` / `test_dataset` with `TensorDataset` | 1 |
79
+ | 3. Create DataLoaders with batch size 32 | 1 |
80
+ | 4. Print the shape of one batch from the train loader | 1 |
81
+ | 5. Display a few images with matplotlib | 1 |
82
+
83
+ ### Part 2: Model (8 marks)
84
+
85
+ | Task | Marks |
86
+ |---|---|
87
+ | 1. Create a model class with 4 linear layers | 2 |
88
+ | 2. Create a training loop function | 1 |
89
+ | 3. Create a validation loop function | 2 |
90
+ | 4. Define the device, model, loss function, and optimizer | 2 |
91
+ | 5. Train for 20 epochs, tracking training and validation losses | 1 |
92
+
93
+ ### Part 3: Plots (1 mark + 3 bonus)
94
+
95
+ | Task | Marks |
96
+ |---|---|
97
+ | 1. Plot training and validation loss over epochs | 1 |
98
+ | 2. Bonus: plot predictions with their actual images (predicted vs actual age) | 3 |
99
+
100
+ ---
101
+
102
+ ## Q3: Classification — Find the Golden Feature (anonymized data)
103
+
104
+ Corrected total: 19 marks + 3 bonus (maximum 22). The distributed PDF said
105
+ 22 + 3 bonus with task tables summing to 21 + 3; the two ⚠ corrections below
106
+ were issued by email during grading after inconsistencies were found in the
107
+ student version.
108
+
109
+ ### Part 1: Read Data (2 marks) ⚠
110
+
111
+ | Task | Marks |
112
+ |---|---|
113
+ | 1. Read `Q3_data.csv` using `read_csv()` | 0.5 |
114
+ | 2. Inspect the first few rows using `head()` | 0.5 |
115
+ | 3. Display dataset information using `info()` | 0.5 |
116
+ | 4. Show statistical description using `describe()` | 0.5 |
117
+
118
+ ⚠ Task 5 ("plot the target distribution", 1 mark) was removed by instructor
119
+ correction: inconsistent in the student version; TAs were told to treat
120
+ Part 1 as 4 tasks worth 2 marks.
121
+
122
+ ### Part 2: Data Cleaning (5 marks)
123
+
124
+ | Task | Marks | Notes |
125
+ |---|---|---|
126
+ | 1. Handle missing values appropriately | 1 | any method accepted |
127
+ | 2. Check and remove duplicates | 1 | |
128
+ | 3. Encode categorical variables | 1 | |
129
+ | 4. Apply feature scaling (StandardScaler) | 1 | |
130
+ | 5. Check for target imbalance and state whether it is imbalanced | 1 | |
131
+
132
+ ### Part 3: Modeling (7 marks)
133
+
134
+ | Task | Marks |
135
+ |---|---|
136
+ | 1. Split into features (X) and target (y) | 1 |
137
+ | 2. Use the correct split: KFold or StratifiedKFold | 2 |
138
+ | 3. Train a CatBoostClassifier model | 1 |
139
+ | 4. Evaluate using the appropriate metric only (Accuracy vs. F1) | 2 |
140
+ | 5. Print the averaged score across all folds | 1 |
141
+
142
+ ### Part 4: Find the Golden Feature (5 marks) ⚠
143
+
144
+ | Task | Marks |
145
+ |---|---|
146
+ | 1. Plot feature importance from the trained model | 2 |
147
+ | 2. Identify and print the most important feature (the "golden feature") | 3 |
148
+
149
+ ⚠ Task 3 ("plot the distribution of predictions", 1 mark) was removed by
150
+ instructor correction; TAs were told to grade Part 4 out of 5 marks.
151
+
152
+ ### Part 5: Bonus — Retrain with the Golden Feature Only (3 marks)
153
+
154
+ Retrain the CatBoostClassifier using only the golden feature: build the
155
+ single-feature X, run the same KFold loop, and print and compare accuracy
156
+ with the full model. **3 marks.**
submissions_extracted/1/Q1.ipynb ADDED
@@ -0,0 +1,286 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "metadata": {},
6
+ "source": [
7
+ "import kagglehub\n",
8
+ "import numpy as np\n",
9
+ "import pandas as pd\n",
10
+ "import matplotlib.pyplot as plt\n",
11
+ "import os\n",
12
+ "import kagglehub\n",
13
+ "import seaborn as sns\n",
14
+ "from sklearn.model_selection import train_test_split, KFold\n",
15
+ "from sklearn.preprocessing import StandardScaler, LabelEncoder\n",
16
+ "from sklearn.ensemble import RandomForestRegressor\n",
17
+ "from sklearn.metrics import mean_absolute_error, mean_squared_error\n",
18
+ "from tqdm import tqdm\n",
19
+ "from sklearn.tree import DecisionTreeRegressor\n",
20
+ "from sklearn.ensemble import RandomForestRegressor, GradientBoostingRegressor\n",
21
+ "\n",
22
+ "%matplotlib inline\n",
23
+ "import warnings\n",
24
+ "warnings.filterwarnings('ignore')\n",
25
+ "# Download latest version\n",
26
+ "path = kagglehub.dataset_download(\"ANON_OWNER/q1-exam-data\")\n",
27
+ "\n",
28
+ "print(\"Path to dataset files:\", path)"
29
+ ],
30
+ "execution_count": null,
31
+ "outputs": []
32
+ },
33
+ {
34
+ "cell_type": "code",
35
+ "metadata": {},
36
+ "source": [
37
+ "\n",
38
+ "# Task 1: Write your code here:\n",
39
+ "delev_path = os.path.join(path, 'Q1_data.csv')\n",
40
+ "df = pd.read_csv(delev_path)\n",
41
+ "print(f\"Dataset shape: {df.shape}\")\n"
42
+ ],
43
+ "execution_count": null,
44
+ "outputs": []
45
+ },
46
+ {
47
+ "cell_type": "code",
48
+ "metadata": {},
49
+ "source": [
50
+ "# Task 2: Write your code here:\n",
51
+ "df.head()"
52
+ ],
53
+ "execution_count": null,
54
+ "outputs": []
55
+ },
56
+ {
57
+ "cell_type": "code",
58
+ "metadata": {},
59
+ "source": [
60
+ "# Task 3: Write your code here:\n",
61
+ "df.info()"
62
+ ],
63
+ "execution_count": null,
64
+ "outputs": []
65
+ },
66
+ {
67
+ "cell_type": "code",
68
+ "metadata": {},
69
+ "source": [
70
+ "# Task 4: Write your code here:\n",
71
+ "df.describe()"
72
+ ],
73
+ "execution_count": null,
74
+ "outputs": []
75
+ },
76
+ {
77
+ "cell_type": "code",
78
+ "metadata": {},
79
+ "source": [
80
+ "# Task 5: Write your code here:\n",
81
+ "plt.figure(figsize=(10, 5))\n",
82
+ "plt.hist(df['Delivery_Time'].dropna(), bins=30, edgecolor='black')\n",
83
+ "plt.title('Delivery_Time')\n",
84
+ "plt.xlabel('time taken')\n",
85
+ "plt.ylabel('Frequency')\n",
86
+ "plt.show()"
87
+ ],
88
+ "execution_count": null,
89
+ "outputs": []
90
+ },
91
+ {
92
+ "cell_type": "code",
93
+ "metadata": {},
94
+ "source": [
95
+ "# Task 1: Write your code here:\n",
96
+ "col = ['Distance_km','Weather','Traffic_Level', 'Time_of_Day','Vehicle_Type' , 'Preparation_Time_min','Courier_Experience_yrs']\n",
97
+ "target_column = \"Delivery_Time\"\n",
98
+ "X = df.drop(target_column , axis =1).copy()\n",
99
+ "y = df[target_column].copy()\n"
100
+ ],
101
+ "execution_count": null,
102
+ "outputs": []
103
+ },
104
+ {
105
+ "cell_type": "code",
106
+ "metadata": {},
107
+ "source": [
108
+ "# Task 2: Write your code here:\n",
109
+ "df_clean = df[col].copy()\n",
110
+ "f_clean = df.dropna(subset=['Distance_km','Weather','Traffic_Level', 'Time_of_Day','Vehicle_Type' , 'Preparation_Time_min','Courier_Experience_yrs'])"
111
+ ],
112
+ "execution_count": null,
113
+ "outputs": []
114
+ },
115
+ {
116
+ "cell_type": "code",
117
+ "metadata": {},
118
+ "source": [],
119
+ "execution_count": null,
120
+ "outputs": []
121
+ },
122
+ {
123
+ "cell_type": "code",
124
+ "metadata": {},
125
+ "source": [
126
+ "# Task 3: Write your code here:\n",
127
+ "label_encoder = LabelEncoder()\n",
128
+ "for col in df_clean.select_dtypes(include=[\"object\"]).columns:\n",
129
+ " X[col] = label_encoder.fit_transform(X[col])"
130
+ ],
131
+ "execution_count": null,
132
+ "outputs": []
133
+ },
134
+ {
135
+ "cell_type": "code",
136
+ "metadata": {},
137
+ "source": [
138
+ "# Task 4: Write your code here:\n",
139
+ "scaler = StandardScaler()\n",
140
+ "X_scaled = scaler.fit_transform(X)"
141
+ ],
142
+ "execution_count": null,
143
+ "outputs": []
144
+ },
145
+ {
146
+ "cell_type": "code",
147
+ "metadata": {},
148
+ "source": [
149
+ "# Task 5: Write your code here:\n",
150
+ "\n",
151
+ "# Show full dataset class distribution\n",
152
+ "full_ratio = (y.value_counts(normalize=True) * 100).sort_index()\n",
153
+ "print(\"Full Dataset Class Distribution\")\n",
154
+ "print(\" y class percentages:\", {k: f\"{v:.2f}%\" for k, v in full_ratio.items()})\n",
155
+ "print(\"-\" * 40)\n"
156
+ ],
157
+ "execution_count": null,
158
+ "outputs": []
159
+ },
160
+ {
161
+ "cell_type": "code",
162
+ "metadata": {},
163
+ "source": [
164
+ "# Task 6: Write your code here:"
165
+ ],
166
+ "execution_count": null,
167
+ "outputs": []
168
+ },
169
+ {
170
+ "cell_type": "code",
171
+ "metadata": {},
172
+ "source": [
173
+ "# Task 1: Write your code here:\n"
174
+ ],
175
+ "execution_count": null,
176
+ "outputs": []
177
+ },
178
+ {
179
+ "cell_type": "code",
180
+ "metadata": {},
181
+ "source": [
182
+ "# Task 2,3,4,5: Write your code here:\n",
183
+ "from sklearn.metrics import accuracy_score, precision_score, recall_score, f1_score\n",
184
+ "\n",
185
+ "from sklearn.tree import DecisionTreeRegressor\n",
186
+ "from sklearn.ensemble import RandomForestRegressor, GradientBoostingRegressor\n",
187
+ "from sklearn.datasets import make_regression\n",
188
+ "kf = KFold(n_splits=5, shuffle=True, random_state=42)\n",
189
+ "\n",
190
+ "# Iterate through folds\n",
191
+ "for fold, (train_idx, test_idx) in enumerate(kf.split(X), start=1):\n",
192
+ " # indexing for each fold\n",
193
+ " X_train, X_test = X.iloc[train_idx], X.iloc[test_idx]\n",
194
+ " y_train, y_test = y.iloc[train_idx], y.iloc[test_idx]\n",
195
+ " # print shapes\n",
196
+ " print(f\"Fold {fold}\")\n",
197
+ " print(\" X_train shape:\", X_train.shape)\n",
198
+ " print(\" X_test shape :\", X_test.shape)\n",
199
+ " print(\" y_train shape:\", y_train.shape)\n",
200
+ " print(\" y_test shape :\", y_test.shape)\n",
201
+ " print(\"-\" * 30)\n",
202
+ "\n",
203
+ "\n",
204
+ "\n",
205
+ "X, y = make_regression(n_samples=1000, n_features=10, noise=10, random_state=42)\n",
206
+ "X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)\n",
207
+ "\n",
208
+ "# 1. Decision Tree\n",
209
+ "dt = DecisionTreeRegressor(max_depth=5, random_state=42)\n",
210
+ "dt.fit(X_train, y_train)\n",
211
+ "print(\"Decision Tree R²:\", dt.score(X_test, y_test))\n",
212
+ "\n",
213
+ "# 2. Random Forest\n",
214
+ "rf = RandomForestRegressor(n_estimators=100, max_depth=5, random_state=42)\n",
215
+ "rf.fit(X_train, y_train)\n",
216
+ "print(\"Random Forest R²:\", rf.score(X_test, y_test))\n",
217
+ "\n",
218
+ "# 3. Gradient Boosting\n",
219
+ "gb = GradientBoostingRegressor(n_estimators=100, learning_rate=0.1,\n",
220
+ " max_depth=3, random_state=42)\n",
221
+ "gb.fit(X_train, y_train)\n",
222
+ "print(\"Gradient Boosting R²:\", gb.score(X_test, y_test))\n",
223
+ "\n",
224
+ "# Feature importance\n",
225
+ "print(\"\\nTop 3 important features (Random Forest):\")\n",
226
+ "importances = rf.feature_importances_\n",
227
+ "for i in np.argsort(importances)[-3:][::-1]:\n",
228
+ " print(f\" Feature {i}: {importances[i]:.3f}\")\n",
229
+ "\n",
230
+ ""
231
+ ],
232
+ "execution_count": null,
233
+ "outputs": []
234
+ },
235
+ {
236
+ "cell_type": "code",
237
+ "metadata": {},
238
+ "source": [
239
+ "# Task 1: Write your code here:\n",
240
+ "col\n",
241
+ "feature_importance = pd.DataFrame({\n",
242
+ " 'feature': col,\n",
243
+ " 'importance': dt.feature_importances_\n",
244
+ "}).sort_values('importance', ascending=False)\n",
245
+ "\n",
246
+ "plt.figure(figsize=(10, 6))\n",
247
+ "plt.barh(feature_importance['feature'], feature_importance['importance'])\n",
248
+ "plt.xlabel('Importance')\n",
249
+ "plt.title('Feature Importance')\n",
250
+ "plt.gca().invert_yaxis()\n",
251
+ "plt.show()"
252
+ ],
253
+ "execution_count": null,
254
+ "outputs": []
255
+ },
256
+ {
257
+ "cell_type": "code",
258
+ "metadata": {},
259
+ "source": [
260
+ "# Task 2: Write your code here:"
261
+ ],
262
+ "execution_count": null,
263
+ "outputs": []
264
+ },
265
+ {
266
+ "cell_type": "code",
267
+ "metadata": {},
268
+ "source": [
269
+ "# Task Bonus: Write your code here:"
270
+ ],
271
+ "execution_count": null,
272
+ "outputs": []
273
+ }
274
+ ],
275
+ "metadata": {
276
+ "kernelspec": {
277
+ "display_name": "Python 3",
278
+ "name": "python3"
279
+ },
280
+ "language_info": {
281
+ "name": "python"
282
+ }
283
+ },
284
+ "nbformat": 4,
285
+ "nbformat_minor": 0
286
+ }
submissions_extracted/1/Q3.ipynb ADDED
@@ -0,0 +1,190 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "metadata": {},
6
+ "source": [
7
+ "import kagglehub\n",
8
+ "import kagglehub\n",
9
+ "import numpy as np\n",
10
+ "import pandas as pd\n",
11
+ "import matplotlib.pyplot as plt\n",
12
+ "import os\n",
13
+ "import kagglehub\n",
14
+ "import seaborn as sns\n",
15
+ "from sklearn.model_selection import train_test_split, KFold\n",
16
+ "from sklearn.preprocessing import StandardScaler, LabelEncoder\n",
17
+ "from sklearn.ensemble import RandomForestRegressor\n",
18
+ "from sklearn.metrics import mean_absolute_error, mean_squared_error\n",
19
+ "from tqdm import tqdm\n",
20
+ "from sklearn.tree import DecisionTreeRegressor\n",
21
+ "from sklearn.ensemble import RandomForestRegressor, GradientBoostingRegressor\n",
22
+ "\n",
23
+ "import pandas as pd\n",
24
+ "import numpy as np\n",
25
+ "import torch\n",
26
+ "import torch.nn as nn\n",
27
+ "from torch.optim import AdamW\n",
28
+ "import matplotlib.pyplot as plt\n",
29
+ "from torch.utils.data import DataLoader, TensorDataset\n",
30
+ "from sklearn.model_selection import train_test_split\n",
31
+ "from sklearn.preprocessing import StandardScaler, LabelEncoder\n",
32
+ "from sklearn.metrics import mean_absolute_error, mean_squared_error, r2_score\n",
33
+ "\n",
34
+ "\n",
35
+ "# Download latest version\n",
36
+ "\n",
37
+ "path = kagglehub.dataset_download(\"ANON_OWNER/q3-exam-data\")\n",
38
+ "\n",
39
+ "\n",
40
+ "\n",
41
+ "print(\"Path to dataset files:\", path)"
42
+ ],
43
+ "execution_count": null,
44
+ "outputs": []
45
+ },
46
+ {
47
+ "cell_type": "code",
48
+ "metadata": {},
49
+ "source": [
50
+ "# Task 1: Write your code here:\n",
51
+ "path1= os.path.join(path, 'Q3_data.csv')\n",
52
+ "df = pd.read_csv(path1)\n",
53
+ "print(f\"Dataset shape: {df.shape}\")"
54
+ ],
55
+ "execution_count": null,
56
+ "outputs": []
57
+ },
58
+ {
59
+ "cell_type": "code",
60
+ "metadata": {},
61
+ "source": [
62
+ "# Task 2: Write your code here:\n",
63
+ "df.head()"
64
+ ],
65
+ "execution_count": null,
66
+ "outputs": []
67
+ },
68
+ {
69
+ "cell_type": "code",
70
+ "metadata": {},
71
+ "source": [
72
+ "# Task 3: Write your code here:\n",
73
+ "df.info()"
74
+ ],
75
+ "execution_count": null,
76
+ "outputs": []
77
+ },
78
+ {
79
+ "cell_type": "code",
80
+ "metadata": {},
81
+ "source": [
82
+ "# Task 4: Write your code here:\n",
83
+ "df.describe()"
84
+ ],
85
+ "execution_count": null,
86
+ "outputs": []
87
+ },
88
+ {
89
+ "cell_type": "code",
90
+ "metadata": {},
91
+ "source": [
92
+ "# Task 1: Write your code here:\n"
93
+ ],
94
+ "execution_count": null,
95
+ "outputs": []
96
+ },
97
+ {
98
+ "cell_type": "code",
99
+ "metadata": {},
100
+ "source": [
101
+ "# Task 2: Write your code here:"
102
+ ],
103
+ "execution_count": null,
104
+ "outputs": []
105
+ },
106
+ {
107
+ "cell_type": "code",
108
+ "metadata": {},
109
+ "source": [
110
+ "# Task 3: Write your code here:"
111
+ ],
112
+ "execution_count": null,
113
+ "outputs": []
114
+ },
115
+ {
116
+ "cell_type": "code",
117
+ "metadata": {},
118
+ "source": [
119
+ "# Task 4: Write your code here:"
120
+ ],
121
+ "execution_count": null,
122
+ "outputs": []
123
+ },
124
+ {
125
+ "cell_type": "code",
126
+ "metadata": {},
127
+ "source": [
128
+ "# Task 5: Write your code here:"
129
+ ],
130
+ "execution_count": null,
131
+ "outputs": []
132
+ },
133
+ {
134
+ "cell_type": "code",
135
+ "metadata": {},
136
+ "source": [
137
+ "# Task 1: Write your code here:"
138
+ ],
139
+ "execution_count": null,
140
+ "outputs": []
141
+ },
142
+ {
143
+ "cell_type": "code",
144
+ "metadata": {},
145
+ "source": [
146
+ "# Task 2,3,4,5: Write your code here:"
147
+ ],
148
+ "execution_count": null,
149
+ "outputs": []
150
+ },
151
+ {
152
+ "cell_type": "code",
153
+ "metadata": {},
154
+ "source": [
155
+ "# Task 1: Write your code here:"
156
+ ],
157
+ "execution_count": null,
158
+ "outputs": []
159
+ },
160
+ {
161
+ "cell_type": "code",
162
+ "metadata": {},
163
+ "source": [
164
+ "# Task 2: Write your code here:"
165
+ ],
166
+ "execution_count": null,
167
+ "outputs": []
168
+ },
169
+ {
170
+ "cell_type": "code",
171
+ "metadata": {},
172
+ "source": [
173
+ "# Task Bonus: Write your code here:"
174
+ ],
175
+ "execution_count": null,
176
+ "outputs": []
177
+ }
178
+ ],
179
+ "metadata": {
180
+ "kernelspec": {
181
+ "display_name": "Python 3",
182
+ "name": "python3"
183
+ },
184
+ "language_info": {
185
+ "name": "python"
186
+ }
187
+ },
188
+ "nbformat": 4,
189
+ "nbformat_minor": 0
190
+ }
submissions_extracted/10/Q1.ipynb ADDED
@@ -0,0 +1,280 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "metadata": {},
6
+ "source": [
7
+ "import kagglehub\n",
8
+ "\n",
9
+ "# Download latest version\n",
10
+ "path = kagglehub.dataset_download(\"ANON_OWNER/q1-exam-data\")\n",
11
+ "\n",
12
+ "print(\"Path to dataset files:\", path)"
13
+ ],
14
+ "execution_count": null,
15
+ "outputs": []
16
+ },
17
+ {
18
+ "cell_type": "code",
19
+ "metadata": {},
20
+ "source": [
21
+ "# Task 1: Read the dataset\n",
22
+ "import pandas as pd\n",
23
+ "import matplotlib.pyplot as plt\n",
24
+ "import seaborn as sns\n",
25
+ "import numpy as np\n",
26
+ "\n",
27
+ "df = pd.read_csv(f\"{path}/Q1_data.csv\")"
28
+ ],
29
+ "execution_count": null,
30
+ "outputs": []
31
+ },
32
+ {
33
+ "cell_type": "code",
34
+ "metadata": {},
35
+ "source": [
36
+ "# Task 2: Inspect the first few rows\n",
37
+ "df.head()"
38
+ ],
39
+ "execution_count": null,
40
+ "outputs": []
41
+ },
42
+ {
43
+ "cell_type": "code",
44
+ "metadata": {},
45
+ "source": [
46
+ "# Task 3: Display dataset information\n",
47
+ "df.info()"
48
+ ],
49
+ "execution_count": null,
50
+ "outputs": []
51
+ },
52
+ {
53
+ "cell_type": "code",
54
+ "metadata": {},
55
+ "source": [
56
+ "# Task 4: Show statistical description\n",
57
+ "df.describe()"
58
+ ],
59
+ "execution_count": null,
60
+ "outputs": []
61
+ },
62
+ {
63
+ "cell_type": "code",
64
+ "metadata": {},
65
+ "source": [
66
+ "# Task 5: Plot the target distribution\n",
67
+ "plt.figure(figsize=(8, 5))\n",
68
+ "plt.hist(df['Delivery_Time'], bins=30, edgecolor='black')\n",
69
+ "plt.title('Distribution of Delivery Time')\n",
70
+ "plt.xlabel('Delivery Time (minutes)')\n",
71
+ "plt.ylabel('Frequency')\n",
72
+ "plt.show()"
73
+ ],
74
+ "execution_count": null,
75
+ "outputs": []
76
+ },
77
+ {
78
+ "cell_type": "code",
79
+ "metadata": {},
80
+ "source": [
81
+ "# Task 1: Drop the 'Order_ID' column\n",
82
+ "df = df.drop('Order_ID', axis=1)"
83
+ ],
84
+ "execution_count": null,
85
+ "outputs": []
86
+ },
87
+ {
88
+ "cell_type": "code",
89
+ "metadata": {},
90
+ "source": [
91
+ "# Task 2: Handle missing values\n",
92
+ "print(df.isnull().sum())\n",
93
+ "\n",
94
+ "for col in df.columns:\n",
95
+ " if df[col].isnull().sum() > 0:\n",
96
+ " if df[col].dtype == 'object':\n",
97
+ " df[col] = df[col].fillna(df[col].mode()[0])\n",
98
+ " else:\n",
99
+ " df[col] = df[col].fillna(df[col].median())"
100
+ ],
101
+ "execution_count": null,
102
+ "outputs": []
103
+ },
104
+ {
105
+ "cell_type": "code",
106
+ "metadata": {},
107
+ "source": [
108
+ "# Task 3: Check and remove duplicates\n",
109
+ "print(f\"Duplicates before: {df.duplicated().sum()}\")\n",
110
+ "df = df.drop_duplicates()\n",
111
+ "print(f\"Duplicates after: {df.duplicated().sum()}\")"
112
+ ],
113
+ "execution_count": null,
114
+ "outputs": []
115
+ },
116
+ {
117
+ "cell_type": "code",
118
+ "metadata": {},
119
+ "source": [
120
+ "# Task 4: Encode categorical variables (One Hot Encoding)\n",
121
+ "categorical_cols = df.select_dtypes(include=['object']).columns.tolist()\n",
122
+ "df = pd.get_dummies(df, columns=categorical_cols, drop_first=True)"
123
+ ],
124
+ "execution_count": null,
125
+ "outputs": []
126
+ },
127
+ {
128
+ "cell_type": "code",
129
+ "metadata": {},
130
+ "source": [
131
+ "# Task 5: Apply feature scaling (StandardScaler)\n",
132
+ "from sklearn.preprocessing import StandardScaler\n",
133
+ "\n",
134
+ "X = df.drop('Delivery_Time', axis=1)\n",
135
+ "y = df['Delivery_Time']\n",
136
+ "\n",
137
+ "scaler = StandardScaler()\n",
138
+ "X_scaled = pd.DataFrame(scaler.fit_transform(X), columns=X.columns)"
139
+ ],
140
+ "execution_count": null,
141
+ "outputs": []
142
+ },
143
+ {
144
+ "cell_type": "code",
145
+ "metadata": {},
146
+ "source": [
147
+ "# Task 6: Write your code here:"
148
+ ],
149
+ "execution_count": null,
150
+ "outputs": []
151
+ },
152
+ {
153
+ "cell_type": "code",
154
+ "metadata": {},
155
+ "source": [
156
+ "# Task 1: Write your code here:"
157
+ ],
158
+ "execution_count": null,
159
+ "outputs": []
160
+ },
161
+ {
162
+ "cell_type": "code",
163
+ "metadata": {},
164
+ "source": [
165
+ "# Task 2, 3, 4, 5: KFold, RandomForest, MAE, Print averaged score\n",
166
+ "from sklearn.model_selection import KFold\n",
167
+ "from sklearn.ensemble import RandomForestRegressor\n",
168
+ "from sklearn.metrics import mean_absolute_error\n",
169
+ "\n",
170
+ "kfold = KFold(n_splits=5, shuffle=True, random_state=42)\n",
171
+ "\n",
172
+ "mae_scores = []\n",
173
+ "model = None\n",
174
+ "\n",
175
+ "for train_idx, val_idx in kfold.split(X_scaled):\n",
176
+ " X_train, X_val = X_scaled.iloc[train_idx], X_scaled.iloc[val_idx]\n",
177
+ " y_train, y_val = y.iloc[train_idx], y.iloc[val_idx]\n",
178
+ "\n",
179
+ " model = RandomForestRegressor(n_estimators=100, random_state=42)\n",
180
+ " model.fit(X_train, y_train)\n",
181
+ "\n",
182
+ " y_pred = model.predict(X_val)\n",
183
+ " mae = mean_absolute_error(y_val, y_pred)\n",
184
+ " mae_scores.append(mae)\n",
185
+ "\n",
186
+ "print(f\"MAE Scores per fold: {mae_scores}\")\n",
187
+ "print(f\"Average MAE: {np.mean(mae_scores):.4f}\")"
188
+ ],
189
+ "execution_count": null,
190
+ "outputs": []
191
+ },
192
+ {
193
+ "cell_type": "code",
194
+ "metadata": {},
195
+ "source": [
196
+ "# Task 1: Plot feature importance\n",
197
+ "feature_importance = model.feature_importances_\n",
198
+ "feature_names = X_scaled.columns\n",
199
+ "\n",
200
+ "sorted_idx = np.argsort(feature_importance)\n",
201
+ "\n",
202
+ "plt.figure(figsize=(10, 8))\n",
203
+ "plt.barh(range(len(sorted_idx)), feature_importance[sorted_idx])\n",
204
+ "plt.yticks(range(len(sorted_idx)), feature_names[sorted_idx])\n",
205
+ "plt.xlabel('Feature Importance')\n",
206
+ "plt.title('Random Forest Feature Importance')\n",
207
+ "plt.tight_layout()\n",
208
+ "plt.show()"
209
+ ],
210
+ "execution_count": null,
211
+ "outputs": []
212
+ },
213
+ {
214
+ "cell_type": "code",
215
+ "metadata": {},
216
+ "source": [
217
+ "# Task 2: Plot predicted delivery time histogram\n",
218
+ "model_final = RandomForestRegressor(n_estimators=100, random_state=42)\n",
219
+ "model_final.fit(X_scaled, y)\n",
220
+ "y_pred_all = model_final.predict(X_scaled)\n",
221
+ "\n",
222
+ "plt.figure(figsize=(8, 5))\n",
223
+ "plt.hist(y_pred_all, bins=30, edgecolor='black', alpha=0.7)\n",
224
+ "plt.title('Predicted Delivery Time Distribution')\n",
225
+ "plt.xlabel('Predicted Delivery Time (minutes)')\n",
226
+ "plt.ylabel('Frequency')\n",
227
+ "plt.show()"
228
+ ],
229
+ "execution_count": null,
230
+ "outputs": []
231
+ },
232
+ {
233
+ "cell_type": "code",
234
+ "metadata": {},
235
+ "source": [
236
+ "from sklearn.ensemble import RandomForestRegressor\n",
237
+ "from catboost import CatBoostRegressor\n",
238
+ "\n",
239
+ "kfold = KFold(n_splits=5, shuffle=True, random_state=42)\n",
240
+ "ensemble_mae_scores = []\n",
241
+ "\n",
242
+ "for train_idx, val_idx in kfold.split(X_scaled):\n",
243
+ " X_train, X_val = X_scaled.iloc[train_idx], X_scaled.iloc[val_idx]\n",
244
+ " y_train, y_val = y.iloc[train_idx], y.iloc[val_idx]\n",
245
+ "\n",
246
+ " # Model 1: RandomForest\n",
247
+ " rf_model = RandomForestRegressor(n_estimators=100, random_state=42)\n",
248
+ " rf_model.fit(X_train, y_train)\n",
249
+ " rf_pred = rf_model.predict(X_val)\n",
250
+ "\n",
251
+ " # Model 2: CatBoost\n",
252
+ " cb_model = CatBoostRegressor(iterations=100, random_state=42, verbose=0)\n",
253
+ " cb_model.fit(X_train, y_train)\n",
254
+ " cb_pred = cb_model.predict(X_val)\n",
255
+ "\n",
256
+ " # Average predictions\n",
257
+ " ensemble_pred = (rf_pred + cb_pred) / 2\n",
258
+ "\n",
259
+ " mae = mean_absolute_error(y_val, ensemble_pred)\n",
260
+ " ensemble_mae_scores.append(mae)\n",
261
+ "\n",
262
+ "print(f\"Ensemble MAE Scores per fold: {ensemble_mae_scores}\")\n",
263
+ "print(f\"Ensemble Average MAE: {np.mean(ensemble_mae_scores):.4f}\")"
264
+ ],
265
+ "execution_count": null,
266
+ "outputs": []
267
+ }
268
+ ],
269
+ "metadata": {
270
+ "kernelspec": {
271
+ "display_name": "Python 3",
272
+ "name": "python3"
273
+ },
274
+ "language_info": {
275
+ "name": "python"
276
+ }
277
+ },
278
+ "nbformat": 4,
279
+ "nbformat_minor": 0
280
+ }
submissions_extracted/10/Q2.ipynb ADDED
@@ -0,0 +1,323 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "metadata": {},
6
+ "source": [
7
+ "import kagglehub\n",
8
+ "\n",
9
+ "# Download latest version\n",
10
+ "path = kagglehub.dataset_download(\"ANON_OWNER/q2-exam-data\")\n",
11
+ "\n",
12
+ "print(\"Path to dataset files:\", path)"
13
+ ],
14
+ "execution_count": null,
15
+ "outputs": []
16
+ },
17
+ {
18
+ "cell_type": "code",
19
+ "metadata": {},
20
+ "source": [
21
+ "import os\n",
22
+ "import pandas as pd\n",
23
+ "import numpy as np\n",
24
+ "from PIL import Image\n",
25
+ "from sklearn.model_selection import train_test_split\n",
26
+ "\n",
27
+ "# Load Labels\n",
28
+ "labels_df = pd.read_csv(os.path.join(path, \"labels.csv\"))\n",
29
+ "img_dir = os.path.join(path, \"images\")\n",
30
+ "\n",
31
+ "images = []\n",
32
+ "ages = []\n",
33
+ "\n",
34
+ "# Load Images and Resize\n",
35
+ "print(\"Loading images...\")\n",
36
+ "for index, row in labels_df.iterrows():\n",
37
+ " img_name = row.iloc[0]\n",
38
+ " age = row.iloc[1]\n",
39
+ " img_path = os.path.join(img_dir, img_name)\n",
40
+ "\n",
41
+ " if os.path.exists(img_path):\n",
42
+ " img = Image.open(img_path).convert('RGB')\n",
43
+ " img_array = np.array(img) / 255.0 # Normalize pixel values to [0, 1]\n",
44
+ " images.append(img_array)\n",
45
+ " ages.append(age)\n",
46
+ "\n",
47
+ "X = np.array(images)\n",
48
+ "y = np.array(ages)\n",
49
+ "\n",
50
+ "# Transpose image dimensions to match PyTorch format (N, C, H, W)\n",
51
+ "X = np.transpose(X, (0, 3, 1, 2))\n",
52
+ "\n",
53
+ "# Split Data\n",
54
+ "X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)\n",
55
+ "\n",
56
+ "print(f\"X_train shape: {X_train.shape}\")\n",
57
+ "print(f\"X_test shape: {X_test.shape}\")\n",
58
+ "print(f\"y_train shape: {y_train.shape}\")\n",
59
+ "print(f\"y_test shape: {y_test.shape}\")"
60
+ ],
61
+ "execution_count": null,
62
+ "outputs": []
63
+ },
64
+ {
65
+ "cell_type": "code",
66
+ "metadata": {},
67
+ "source": [
68
+ "# 1. Convert Numpy arrays to PyTorch Tensors\n",
69
+ "import torch\n",
70
+ "from torch.utils.data import TensorDataset, DataLoader\n",
71
+ "\n",
72
+ "X_train_tensor = torch.tensor(X_train, dtype=torch.float32)\n",
73
+ "X_test_tensor = torch.tensor(X_test, dtype=torch.float32)\n",
74
+ "y_train_tensor = torch.tensor(y_train, dtype=torch.float32)\n",
75
+ "y_test_tensor = torch.tensor(y_test, dtype=torch.float32)"
76
+ ],
77
+ "execution_count": null,
78
+ "outputs": []
79
+ },
80
+ {
81
+ "cell_type": "code",
82
+ "metadata": {},
83
+ "source": [
84
+ "# 2. Create TensorDataset objects\n",
85
+ "train_dataset = TensorDataset(X_train_tensor, y_train_tensor)\n",
86
+ "test_dataset = TensorDataset(X_test_tensor, y_test_tensor)"
87
+ ],
88
+ "execution_count": null,
89
+ "outputs": []
90
+ },
91
+ {
92
+ "cell_type": "code",
93
+ "metadata": {},
94
+ "source": [
95
+ "# 3. Create DataLoaders\n",
96
+ "batch_size = 32\n",
97
+ "train_loader = DataLoader(train_dataset, batch_size=batch_size, shuffle=True)\n",
98
+ "test_loader = DataLoader(test_dataset, batch_size=batch_size, shuffle=False)"
99
+ ],
100
+ "execution_count": null,
101
+ "outputs": []
102
+ },
103
+ {
104
+ "cell_type": "code",
105
+ "metadata": {},
106
+ "source": [
107
+ "# 4. Print shape of one batch\n",
108
+ "for images, labels in train_loader:\n",
109
+ " print(f\"Batch images shape: {images.shape}\")\n",
110
+ " print(f\"Batch labels shape: {labels.shape}\")\n",
111
+ " break"
112
+ ],
113
+ "execution_count": null,
114
+ "outputs": []
115
+ },
116
+ {
117
+ "cell_type": "code",
118
+ "metadata": {},
119
+ "source": [
120
+ "# 5. Display sample images\n",
121
+ "import matplotlib.pyplot as plt\n",
122
+ "\n",
123
+ "fig, axes = plt.subplots(1, 5, figsize=(15, 3))\n",
124
+ "for i in range(5):\n",
125
+ " img = X_train[i].transpose(1, 2, 0) # Convert from (C, H, W) to (H, W, C)\n",
126
+ " axes[i].imshow(img)\n",
127
+ " axes[i].set_title(f\"Age: {y_train[i]}\")\n",
128
+ " axes[i].axis('off')\n",
129
+ "plt.tight_layout()\n",
130
+ "plt.show()"
131
+ ],
132
+ "execution_count": null,
133
+ "outputs": []
134
+ },
135
+ {
136
+ "cell_type": "code",
137
+ "metadata": {},
138
+ "source": [
139
+ "# Task 1: Model class with 4 linear layers\n",
140
+ "import torch.nn as nn\n",
141
+ "\n",
142
+ "class AgePredictor(nn.Module):\n",
143
+ " def __init__(self, input_size):\n",
144
+ " super(AgePredictor, self).__init__()\n",
145
+ " self.flatten = nn.Flatten()\n",
146
+ " self.layer1 = nn.Linear(input_size, 512)\n",
147
+ " self.layer2 = nn.Linear(512, 256)\n",
148
+ " self.layer3 = nn.Linear(256, 64)\n",
149
+ " self.layer4 = nn.Linear(64, 1)\n",
150
+ " self.relu = nn.ReLU()\n",
151
+ "\n",
152
+ " def forward(self, x):\n",
153
+ " x = self.flatten(x)\n",
154
+ " x = self.relu(self.layer1(x))\n",
155
+ " x = self.relu(self.layer2(x))\n",
156
+ " x = self.relu(self.layer3(x))\n",
157
+ " x = self.layer4(x)\n",
158
+ " return x.squeeze()"
159
+ ],
160
+ "execution_count": null,
161
+ "outputs": []
162
+ },
163
+ {
164
+ "cell_type": "code",
165
+ "metadata": {},
166
+ "source": [
167
+ "# Task 2: Training loop function\n",
168
+ "def train_one_epoch(model, optimizer, criterion, train_loader, device):\n",
169
+ " model.train()\n",
170
+ " running_loss = 0.0\n",
171
+ "\n",
172
+ " for X_batch, y_batch in train_loader:\n",
173
+ " X_batch = X_batch.to(device)\n",
174
+ " y_batch = y_batch.to(device)\n",
175
+ "\n",
176
+ " # Forward pass\n",
177
+ " outputs = model(X_batch)\n",
178
+ " loss = criterion(outputs, y_batch)\n",
179
+ "\n",
180
+ " # Backward pass\n",
181
+ " optimizer.zero_grad()\n",
182
+ " loss.backward()\n",
183
+ " optimizer.step()\n",
184
+ "\n",
185
+ " running_loss += loss.item()\n",
186
+ "\n",
187
+ " avg_loss = running_loss / len(train_loader)\n",
188
+ " return avg_loss"
189
+ ],
190
+ "execution_count": null,
191
+ "outputs": []
192
+ },
193
+ {
194
+ "cell_type": "code",
195
+ "metadata": {},
196
+ "source": [
197
+ "# Task 3: Validation loop function\n",
198
+ "def validate(model, criterion, test_loader, device):\n",
199
+ " model.eval()\n",
200
+ " running_loss = 0.0\n",
201
+ "\n",
202
+ " with torch.no_grad():\n",
203
+ " for X_batch, y_batch in test_loader:\n",
204
+ " X_batch = X_batch.to(device)\n",
205
+ " y_batch = y_batch.to(device)\n",
206
+ "\n",
207
+ " outputs = model(X_batch)\n",
208
+ " loss = criterion(outputs, y_batch)\n",
209
+ " running_loss += loss.item()\n",
210
+ "\n",
211
+ " avg_loss = running_loss / len(test_loader)\n",
212
+ " return avg_loss"
213
+ ],
214
+ "execution_count": null,
215
+ "outputs": []
216
+ },
217
+ {
218
+ "cell_type": "code",
219
+ "metadata": {},
220
+ "source": [
221
+ "# Task 4: Define device, model, loss, optimizer\n",
222
+ "device = torch.device(\"cuda\" if torch.cuda.is_available() else \"cpu\")\n",
223
+ "print(f\"Using device: {device}\")\n",
224
+ "\n",
225
+ "# Calculate input size: C * H * W\n",
226
+ "input_size = X_train.shape[1] * X_train.shape[2] * X_train.shape[3]\n",
227
+ "print(f\"Input size: {input_size}\")\n",
228
+ "\n",
229
+ "model = AgePredictor(input_size).to(device)\n",
230
+ "criterion = nn.MSELoss()\n",
231
+ "optimizer = torch.optim.Adam(model.parameters(), lr=0.001)\n",
232
+ "\n",
233
+ "print(model)"
234
+ ],
235
+ "execution_count": null,
236
+ "outputs": []
237
+ },
238
+ {
239
+ "cell_type": "code",
240
+ "metadata": {},
241
+ "source": [
242
+ "# Task 5: Start training for 20 epochs\n",
243
+ "num_epochs = 20\n",
244
+ "train_losses = []\n",
245
+ "val_losses = []\n",
246
+ "\n",
247
+ "print(\"Starting Training...\")\n",
248
+ "for epoch in range(num_epochs):\n",
249
+ " train_loss = train_one_epoch(model, optimizer, criterion, train_loader, device)\n",
250
+ " val_loss = validate(model, criterion, test_loader, device)\n",
251
+ "\n",
252
+ " train_losses.append(train_loss)\n",
253
+ " val_losses.append(val_loss)\n",
254
+ "\n",
255
+ " print(f\"Epoch [{epoch+1}/{num_epochs}], Train Loss: {train_loss:.4f}, Val Loss: {val_loss:.4f}\")\n",
256
+ "\n",
257
+ "print(\"Training Complete!\")"
258
+ ],
259
+ "execution_count": null,
260
+ "outputs": []
261
+ },
262
+ {
263
+ "cell_type": "code",
264
+ "metadata": {},
265
+ "source": [
266
+ "# Task 1: Plot training and validation loss over epochs\n",
267
+ "plt.figure(figsize=(10, 6))\n",
268
+ "plt.plot(train_losses, label='Train Loss')\n",
269
+ "plt.plot(val_losses, label='Validation Loss')\n",
270
+ "plt.title('Loss over Epochs')\n",
271
+ "plt.xlabel('Epoch')\n",
272
+ "plt.ylabel('Loss (MSE)')\n",
273
+ "plt.legend()\n",
274
+ "plt.grid(True)\n",
275
+ "plt.show()"
276
+ ],
277
+ "execution_count": null,
278
+ "outputs": []
279
+ },
280
+ {
281
+ "cell_type": "code",
282
+ "metadata": {},
283
+ "source": [
284
+ "# Task 2 (Bonus): Plot predictions with actual images\n",
285
+ "model.eval()\n",
286
+ "fig, axes = plt.subplots(2, 5, figsize=(15, 6))\n",
287
+ "axes = axes.flatten()\n",
288
+ "\n",
289
+ "with torch.no_grad():\n",
290
+ " # Get a batch of test data\n",
291
+ " test_images, test_labels = next(iter(test_loader))\n",
292
+ " test_images = test_images.to(device)\n",
293
+ " predictions = model(test_images).cpu().numpy()\n",
294
+ "\n",
295
+ " for i in range(10):\n",
296
+ " img = test_images[i].cpu().numpy().transpose(1, 2, 0) # (C, H, W) -> (H, W, C)\n",
297
+ " actual_age = test_labels[i].item()\n",
298
+ " predicted_age = predictions[i]\n",
299
+ "\n",
300
+ " axes[i].imshow(img)\n",
301
+ " axes[i].set_title(f\"Actual: {actual_age:.0f}\\nPred: {predicted_age:.1f}\")\n",
302
+ " axes[i].axis('off')\n",
303
+ "\n",
304
+ "plt.suptitle(\"Predicted vs Actual Age\", fontsize=14)\n",
305
+ "plt.tight_layout()\n",
306
+ "plt.show()"
307
+ ],
308
+ "execution_count": null,
309
+ "outputs": []
310
+ }
311
+ ],
312
+ "metadata": {
313
+ "kernelspec": {
314
+ "display_name": "Python 3",
315
+ "name": "python3"
316
+ },
317
+ "language_info": {
318
+ "name": "python"
319
+ }
320
+ },
321
+ "nbformat": 4,
322
+ "nbformat_minor": 0
323
+ }
submissions_extracted/10/Q3.ipynb ADDED
@@ -0,0 +1,307 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "metadata": {},
6
+ "source": [
7
+ "import kagglehub\n",
8
+ "\n",
9
+ "\n",
10
+ "\n",
11
+ "# Download latest version\n",
12
+ "\n",
13
+ "path = kagglehub.dataset_download(\"ANON_OWNER/q3-exam-data\")\n",
14
+ "\n",
15
+ "\n",
16
+ "\n",
17
+ "print(\"Path to dataset files:\", path)"
18
+ ],
19
+ "execution_count": null,
20
+ "outputs": []
21
+ },
22
+ {
23
+ "cell_type": "code",
24
+ "metadata": {},
25
+ "source": [
26
+ "# Task 1: Read the dataset\n",
27
+ "import pandas as pd\n",
28
+ "import numpy as np\n",
29
+ "import matplotlib.pyplot as plt\n",
30
+ "\n",
31
+ "df = pd.read_csv(f\"{path}/Q3_data.csv\")"
32
+ ],
33
+ "execution_count": null,
34
+ "outputs": []
35
+ },
36
+ {
37
+ "cell_type": "code",
38
+ "metadata": {},
39
+ "source": [
40
+ "# Task 2: Inspect the first few rows\n",
41
+ "df.head()"
42
+ ],
43
+ "execution_count": null,
44
+ "outputs": []
45
+ },
46
+ {
47
+ "cell_type": "code",
48
+ "metadata": {},
49
+ "source": [
50
+ "# Task 3: Display dataset information\n",
51
+ "df.info()"
52
+ ],
53
+ "execution_count": null,
54
+ "outputs": []
55
+ },
56
+ {
57
+ "cell_type": "code",
58
+ "metadata": {},
59
+ "source": [
60
+ "# Task 4: Show statistical description\n",
61
+ "df.describe()"
62
+ ],
63
+ "execution_count": null,
64
+ "outputs": []
65
+ },
66
+ {
67
+ "cell_type": "code",
68
+ "metadata": {},
69
+ "source": [
70
+ "# Task 1: Handle missing values\n",
71
+ "print(\"Missing values before:\")\n",
72
+ "print(df.isnull().sum())\n",
73
+ "\n",
74
+ "# Fill missing values\n",
75
+ "for col in df.columns:\n",
76
+ " if df[col].isnull().sum() > 0:\n",
77
+ " if df[col].dtype == 'object':\n",
78
+ " df[col] = df[col].fillna(df[col].mode()[0])\n",
79
+ " else:\n",
80
+ " df[col] = df[col].fillna(df[col].median())\n",
81
+ "\n",
82
+ "print(\"\\nMissing values after:\")\n",
83
+ "print(df.isnull().sum().sum())"
84
+ ],
85
+ "execution_count": null,
86
+ "outputs": []
87
+ },
88
+ {
89
+ "cell_type": "code",
90
+ "metadata": {},
91
+ "source": [
92
+ "# Task 2: Check and remove duplicates\n",
93
+ "print(f\"Duplicates before: {df.duplicated().sum()}\")\n",
94
+ "df = df.drop_duplicates()\n",
95
+ "print(f\"Duplicates after: {df.duplicated().sum()}\")"
96
+ ],
97
+ "execution_count": null,
98
+ "outputs": []
99
+ },
100
+ {
101
+ "cell_type": "code",
102
+ "metadata": {},
103
+ "source": [
104
+ "# Task 3: Encode categorical variables\n",
105
+ "categorical_cols = df.select_dtypes(include=['object']).columns.tolist()\n",
106
+ "print(f\"Categorical columns: {categorical_cols}\")\n",
107
+ "\n",
108
+ "if len(categorical_cols) > 0:\n",
109
+ " df = pd.get_dummies(df, columns=categorical_cols, drop_first=True)"
110
+ ],
111
+ "execution_count": null,
112
+ "outputs": []
113
+ },
114
+ {
115
+ "cell_type": "code",
116
+ "metadata": {},
117
+ "source": [
118
+ "# Task 4: Apply feature scaling (StandardScaler)\n",
119
+ "from sklearn.preprocessing import StandardScaler\n",
120
+ "\n",
121
+ "target_col = 'Target' # Correct column name\n",
122
+ "\n",
123
+ "X = df.drop(target_col, axis=1)\n",
124
+ "y = df[target_col]\n",
125
+ "\n",
126
+ "scaler = StandardScaler()\n",
127
+ "X_scaled = pd.DataFrame(scaler.fit_transform(X), columns=X.columns)"
128
+ ],
129
+ "execution_count": null,
130
+ "outputs": []
131
+ },
132
+ {
133
+ "cell_type": "code",
134
+ "metadata": {},
135
+ "source": [
136
+ "# Task 5: Check for target imbalance\n",
137
+ "print(\"Target distribution:\")\n",
138
+ "print(y.value_counts())\n",
139
+ "print(f\"\\nPercentage:\\n{y.value_counts(normalize=True) * 100}\")\n",
140
+ "\n",
141
+ "# Plot target distribution\n",
142
+ "plt.figure(figsize=(6, 4))\n",
143
+ "y.value_counts().plot(kind='bar', edgecolor='black')\n",
144
+ "plt.title('Target Distribution')\n",
145
+ "plt.xlabel('Class')\n",
146
+ "plt.ylabel('Count')\n",
147
+ "plt.xticks(rotation=0)\n",
148
+ "plt.show()\n",
149
+ "\n",
150
+ "# Check imbalance ratio\n",
151
+ "imbalance_ratio = y.value_counts().min() / y.value_counts().max()\n",
152
+ "print(f\"\\nImbalance ratio: {imbalance_ratio:.2f}\")\n",
153
+ "\n",
154
+ "if imbalance_ratio < 0.8:\n",
155
+ " print(\"The dataset IS IMBALANCED - Use F1 Score and StratifiedKFold\")\n",
156
+ "else:\n",
157
+ " print(\"The dataset is balanced - Can use Accuracy\")"
158
+ ],
159
+ "execution_count": null,
160
+ "outputs": []
161
+ },
162
+ {
163
+ "cell_type": "code",
164
+ "metadata": {},
165
+ "source": [
166
+ "# Task 1: Write your code here:"
167
+ ],
168
+ "execution_count": null,
169
+ "outputs": []
170
+ },
171
+ {
172
+ "cell_type": "code",
173
+ "metadata": {},
174
+ "source": [
175
+ "# Task 2, 3, 4, 5: StratifiedKFold, CatBoost, F1 Score, Print averaged score\n",
176
+ "!pip install catboost -q\n",
177
+ "\n",
178
+ "from sklearn.model_selection import StratifiedKFold\n",
179
+ "from catboost import CatBoostClassifier\n",
180
+ "from sklearn.metrics import f1_score, accuracy_score\n",
181
+ "\n",
182
+ "# Use StratifiedKFold for classification (maintains class distribution)\n",
183
+ "skfold = StratifiedKFold(n_splits=5, shuffle=True, random_state=42)\n",
184
+ "\n",
185
+ "f1_scores = []\n",
186
+ "accuracy_scores = []\n",
187
+ "model = None\n",
188
+ "\n",
189
+ "for train_idx, val_idx in skfold.split(X_scaled, y):\n",
190
+ " X_train, X_val = X_scaled.iloc[train_idx], X_scaled.iloc[val_idx]\n",
191
+ " y_train, y_val = y.iloc[train_idx], y.iloc[val_idx]\n",
192
+ "\n",
193
+ " # Train CatBoostClassifier\n",
194
+ " model = CatBoostClassifier(iterations=100, random_state=42, verbose=0)\n",
195
+ " model.fit(X_train, y_train)\n",
196
+ "\n",
197
+ " # Predict\n",
198
+ " y_pred = model.predict(X_val)\n",
199
+ "\n",
200
+ " # Calculate F1 Score (use for imbalanced data)\n",
201
+ " f1 = f1_score(y_val, y_pred)\n",
202
+ " acc = accuracy_score(y_val, y_pred)\n",
203
+ "\n",
204
+ " f1_scores.append(f1)\n",
205
+ " accuracy_scores.append(acc)\n",
206
+ "\n",
207
+ "# Print averaged scores\n",
208
+ "print(f\"F1 Scores per fold: {f1_scores}\")\n",
209
+ "print(f\"Average F1 Score: {np.mean(f1_scores):.4f}\")\n",
210
+ "print(f\"\\nAccuracy Scores per fold: {accuracy_scores}\")\n",
211
+ "print(f\"Average Accuracy: {np.mean(accuracy_scores):.4f}\")"
212
+ ],
213
+ "execution_count": null,
214
+ "outputs": []
215
+ },
216
+ {
217
+ "cell_type": "code",
218
+ "metadata": {},
219
+ "source": [
220
+ "# Task 1: Plot feature importance\n",
221
+ "feature_importance = model.feature_importances_\n",
222
+ "feature_names = X_scaled.columns\n",
223
+ "\n",
224
+ "# Sort by importance\n",
225
+ "sorted_idx = np.argsort(feature_importance)\n",
226
+ "\n",
227
+ "plt.figure(figsize=(10, 20))\n",
228
+ "plt.barh(range(len(sorted_idx)), feature_importance[sorted_idx])\n",
229
+ "plt.yticks(range(len(sorted_idx)), feature_names[sorted_idx], fontsize=6)\n",
230
+ "plt.xlabel('Feature Importance')\n",
231
+ "plt.title('CatBoost Feature Importance')\n",
232
+ "plt.tight_layout()\n",
233
+ "plt.show()"
234
+ ],
235
+ "execution_count": null,
236
+ "outputs": []
237
+ },
238
+ {
239
+ "cell_type": "code",
240
+ "metadata": {},
241
+ "source": [
242
+ "# Task 2: Identify the golden feature (most important)\n",
243
+ "golden_feature_idx = np.argmax(feature_importance)\n",
244
+ "golden_feature = feature_names[golden_feature_idx]\n",
245
+ "\n",
246
+ "print(f\"The GOLDEN FEATURE is: {golden_feature}\")\n",
247
+ "print(f\"Importance score: {feature_importance[golden_feature_idx]:.4f}\")"
248
+ ],
249
+ "execution_count": null,
250
+ "outputs": []
251
+ },
252
+ {
253
+ "cell_type": "code",
254
+ "metadata": {},
255
+ "source": [
256
+ "# Bonus: Retrain using ONLY the golden feature\n",
257
+ "\n",
258
+ "# 1. Create new X with only the golden feature\n",
259
+ "X_golden = X_scaled[[golden_feature]]\n",
260
+ "\n",
261
+ "# 2. Run StratifiedKFold with single feature\n",
262
+ "skfold = StratifiedKFold(n_splits=5, shuffle=True, random_state=42)\n",
263
+ "\n",
264
+ "golden_f1_scores = []\n",
265
+ "golden_accuracy_scores = []\n",
266
+ "\n",
267
+ "for train_idx, val_idx in skfold.split(X_golden, y):\n",
268
+ " X_train, X_val = X_golden.iloc[train_idx], X_golden.iloc[val_idx]\n",
269
+ " y_train, y_val = y.iloc[train_idx], y.iloc[val_idx]\n",
270
+ "\n",
271
+ " model_golden = CatBoostClassifier(iterations=100, random_state=42, verbose=0)\n",
272
+ " model_golden.fit(X_train, y_train)\n",
273
+ "\n",
274
+ " y_pred = model_golden.predict(X_val)\n",
275
+ "\n",
276
+ " f1 = f1_score(y_val, y_pred)\n",
277
+ " acc = accuracy_score(y_val, y_pred)\n",
278
+ "\n",
279
+ " golden_f1_scores.append(f1)\n",
280
+ " golden_accuracy_scores.append(acc)\n",
281
+ "\n",
282
+ "# 3. Print and compare\n",
283
+ "print(\"=\" * 50)\n",
284
+ "print(\"COMPARISON: Full Model vs Golden Feature Only\")\n",
285
+ "print(\"=\" * 50)\n",
286
+ "print(f\"\\nFull Model Average F1 Score: {np.mean(f1_scores):.4f}\")\n",
287
+ "print(f\"Golden Feature Average F1 Score: {np.mean(golden_f1_scores):.4f}\")\n",
288
+ "print(f\"\\nFull Model Average Accuracy: {np.mean(accuracy_scores):.4f}\")\n",
289
+ "print(f\"Golden Feature Average Accuracy: {np.mean(golden_accuracy_scores):.4f}\")\n",
290
+ "print(\"=\" * 50)"
291
+ ],
292
+ "execution_count": null,
293
+ "outputs": []
294
+ }
295
+ ],
296
+ "metadata": {
297
+ "kernelspec": {
298
+ "display_name": "Python 3",
299
+ "name": "python3"
300
+ },
301
+ "language_info": {
302
+ "name": "python"
303
+ }
304
+ },
305
+ "nbformat": 4,
306
+ "nbformat_minor": 0
307
+ }
submissions_extracted/100/Q1.ipynb ADDED
@@ -0,0 +1,311 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "metadata": {},
6
+ "source": [
7
+ "import kagglehub\n",
8
+ "import numpy as np\n",
9
+ "import pandas as pd\n",
10
+ "import matplotlib.pyplot as plt\n",
11
+ "import os\n",
12
+ "import kagglehub\n",
13
+ "\n",
14
+ "from sklearn.preprocessing import OneHotEncoder\n",
15
+ "from sklearn.model_selection import train_test_split, KFold\n",
16
+ "from sklearn.preprocessing import StandardScaler, LabelEncoder\n",
17
+ "from sklearn.ensemble import RandomForestRegressor\n",
18
+ "from sklearn.metrics import mean_absolute_error, mean_squared_error\n",
19
+ "\n",
20
+ "import warnings\n",
21
+ "warnings.filterwarnings('ignore')\n",
22
+ "\n",
23
+ "# Download latest version\n",
24
+ "path = kagglehub.dataset_download(\"ANON_OWNER/q1-exam-data\")\n",
25
+ "\n",
26
+ "print(\"Path to dataset files:\", path)"
27
+ ],
28
+ "execution_count": null,
29
+ "outputs": []
30
+ },
31
+ {
32
+ "cell_type": "code",
33
+ "metadata": {},
34
+ "source": [
35
+ "# Load the dataset\n",
36
+ "Dli_path = os.path.join(path,'Q1_data.csv')\n",
37
+ "df_dli = pd.read_csv(Dli_path)\n",
38
+ "\n",
39
+ "print(f\"Dataset shape: {df_dli.shape}\")\n"
40
+ ],
41
+ "execution_count": null,
42
+ "outputs": []
43
+ },
44
+ {
45
+ "cell_type": "code",
46
+ "metadata": {},
47
+ "source": [
48
+ "df_dli.head()"
49
+ ],
50
+ "execution_count": null,
51
+ "outputs": []
52
+ },
53
+ {
54
+ "cell_type": "code",
55
+ "metadata": {},
56
+ "source": [
57
+ "df_dli.info()"
58
+ ],
59
+ "execution_count": null,
60
+ "outputs": []
61
+ },
62
+ {
63
+ "cell_type": "code",
64
+ "metadata": {},
65
+ "source": [
66
+ "df_dli.describe()"
67
+ ],
68
+ "execution_count": null,
69
+ "outputs": []
70
+ },
71
+ {
72
+ "cell_type": "code",
73
+ "metadata": {},
74
+ "source": [
75
+ "# delivery_time distribution (target variable)\n",
76
+ "plt.figure(figsize=(10, 5))\n",
77
+ "plt.hist(df_dli['Delivery_Time'].dropna(), bins=50, edgecolor='black')\n",
78
+ "plt.title('time Distribution')\n",
79
+ "plt.xlabel('time')\n",
80
+ "plt.ylabel('Frequency')\n",
81
+ "plt.show()"
82
+ ],
83
+ "execution_count": null,
84
+ "outputs": []
85
+ },
86
+ {
87
+ "cell_type": "code",
88
+ "metadata": {},
89
+ "source": [
90
+ "df_dli.drop(columns=['Order_ID'])"
91
+ ],
92
+ "execution_count": null,
93
+ "outputs": []
94
+ },
95
+ {
96
+ "cell_type": "code",
97
+ "metadata": {},
98
+ "source": [
99
+ "# Analyze missing values\n",
100
+ "missing_percentage = (df_dli.isnull().sum() / len(df_dli)) * 100\n",
101
+ "missing_data = pd.DataFrame({\n",
102
+ " 'Column': missing_percentage.index,\n",
103
+ " 'Missing_Percentage': missing_percentage.values\n",
104
+ "})\n",
105
+ "missing_data = missing_data[missing_data['Missing_Percentage'] > 0].sort_values('Missing_Percentage', ascending=False)\n",
106
+ "\n",
107
+ "print(\"Missing Data Analysis:\")\n",
108
+ "missing_data.head(10)\n",
109
+ "\n",
110
+ "df_dli['Delivery_Time'].fillna(df_dli['Delivery_Time'].mean())\n",
111
+ "#df_dli.dropna(subset=['Delivery_Time'])"
112
+ ],
113
+ "execution_count": null,
114
+ "outputs": []
115
+ },
116
+ {
117
+ "cell_type": "code",
118
+ "metadata": {},
119
+ "source": [
120
+ "# Do we have duplicate samples?\n",
121
+ "def check_duplicates(df):\n",
122
+ " duplicates = df.duplicated().sum()\n",
123
+ " print(f\"Number of Duplicate Samples: {duplicates}\")\n",
124
+ " if duplicates > 0:\n",
125
+ " print(\"Dropping Duplicates...\")\n",
126
+ " df.drop_duplicates(inplace=True)\n",
127
+ " print(\"Duplicates Dropped.\")\n",
128
+ " else:\n",
129
+ " print(\"No Duplicate Samples Found.\")\n",
130
+ "\n",
131
+ "check_duplicates(df_dli)\n",
132
+ "df_dli.drop_duplicates(inplace=True)"
133
+ ],
134
+ "execution_count": null,
135
+ "outputs": []
136
+ },
137
+ {
138
+ "cell_type": "code",
139
+ "metadata": {},
140
+ "source": [
141
+ "# Do we have categorical columns?\n",
142
+ "categorical_cols = df_dli.select_dtypes(include=[\"object\"]).columns\n",
143
+ "\n",
144
+ "print(\"Categorical Columns:\", list(categorical_cols))\n",
145
+ "\n",
146
+ "categorical_cols = df_dli.select_dtypes(include=[\"object\"]).columns\n",
147
+ "for col in categorical_cols:\n",
148
+ " print(f\"Encoding column: {col}\")\n",
149
+ " le = LabelEncoder()\n",
150
+ " df_dli[col] = le.fit_transform(df_dli[col])\n",
151
+ "df_dli\n",
152
+ "\n",
153
+ "\n",
154
+ "#from sklearn.preprocessing import OneHotEncoder #import OneHotEncoder\n",
155
+ "\n",
156
+ "#onehot_encoder = OneHotEncoder(sparse_output=False) # Instantiate OneHotEncoder\n",
157
+ "#data_onehot_encoded = onehot_encoder.fit_transform(categories) # Apply fit_transform to the copied\n",
158
+ "\n"
159
+ ],
160
+ "execution_count": null,
161
+ "outputs": []
162
+ },
163
+ {
164
+ "cell_type": "code",
165
+ "metadata": {},
166
+ "source": [
167
+ "# Standardize features using StandardScaler\n",
168
+ "numerical_cols = df_dli.select_dtypes(include=[\"int64\", \"float64\"]).columns.drop(\"Delivery_Time\") ### DON'T SCALE THE TARGET\n",
169
+ "scaler = StandardScaler()\n",
170
+ "df_dli[numerical_cols] = scaler.fit_transform(df_dli[numerical_cols])\n",
171
+ "df_dli"
172
+ ],
173
+ "execution_count": null,
174
+ "outputs": []
175
+ },
176
+ {
177
+ "cell_type": "code",
178
+ "metadata": {},
179
+ "source": [
180
+ "# 1. Is the target imbalanced?\n",
181
+ "def check_target_imbalance(df, target_column):\n",
182
+ " print(\"Target Distribution:\")\n",
183
+ "\n",
184
+ " df['Delivery_Time'].hist() # Yeah you can just do this :)\n",
185
+ " plt.show()\n",
186
+ "\n",
187
+ "check_target_imbalance(df_dli, \"time\")"
188
+ ],
189
+ "execution_count": null,
190
+ "outputs": []
191
+ },
192
+ {
193
+ "cell_type": "code",
194
+ "metadata": {},
195
+ "source": [
196
+ "# Define features (X) and target (y)\n",
197
+ "feature_cols = ['Distance_km' ,'Weather','Traffic_Level','Time_of_Day','Vehicle_Type','Preparation_Time_min',\t'Courier_Experience_yrs']\n",
198
+ "X = df_dli[feature_cols]\n",
199
+ "y = df_dli['Delivery_Time']\n",
200
+ "X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)\n",
201
+ "print(f\"Train: {X_train.shape}, Test: {X_test.shape}\")"
202
+ ],
203
+ "execution_count": null,
204
+ "outputs": []
205
+ },
206
+ {
207
+ "cell_type": "code",
208
+ "metadata": {},
209
+ "source": [
210
+ "print(f\"\\nFeature ranges - Min: {X_train.min().min():.2f}, Max: {X_train.max().max():.2f}\")\n",
211
+ "X_train.head(3)"
212
+ ],
213
+ "execution_count": null,
214
+ "outputs": []
215
+ },
216
+ {
217
+ "cell_type": "code",
218
+ "metadata": {},
219
+ "source": [
220
+ "# Scale features - fit on train, transform both\n",
221
+ "scaler = StandardScaler()\n",
222
+ "X_train_scaled = scaler.fit_transform(X_train)\n",
223
+ "X_test_scaled = scaler.transform(X_test)\n",
224
+ "\n",
225
+ "print(f\"\\nScaled ranges - Min: {X_train_scaled.min():.2f}, Max: {X_train_scaled.max():.2f}\")\n",
226
+ "pd.DataFrame(X_train_scaled, columns=X_train.columns).head(3)"
227
+ ],
228
+ "execution_count": null,
229
+ "outputs": []
230
+ },
231
+ {
232
+ "cell_type": "code",
233
+ "metadata": {},
234
+ "source": [
235
+ "# Train Random Forest Regressor\n",
236
+ "model = RandomForestRegressor(n_estimators=100, max_depth=20, random_state=42, n_jobs=-1)\n",
237
+ "model.fit(X_train_scaled, y_train)\n",
238
+ "print(\"Model trained!\")"
239
+ ],
240
+ "execution_count": null,
241
+ "outputs": []
242
+ },
243
+ {
244
+ "cell_type": "code",
245
+ "metadata": {},
246
+ "source": [
247
+ "from sklearn.ensemble import RandomForestRegressor\n",
248
+ "from sklearn.model_selection import StratifiedKFold\n",
249
+ "\n",
250
+ "n_splits = 5 # K=5 Folds\n",
251
+ "# Stratified 5-Fold Cross-Validation, shuffled\n",
252
+ "skf = StratifiedKFold(n_splits=n_splits, shuffle=True, random_state=42)\n",
253
+ "\n",
254
+ "scaler = StandardScaler()\n",
255
+ "X_train_scaled = scaler.fit_transform(X_train)\n",
256
+ "X_test_scaled = scaler.transform(X_test)\n",
257
+ "\n",
258
+ "print(f\"\\nScaled ranges - Min: {X_train_scaled.min():.2f}, Max: {X_train_scaled.max():.2f}\")\n",
259
+ "pd.DataFrame(X_train_scaled, columns=X_train.columns).head(3)\n",
260
+ "\n",
261
+ "X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)\n",
262
+ "print(f\"Train: {X_train.shape}, Test: {X_test.shape}\")\n",
263
+ "\n",
264
+ "# Train Regressor\n",
265
+ "model = RandomForestRegressor(n_estimators=100, max_depth=20, random_state=42, n_jobs=-1)\n",
266
+ "model.fit(X_train, y_train)\n",
267
+ "print(\"Model trained!\")"
268
+ ],
269
+ "execution_count": null,
270
+ "outputs": []
271
+ },
272
+ {
273
+ "cell_type": "code",
274
+ "metadata": {},
275
+ "source": [
276
+ "# Task 1: Write your code here:"
277
+ ],
278
+ "execution_count": null,
279
+ "outputs": []
280
+ },
281
+ {
282
+ "cell_type": "code",
283
+ "metadata": {},
284
+ "source": [
285
+ "# Task 2: Write your code here:"
286
+ ],
287
+ "execution_count": null,
288
+ "outputs": []
289
+ },
290
+ {
291
+ "cell_type": "code",
292
+ "metadata": {},
293
+ "source": [
294
+ "# Task Bonus: Write your code here:"
295
+ ],
296
+ "execution_count": null,
297
+ "outputs": []
298
+ }
299
+ ],
300
+ "metadata": {
301
+ "kernelspec": {
302
+ "display_name": "Python 3",
303
+ "name": "python3"
304
+ },
305
+ "language_info": {
306
+ "name": "python"
307
+ }
308
+ },
309
+ "nbformat": 4,
310
+ "nbformat_minor": 0
311
+ }
submissions_extracted/100/Q2.ipynb ADDED
@@ -0,0 +1,365 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "metadata": {},
6
+ "source": [
7
+ "import kagglehub\n",
8
+ "\n",
9
+ "# Download latest version\n",
10
+ "path = kagglehub.dataset_download(\"ANON_OWNER/q2-exam-data\")\n",
11
+ "\n",
12
+ "print(\"Path to dataset files:\", path)"
13
+ ],
14
+ "execution_count": null,
15
+ "outputs": []
16
+ },
17
+ {
18
+ "cell_type": "code",
19
+ "metadata": {},
20
+ "source": [
21
+ "import os\n",
22
+ "import pandas as pd\n",
23
+ "import numpy as np\n",
24
+ "from PIL import Image\n",
25
+ "from sklearn.model_selection import train_test_split\n",
26
+ "\n",
27
+ "# Load Labels\n",
28
+ "labels_df = pd.read_csv(os.path.join(path, \"labels.csv\"))\n",
29
+ "img_dir = os.path.join(path, \"images\")\n",
30
+ "\n",
31
+ "images = []\n",
32
+ "ages = []\n",
33
+ "\n",
34
+ "# Load Images and Resize\n",
35
+ "print(\"Loading images...\")\n",
36
+ "for index, row in labels_df.iterrows():\n",
37
+ " img_name = row.iloc[0]\n",
38
+ " age = row.iloc[1]\n",
39
+ " img_path = os.path.join(img_dir, img_name)\n",
40
+ "\n",
41
+ " if os.path.exists(img_path):\n",
42
+ " img = Image.open(img_path).convert('RGB')\n",
43
+ " img_array = np.array(img) / 255.0 # Normalize pixel values to [0, 1]\n",
44
+ " images.append(img_array)\n",
45
+ " ages.append(age)\n",
46
+ "\n",
47
+ "X = np.array(images)\n",
48
+ "y = np.array(ages)\n",
49
+ "\n",
50
+ "# Transpose image dimensions to match PyTorch format (N, C, H, W)\n",
51
+ "X = np.transpose(X, (0, 3, 1, 2))\n",
52
+ "\n",
53
+ "# Split Data\n",
54
+ "X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)\n",
55
+ "\n",
56
+ "print(f\"X_train shape: {X_train.shape}\")\n",
57
+ "print(f\"X_test shape: {X_test.shape}\")\n",
58
+ "print(f\"y_train shape: {y_train.shape}\")\n",
59
+ "print(f\"y_test shape: {y_test.shape}\")"
60
+ ],
61
+ "execution_count": null,
62
+ "outputs": []
63
+ },
64
+ {
65
+ "cell_type": "code",
66
+ "metadata": {},
67
+ "source": [
68
+ "# 1. Convert Numpy arrays to PyTorch Tensors\n",
69
+ "\n",
70
+ "# Create a float32 tensor\n",
71
+ "x = torch.tensor([1.2, 2.3, 3.4], dtype=torch.float32)\n",
72
+ "print(x.dtype) # Output: torch.float32\n",
73
+ "\n",
74
+ "# Convert to float16\n",
75
+ "x_half = x.to(torch.float16)\n",
76
+ "print(x_half.dtype) # Output: torch.float16\n",
77
+ "\n"
78
+ ],
79
+ "execution_count": null,
80
+ "outputs": []
81
+ },
82
+ {
83
+ "cell_type": "code",
84
+ "metadata": {},
85
+ "source": [
86
+ "# 2. Create TensorDataset objects\n",
87
+ "\n",
88
+ "X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42, stratify=y)\n",
89
+ "\n",
90
+ "# Standardize the data\n",
91
+ "scaler = StandardScaler()\n",
92
+ "X_train = scaler.fit_transform(X_train)\n",
93
+ "X_test = scaler.transform(X_test)\n",
94
+ "\n",
95
+ "# transform to tensors\n",
96
+ "X_train = torch.tensor(X_train, dtype=torch.float32)\n",
97
+ "X_test = torch.tensor(X_test, dtype=torch.float32)\n",
98
+ "y_train = torch.tensor(y_train, dtype=torch.float32)\n",
99
+ "y_test = torch.tensor(y_test, dtype=torch.float32)\n",
100
+ "\n",
101
+ "# TensorDataset pairs input features (X) with their corresponding labels (y)\n",
102
+ "# Each item in the dataset is returned as (X[i], y[i])\n",
103
+ "train_dataset = TensorDataset(X_train, y_train)\n",
104
+ "test_dataset = TensorDataset(X_test, y_test)\n",
105
+ "\n",
106
+ "# Access a single sample from the dataset\n",
107
+ "# This helps verify the shape of one data sample\n",
108
+ "first_sample, _ = train_dataset[0]\n",
109
+ "print(f\"Shape of one sample: {first_sample.shape}\")\n"
110
+ ],
111
+ "execution_count": null,
112
+ "outputs": []
113
+ },
114
+ {
115
+ "cell_type": "code",
116
+ "metadata": {},
117
+ "source": [
118
+ "# 3. Create DataLoaders\n",
119
+ "\n",
120
+ "from torch.utils.data import DataLoader\n",
121
+ "\n",
122
+ "# DataLoader for training data\n",
123
+ "train_loader = DataLoader(\n",
124
+ " train_dataset,\n",
125
+ " batch_size=32,\n",
126
+ " shuffle=True,\n",
127
+ " num_workers=2\n",
128
+ ")\n",
129
+ "# DataLoader for test/validation data\n",
130
+ "test_loader = DataLoader(\n",
131
+ " test_dataset,\n",
132
+ " batch_size=32,\n",
133
+ " shuffle=False,\n",
134
+ " num_workers=2\n",
135
+ ")\n",
136
+ "\n"
137
+ ],
138
+ "execution_count": null,
139
+ "outputs": []
140
+ },
141
+ {
142
+ "cell_type": "code",
143
+ "metadata": {},
144
+ "source": [
145
+ "# 4. Print shape of one batch\n",
146
+ "\n",
147
+ "# Get the first batch from the training DataLoader\n",
148
+ "X_batch, y_batch = next(iter(train_loader))\n",
149
+ "print(f\"Training batch input shape: {X_batch.shape}\")\n",
150
+ "print(f\"Training batch labels shape: {y_batch.shape}\")"
151
+ ],
152
+ "execution_count": null,
153
+ "outputs": []
154
+ },
155
+ {
156
+ "cell_type": "code",
157
+ "metadata": {},
158
+ "source": [
159
+ "# 5. Display sample images\n",
160
+ "\n"
161
+ ],
162
+ "execution_count": null,
163
+ "outputs": []
164
+ },
165
+ {
166
+ "cell_type": "code",
167
+ "metadata": {},
168
+ "source": [
169
+ "#class NN2Layer(nn.Module):\n",
170
+ "#use softMax instead\n",
171
+ "#!!!!!!!!!!! I have no time);\n",
172
+ "\n",
173
+ "#1\n",
174
+ "# Instantiate the model\n",
175
+ "input_dim = 4 # number of input features\n",
176
+ "hidden_dim = 4 # number of hidden neurons\n",
177
+ "\n",
178
+ "model = NN2Layer(input_dim, hidden_dim)\n",
179
+ "\n",
180
+ "# Print the model architecture\n",
181
+ "print(\"Model Architecture:\\n\")\n",
182
+ "print(model)\n",
183
+ "\n",
184
+ "# Calculate the total number of trainable parameters\n",
185
+ "total_params = sum(p.numel() for p in model.parameters() if p.requires_grad)\n",
186
+ "\n",
187
+ "print(f\"\\nTotal trainable parameters: {total_params}\")\n",
188
+ "\n",
189
+ "\n",
190
+ "#2\n",
191
+ " def __init__(self, input_dim, hidden_dim):\n",
192
+ "\n",
193
+ " super(NN2Layer, self).__init__()\n",
194
+ " # input_dim = num of features, hidden_dim = num of neurons\n",
195
+ " self.layer1 = nn.Linear(input_dim, hidden_dim)\n",
196
+ " # hidden_dim = num of neurons, Output for binary classification is 1\n",
197
+ " self.layer2 = nn.Linear(hidden_dim, 1)\n",
198
+ "\n",
199
+ " # non-linearity activation function\n",
200
+ " self.relu = nn.ReLU()\n",
201
+ " # output activation function\n",
202
+ " self.sigmoid = nn.Sigmoid()\n",
203
+ "\n",
204
+ " # forward pass\n",
205
+ " def forward(self, x):\n",
206
+ " z1 = self.layer1(x)\n",
207
+ " a1 = self.relu(z1)\n",
208
+ " z2 = self.layer2(a1)\n",
209
+ " a2 = self.sigmoid(z2)\n",
210
+ " return a2"
211
+ ],
212
+ "execution_count": null,
213
+ "outputs": []
214
+ },
215
+ {
216
+ "cell_type": "code",
217
+ "metadata": {},
218
+ "source": [
219
+ "# Instantiate the model\n",
220
+ "input_dim = 4 # number of input features\n",
221
+ "hidden_dim = 3 # number of hidden neurons\n",
222
+ "\n",
223
+ "model = NN2Layer(input_dim, hidden_dim)\n",
224
+ "\n",
225
+ "# Print the model architecture\n",
226
+ "print(\"Model Architecture:\\n\")\n",
227
+ "print(model)\n",
228
+ "\n",
229
+ "# Calculate the total number of trainable parameters\n",
230
+ "total_params = sum(p.numel() for p in model.parameters() if p.requires_grad)\n",
231
+ "\n",
232
+ "print(f\"\\nTotal trainable parameters: {total_params}\")"
233
+ ],
234
+ "execution_count": null,
235
+ "outputs": []
236
+ },
237
+ {
238
+ "cell_type": "code",
239
+ "metadata": {},
240
+ "source": [
241
+ "# Task 3: Write your validation loop here:\n",
242
+ "def train_one_epoch(model, optimizer, criterion, train_loader, device):\n",
243
+ " # Set the model to training mode\n",
244
+ " model.train()\n",
245
+ "\n",
246
+ " running_loss = 0.0\n",
247
+ "\n",
248
+ " for X_batch, y_batch in train_loader:\n",
249
+ " # Move batch to the selected device\n",
250
+ " X_batch = X_batch.to(device)\n",
251
+ " y_batch = y_batch.view(-1, 1).to(device)\n",
252
+ "\n",
253
+ " # Forward pass\n",
254
+ " outputs = model(X_batch)\n",
255
+ " loss = criterion(outputs, y_batch)\n",
256
+ "\n",
257
+ " # Backward pass & optimization\n",
258
+ " optimizer.zero_grad() # Clear previous gradients\n",
259
+ " loss.backward() # Compute gradients\n",
260
+ " optimizer.step() # Update model parameters\n",
261
+ "\n",
262
+ " running_loss += loss.item()\n",
263
+ "\n",
264
+ " # Average loss over all batches\n",
265
+ " avg_loss = running_loss / len(train_loader)\n",
266
+ "\n",
267
+ " return avg_loss"
268
+ ],
269
+ "execution_count": null,
270
+ "outputs": []
271
+ },
272
+ {
273
+ "cell_type": "code",
274
+ "metadata": {},
275
+ "source": [
276
+ "# Task 4: Define device, model, loss, optimizer:\n",
277
+ "# Device configuration\n",
278
+ "device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')\n",
279
+ "print(f\"Using device: {device}\")\n",
280
+ "\n",
281
+ "num_epochs = 20\n",
282
+ "learning_rate = 0.001\n",
283
+ "# Model, Criterion, Optimizer\n",
284
+ "input_dim = X_train.shape[1]\n",
285
+ "hidden_dim = 10\n",
286
+ "model =NN2Layer(input_dim, hidden_dim).to(device)\n",
287
+ "criterion = nn.BCELoss()\n",
288
+ "optimizer = Adam(model.parameters(), lr=learning_rate)"
289
+ ],
290
+ "execution_count": null,
291
+ "outputs": []
292
+ },
293
+ {
294
+ "cell_type": "code",
295
+ "metadata": {},
296
+ "source": [
297
+ "# Task 5: Start training for 20 epochs:\n",
298
+ "# Run Training\n",
299
+ "train_losses = []\n",
300
+ "val_losses = []\n",
301
+ "val_accuracies = []\n",
302
+ "\n",
303
+ "print('Starting Training...')\n",
304
+ "for epoch in range(num_epochs):\n",
305
+ " # Train one epoch\n",
306
+ " train_loss = train_one_epoch(model, optimizer, criterion, train_loader, device)\n",
307
+ "\n",
308
+ " # Validate\n",
309
+ " val_loss, val_accuracy = validate(model, criterion, test_loader, device)\n",
310
+ "\n",
311
+ " train_losses.append(train_loss)\n",
312
+ " val_losses.append(val_loss)\n",
313
+ " val_accuracies.append(val_accuracy)\n",
314
+ "\n",
315
+ " if (epoch + 1) % 5 == 0:\n",
316
+ " print(f'Epoch [{epoch+1}/{num_epochs}], Train Loss: {train_loss:.4f}, Val Loss: {val_loss:.4f}, Val Accuracy: {val_accuracy:.4f}')\n",
317
+ "\n",
318
+ "print('Training Complete!')"
319
+ ],
320
+ "execution_count": null,
321
+ "outputs": []
322
+ },
323
+ {
324
+ "cell_type": "code",
325
+ "metadata": {},
326
+ "source": [
327
+ "# Task 1: Write your code here:\n",
328
+ "# Plotting results\n",
329
+ "plt.figure(figsize=(7, 5))\n",
330
+ "\n",
331
+ "plt.plot(train_losses, label='Train Loss')\n",
332
+ "plt.plot(val_losses, label='Validation Loss')\n",
333
+ "plt.title('Loss over Epochs')\n",
334
+ "plt.xlabel('Epoch')\n",
335
+ "plt.ylabel('Loss')\n",
336
+ "plt.legend()\n",
337
+ "\n",
338
+ "plt.tight_layout()\n",
339
+ "plt.show()"
340
+ ],
341
+ "execution_count": null,
342
+ "outputs": []
343
+ },
344
+ {
345
+ "cell_type": "code",
346
+ "metadata": {},
347
+ "source": [
348
+ "# Task 2 (Bonus): Write your code here: #I am Great in another story maybe):"
349
+ ],
350
+ "execution_count": null,
351
+ "outputs": []
352
+ }
353
+ ],
354
+ "metadata": {
355
+ "kernelspec": {
356
+ "display_name": "Python 3",
357
+ "name": "python3"
358
+ },
359
+ "language_info": {
360
+ "name": "python"
361
+ }
362
+ },
363
+ "nbformat": 4,
364
+ "nbformat_minor": 0
365
+ }
submissions_extracted/100/Q3.ipynb ADDED
@@ -0,0 +1,219 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "metadata": {},
6
+ "source": [
7
+ "\n",
8
+ "import numpy as np\n",
9
+ "import pandas as pd\n",
10
+ "import matplotlib.pyplot as plt\n",
11
+ "import os\n",
12
+ "import kagglehub\n",
13
+ "\n",
14
+ "from sklearn.model_selection import train_test_split, KFold\n",
15
+ "from sklearn.preprocessing import StandardScaler, LabelEncoder\n",
16
+ "from sklearn.ensemble import RandomForestRegressor\n",
17
+ "from sklearn.metrics import mean_absolute_error, mean_squared_error\n",
18
+ "\n",
19
+ "import warnings\n",
20
+ "warnings.filterwarnings('ignore')\n",
21
+ "import kagglehub\n",
22
+ "\n",
23
+ "# Download latest version\n",
24
+ "\n",
25
+ "path = kagglehub.dataset_download(\"ANON_OWNER/q3-exam-data\")\n",
26
+ "print(\"Path to dataset files:\", path)"
27
+ ],
28
+ "execution_count": null,
29
+ "outputs": []
30
+ },
31
+ {
32
+ "cell_type": "code",
33
+ "metadata": {},
34
+ "source": [
35
+ "c_path = os.path.join(path, 'Q3_data.csv')\n",
36
+ "df_c = pd.read_csv(c_path)\n",
37
+ "\n",
38
+ "print(f\"Dataset shape: {df_c.shape}\")\n"
39
+ ],
40
+ "execution_count": null,
41
+ "outputs": []
42
+ },
43
+ {
44
+ "cell_type": "code",
45
+ "metadata": {},
46
+ "source": [
47
+ "df_c.head()"
48
+ ],
49
+ "execution_count": null,
50
+ "outputs": []
51
+ },
52
+ {
53
+ "cell_type": "code",
54
+ "metadata": {},
55
+ "source": [
56
+ "# Task 3: Write your code here:\n",
57
+ "df_c.info()"
58
+ ],
59
+ "execution_count": null,
60
+ "outputs": []
61
+ },
62
+ {
63
+ "cell_type": "code",
64
+ "metadata": {},
65
+ "source": [
66
+ "# Task 4: Write your code here:\n",
67
+ "df_c.describe()"
68
+ ],
69
+ "execution_count": null,
70
+ "outputs": []
71
+ },
72
+ {
73
+ "cell_type": "code",
74
+ "metadata": {},
75
+ "source": [
76
+ "# Task 1: Write your code here:\n",
77
+ "# Analyze missing values\n",
78
+ "missing_percentage = (df_c.isnull().sum() / len(df_c)) * 100\n",
79
+ "missing_data = pd.DataFrame({\n",
80
+ " 'Column': missing_percentage.index,\n",
81
+ " 'Missing_Percentage': missing_percentage.values\n",
82
+ "})\n",
83
+ "missing_data = missing_data[missing_data['Missing_Percentage'] > 0].sort_values('Missing_Percentage', ascending=False)\n",
84
+ "\n",
85
+ "print(\"Missing Data Analysis:\")\n",
86
+ "missing_data.head(10)"
87
+ ],
88
+ "execution_count": null,
89
+ "outputs": []
90
+ },
91
+ {
92
+ "cell_type": "code",
93
+ "metadata": {},
94
+ "source": [
95
+ "# Task 2: Write your code here:\n",
96
+ "def check_duplicates(df):\n",
97
+ " duplicates = df.duplicated().sum()\n",
98
+ " print(f\"Number of Duplicate Samples: {duplicates}\")\n",
99
+ " if duplicates > 0:\n",
100
+ " print(\"Dropping Duplicates...\")\n",
101
+ " df.drop_duplicates(inplace=True)\n",
102
+ " print(\"Duplicates Dropped.\")\n",
103
+ " else:\n",
104
+ " print(\"No Duplicate Samples Found.\")\n",
105
+ "\n",
106
+ "check_duplicates(df_c)\n",
107
+ "df_c.drop_duplicates(inplace=True)"
108
+ ],
109
+ "execution_count": null,
110
+ "outputs": []
111
+ },
112
+ {
113
+ "cell_type": "code",
114
+ "metadata": {},
115
+ "source": [
116
+ "# Task 3: Write your code here:\n",
117
+ "categorical_cols = df_c.select_dtypes(include=[\"object\"]).columns\n",
118
+ "\n",
119
+ "print(\"Categorical Columns:\", list(categorical_cols))\n",
120
+ "\n",
121
+ "categorical_cols = df_c.select_dtypes(include=[\"object\"]).columns\n",
122
+ "for col in categorical_cols:\n",
123
+ " print(f\"Encoding column: {col}\")\n",
124
+ " le = LabelEncoder()\n",
125
+ " df_c[col] = le.fit_transform(df_c[col])\n",
126
+ "df_c"
127
+ ],
128
+ "execution_count": null,
129
+ "outputs": []
130
+ },
131
+ {
132
+ "cell_type": "code",
133
+ "metadata": {},
134
+ "source": [
135
+ "# Task 4: Write your code here:\n",
136
+ "# Standardize features using StandardScaler\n",
137
+ "numerical_cols = df_c.select_dtypes(include=[\"int64\", \"float64\"]).columns.drop(\"target\") ### DON'T SCALE THE TARGET\n",
138
+ "scaler = StandardScaler()\n",
139
+ "df_c[numerical_cols] = scaler.fit_transform(df_c[numerical_cols])\n",
140
+ "df_c"
141
+ ],
142
+ "execution_count": null,
143
+ "outputs": []
144
+ },
145
+ {
146
+ "cell_type": "code",
147
+ "metadata": {},
148
+ "source": [
149
+ "# Task 5: Write your code here\n",
150
+ "# 1. Is the target imbalanced?\n",
151
+ "def check_target_imbalance(df, target_column):\n",
152
+ " print(\"Target Distribution:\")\n",
153
+ "\n",
154
+ " df['Delivery_Time'].hist() # Yeah you can just do this :)\n",
155
+ " plt.show()\n",
156
+ "\n",
157
+ "check_target_imbalance(df_c, \"Target\")"
158
+ ],
159
+ "execution_count": null,
160
+ "outputs": []
161
+ },
162
+ {
163
+ "cell_type": "code",
164
+ "metadata": {},
165
+ "source": [
166
+ "# Task 1: Write your code here:"
167
+ ],
168
+ "execution_count": null,
169
+ "outputs": []
170
+ },
171
+ {
172
+ "cell_type": "code",
173
+ "metadata": {},
174
+ "source": [
175
+ "# Task 2,3,4,5: Write your code here:"
176
+ ],
177
+ "execution_count": null,
178
+ "outputs": []
179
+ },
180
+ {
181
+ "cell_type": "code",
182
+ "metadata": {},
183
+ "source": [
184
+ "# Task 1: Write your code here:"
185
+ ],
186
+ "execution_count": null,
187
+ "outputs": []
188
+ },
189
+ {
190
+ "cell_type": "code",
191
+ "metadata": {},
192
+ "source": [
193
+ "# Task 2: Write your code here:"
194
+ ],
195
+ "execution_count": null,
196
+ "outputs": []
197
+ },
198
+ {
199
+ "cell_type": "code",
200
+ "metadata": {},
201
+ "source": [
202
+ "# Task Bonus: Write your code here:"
203
+ ],
204
+ "execution_count": null,
205
+ "outputs": []
206
+ }
207
+ ],
208
+ "metadata": {
209
+ "kernelspec": {
210
+ "display_name": "Python 3",
211
+ "name": "python3"
212
+ },
213
+ "language_info": {
214
+ "name": "python"
215
+ }
216
+ },
217
+ "nbformat": 4,
218
+ "nbformat_minor": 0
219
+ }
submissions_extracted/1000/Q1.ipynb ADDED
@@ -0,0 +1,293 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "metadata": {},
6
+ "source": [
7
+ "import kagglehub\n",
8
+ "\n",
9
+ "# Download latest version\n",
10
+ "path = kagglehub.dataset_download(\"ANON_OWNER/q1-exam-data\")\n",
11
+ "\n",
12
+ "print(\"Path to dataset files:\", path)"
13
+ ],
14
+ "execution_count": null,
15
+ "outputs": []
16
+ },
17
+ {
18
+ "cell_type": "code",
19
+ "metadata": {},
20
+ "source": [
21
+ "# Task 1: Write your code here:\n",
22
+ "import pandas\n",
23
+ "import os\n",
24
+ "q1_path = os.path.join(path, 'Q1_data.csv')\n",
25
+ "q1_dataset = pandas.read_csv(q1_path)"
26
+ ],
27
+ "execution_count": null,
28
+ "outputs": []
29
+ },
30
+ {
31
+ "cell_type": "code",
32
+ "metadata": {},
33
+ "source": [
34
+ "# Task 2: Write your code here:\n",
35
+ "q1_dataset.head(7)"
36
+ ],
37
+ "execution_count": null,
38
+ "outputs": []
39
+ },
40
+ {
41
+ "cell_type": "code",
42
+ "metadata": {},
43
+ "source": [
44
+ "# Task 3: Write your code here:\n",
45
+ "q1_dataset.info()"
46
+ ],
47
+ "execution_count": null,
48
+ "outputs": []
49
+ },
50
+ {
51
+ "cell_type": "code",
52
+ "metadata": {},
53
+ "source": [
54
+ "# Task 4: Write your code here:\n",
55
+ "q1_dataset.describe()"
56
+ ],
57
+ "execution_count": null,
58
+ "outputs": []
59
+ },
60
+ {
61
+ "cell_type": "code",
62
+ "metadata": {},
63
+ "source": [
64
+ "# Task 5: Write your code here:\n",
65
+ "q1_dataset[\"Delivery_Time\"].plot()"
66
+ ],
67
+ "execution_count": null,
68
+ "outputs": []
69
+ },
70
+ {
71
+ "cell_type": "code",
72
+ "metadata": {},
73
+ "source": [
74
+ "# Task 1: Write your code here:\n",
75
+ "q1_dataset = q1_dataset.drop([\"Order_ID\"], axis=1)"
76
+ ],
77
+ "execution_count": null,
78
+ "outputs": []
79
+ },
80
+ {
81
+ "cell_type": "code",
82
+ "metadata": {},
83
+ "source": [
84
+ "# Task 2: Write your code here:\n",
85
+ "q1_dataset.isnull().sum()"
86
+ ],
87
+ "execution_count": null,
88
+ "outputs": []
89
+ },
90
+ {
91
+ "cell_type": "code",
92
+ "metadata": {},
93
+ "source": [
94
+ "q1_dataset.shape"
95
+ ],
96
+ "execution_count": null,
97
+ "outputs": []
98
+ },
99
+ {
100
+ "cell_type": "code",
101
+ "metadata": {},
102
+ "source": [
103
+ "# Task 2: Write your code here:\n",
104
+ "\n",
105
+ "# i have 1600 + rows and thus droping wont hurt + my target is also missing\n",
106
+ "q1_dataset = q1_dataset.dropna()\n",
107
+ "q1_dataset.isnull().sum()"
108
+ ],
109
+ "execution_count": null,
110
+ "outputs": []
111
+ },
112
+ {
113
+ "cell_type": "code",
114
+ "metadata": {},
115
+ "source": [
116
+ "q1_dataset.sample(20)\n",
117
+ "# Still there is NaN, i will drop it and the check for other issues"
118
+ ],
119
+ "execution_count": null,
120
+ "outputs": []
121
+ },
122
+ {
123
+ "cell_type": "code",
124
+ "metadata": {},
125
+ "source": [
126
+ "q1_dataset = q1_dataset.dropna(subset = q1_dataset.columns)\n",
127
+ "q1_dataset.value_counts()"
128
+ ],
129
+ "execution_count": null,
130
+ "outputs": []
131
+ },
132
+ {
133
+ "cell_type": "code",
134
+ "metadata": {},
135
+ "source": [
136
+ "q1_dataset = q1_dataset.drop_duplicates()"
137
+ ],
138
+ "execution_count": null,
139
+ "outputs": []
140
+ },
141
+ {
142
+ "cell_type": "code",
143
+ "metadata": {},
144
+ "source": [
145
+ "# Task 4: Write your code here:\n",
146
+ "from sklearn.preprocessing import LabelEncoder, OneHotEncoder\n",
147
+ "\n",
148
+ "# Label encode (ordinal) = [\"Traffic_Level\", ]\n",
149
+ "# onehot (independante values) = [\"Vehicle_Type\", \"Weather\", \"Time_of_Day\"]\n",
150
+ "ordinalEncList = [\"Traffic_Level\"]\n",
151
+ "EncList = [\"Vehicle_Type\", \"Weather\", \"Time_of_Day\", \"Traffic_Level\"]\n",
152
+ "\n",
153
+ "le = LabelEncoder()\n",
154
+ "for item in EncList:\n",
155
+ " q1_dataset[item] = le.fit_transform(q1_dataset[item])\n",
156
+ "\n",
157
+ "\"\"\"\n",
158
+ "oneHot = OneHotEncoder(sparse_output = False)\n",
159
+ "for col in one_hot_EncList:\n",
160
+ " q1_dataset = oneHot.fit_transform(q1_dataset[col])\n",
161
+ "q1 = oneHot.fit_transform(q1_dataset[[\"Weather\", \"Time_of_Day\", \"Vehicle_Type\"]])\n",
162
+ "\"\"\"\n",
163
+ "\n",
164
+ "q1_dataset.head(10)"
165
+ ],
166
+ "execution_count": null,
167
+ "outputs": []
168
+ },
169
+ {
170
+ "cell_type": "code",
171
+ "metadata": {},
172
+ "source": [
173
+ "# Task 5: Write your code here:\n",
174
+ "from sklearn.preprocessing import StandardScaler\n",
175
+ "scaler = StandardScaler()\n",
176
+ "\n",
177
+ "dataset = scaler.fit_transform(q1_dataset.drop([\"Delivery_Time\"], axis=1))\n",
178
+ "\n",
179
+ "dataset\n"
180
+ ],
181
+ "execution_count": null,
182
+ "outputs": []
183
+ },
184
+ {
185
+ "cell_type": "code",
186
+ "metadata": {},
187
+ "source": [
188
+ "# Task 6: Write your code here:\n",
189
+ "q1_dataset[\"Delivery_Time\"].plot(kind = \"hist\")"
190
+ ],
191
+ "execution_count": null,
192
+ "outputs": []
193
+ },
194
+ {
195
+ "cell_type": "code",
196
+ "metadata": {},
197
+ "source": [
198
+ "# Task 1: Write your code here:\n",
199
+ "from sklearn.model_selection import train_test_split\n",
200
+ "\n",
201
+ "Xtrain, Xtest, Ytrain, Ytest = train_test_split(dataset, q1_dataset[\"Delivery_Time\"], test_size=0.2)"
202
+ ],
203
+ "execution_count": null,
204
+ "outputs": []
205
+ },
206
+ {
207
+ "cell_type": "code",
208
+ "metadata": {},
209
+ "source": [
210
+ "Xtrain.shape, Ytrain.shape, Xtest.shape, Ytest.shape"
211
+ ],
212
+ "execution_count": null,
213
+ "outputs": []
214
+ },
215
+ {
216
+ "cell_type": "code",
217
+ "metadata": {},
218
+ "source": [
219
+ "# Task 2,3,4,5: Write your code here:\n",
220
+ "from sklearn.model_selection import KFold\n",
221
+ "from sklearn.ensemble import RandomForestRegressor\n",
222
+ "from sklearn.metrics import mean_absolute_error, mean_squared_error\n",
223
+ "import numpy as np\n",
224
+ "\n",
225
+ "rfr = RandomForestRegressor(n_estimators= 50)\n",
226
+ "kf = KFold(n_splits=5, shuffle=True, random_state=30)\n",
227
+ "\n",
228
+ "mae_scores = []\n",
229
+ "rmse_scores = []\n",
230
+ "\n",
231
+ "for train_idx, val_idx in kf.split(Xtrain):\n",
232
+ " X_fold_train, X_fold_val = Xtrain[train_idx], Xtrain[val_idx]\n",
233
+ " y_fold_train, y_fold_val = Ytrain.iloc[train_idx], Ytrain.iloc[val_idx]\n",
234
+ "\n",
235
+ " # Train and predict\n",
236
+ " rfr.fit(X_fold_train, y_fold_train)\n",
237
+ " y_fold_pred = rfr.predict(X_fold_val)\n",
238
+ "\n",
239
+ " # Calculate metrics\n",
240
+ " mae_scores.append(mean_absolute_error(y_fold_val, y_fold_pred))\n",
241
+ " rmse_scores.append(np.sqrt(mean_squared_error(y_fold_val, y_fold_pred)))\n",
242
+ "\n",
243
+ "mae_scores = np.array(mae_scores)\n",
244
+ "rmse_scores = np.array(rmse_scores)\n",
245
+ "\n",
246
+ "print(f\"5-Fold CV Results:\")\n",
247
+ "print(f\"MAE: ${mae_scores.mean():,.2f}\")\n",
248
+ "print(f\"RMSE: ${rmse_scores.mean():,.2f}\")\n"
249
+ ],
250
+ "execution_count": null,
251
+ "outputs": []
252
+ },
253
+ {
254
+ "cell_type": "code",
255
+ "metadata": {},
256
+ "source": [
257
+ "# Task 1: Write your code here:\n",
258
+ "rfr.feature_importances_"
259
+ ],
260
+ "execution_count": null,
261
+ "outputs": []
262
+ },
263
+ {
264
+ "cell_type": "code",
265
+ "metadata": {},
266
+ "source": [
267
+ "# Task 2: Write your code here:"
268
+ ],
269
+ "execution_count": null,
270
+ "outputs": []
271
+ },
272
+ {
273
+ "cell_type": "code",
274
+ "metadata": {},
275
+ "source": [
276
+ "# Task Bonus: Write your code here:"
277
+ ],
278
+ "execution_count": null,
279
+ "outputs": []
280
+ }
281
+ ],
282
+ "metadata": {
283
+ "kernelspec": {
284
+ "display_name": "Python 3",
285
+ "name": "python3"
286
+ },
287
+ "language_info": {
288
+ "name": "python"
289
+ }
290
+ },
291
+ "nbformat": 4,
292
+ "nbformat_minor": 0
293
+ }
submissions_extracted/1000/Q2.ipynb ADDED
@@ -0,0 +1,400 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "metadata": {},
6
+ "source": [
7
+ "import kagglehub\n",
8
+ "\n",
9
+ "# Download latest version\n",
10
+ "path = kagglehub.dataset_download(\"ANON_OWNER/q2-exam-data\")\n",
11
+ "\n",
12
+ "print(\"Path to dataset files:\", path)"
13
+ ],
14
+ "execution_count": null,
15
+ "outputs": []
16
+ },
17
+ {
18
+ "cell_type": "code",
19
+ "metadata": {},
20
+ "source": [
21
+ "import os\n",
22
+ "import pandas as pd\n",
23
+ "import numpy as np\n",
24
+ "from PIL import Image\n",
25
+ "from sklearn.model_selection import train_test_split\n",
26
+ "\n",
27
+ "# Load Labels\n",
28
+ "labels_df = pd.read_csv(os.path.join(path, \"labels.csv\"))\n",
29
+ "img_dir = os.path.join(path, \"images\")\n",
30
+ "\n",
31
+ "images = []\n",
32
+ "ages = []\n",
33
+ "\n",
34
+ "# Load Images and Resize\n",
35
+ "print(\"Loading images...\")\n",
36
+ "for index, row in labels_df.iterrows():\n",
37
+ " img_name = row.iloc[0]\n",
38
+ " age = row.iloc[1]\n",
39
+ " img_path = os.path.join(img_dir, img_name)\n",
40
+ "\n",
41
+ " if os.path.exists(img_path):\n",
42
+ " img = Image.open(img_path).convert('RGB')\n",
43
+ " img_array = np.array(img) / 255.0 # Normalize pixel values to [0, 1]\n",
44
+ " images.append(img_array)\n",
45
+ " ages.append(age)\n",
46
+ "\n",
47
+ "X = np.array(images)\n",
48
+ "y = np.array(ages)\n",
49
+ "\n",
50
+ "# Transpose image dimensions to match PyTorch format (N, C, H, W)\n",
51
+ "X = np.transpose(X, (0, 3, 1, 2))\n",
52
+ "\n",
53
+ "# Split Data\n",
54
+ "X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)\n",
55
+ "\n",
56
+ "print(f\"X_train shape: {X_train.shape}\")\n",
57
+ "print(f\"X_test shape: {X_test.shape}\")\n",
58
+ "print(f\"y_train shape: {y_train.shape}\")\n",
59
+ "print(f\"y_test shape: {y_test.shape}\")"
60
+ ],
61
+ "execution_count": null,
62
+ "outputs": []
63
+ },
64
+ {
65
+ "cell_type": "code",
66
+ "metadata": {},
67
+ "source": [
68
+ "import torch\n",
69
+ "import torch.nn as nn\n",
70
+ "from torch.optim import Adam\n",
71
+ "from torch.utils.data import DataLoader, dataset, TensorDataset\n",
72
+ "import torch.nn.functional as F\n",
73
+ "from torchvision.datasets import MNIST\n",
74
+ "from torchvision.transforms import ToTensor, Compose, Normalize\n",
75
+ "\n",
76
+ "from sklearn.decomposition import PCA\n",
77
+ "from sklearn.manifold import TSNE\n",
78
+ "from sklearn.cluster import KMeans\n",
79
+ "\n",
80
+ "import matplotlib.pyplot as plt\n",
81
+ "import numpy as np\n",
82
+ "from collections import Counter"
83
+ ],
84
+ "execution_count": null,
85
+ "outputs": []
86
+ },
87
+ {
88
+ "cell_type": "code",
89
+ "metadata": {},
90
+ "source": [
91
+ "# 1. Convert Numpy arrays to PyTorch Tensors\n",
92
+ "X_train = torch.tensor(X_train, dtype=torch.float32)\n",
93
+ "X_test = torch.tensor(X_test, dtype=torch.float32)\n",
94
+ "y_train = torch.tensor(y_train, dtype=torch.float32)\n",
95
+ "y_test = torch.tensor(y_test, dtype=torch.float32)\n"
96
+ ],
97
+ "execution_count": null,
98
+ "outputs": []
99
+ },
100
+ {
101
+ "cell_type": "code",
102
+ "metadata": {},
103
+ "source": [
104
+ "# 2. Create TensorDataset objects\n",
105
+ "train_dataset = TensorDataset(X_train, y_train)\n",
106
+ "test_dataset = TensorDataset(X_test, y_test)"
107
+ ],
108
+ "execution_count": null,
109
+ "outputs": []
110
+ },
111
+ {
112
+ "cell_type": "code",
113
+ "metadata": {},
114
+ "source": [
115
+ "# 3. Create DataLoaders\n",
116
+ "train_loader = DataLoader(\n",
117
+ " train_dataset,\n",
118
+ " batch_size=32,\n",
119
+ " shuffle=True,\n",
120
+ " num_workers=2\n",
121
+ ")\n",
122
+ "# DataLoader for test/validation data\n",
123
+ "test_loader = DataLoader(\n",
124
+ " test_dataset,\n",
125
+ " batch_size=32,\n",
126
+ " shuffle=False,\n",
127
+ " num_workers=2\n",
128
+ ")\n",
129
+ "\n"
130
+ ],
131
+ "execution_count": null,
132
+ "outputs": []
133
+ },
134
+ {
135
+ "cell_type": "code",
136
+ "metadata": {},
137
+ "source": [
138
+ "# 4. Print shape of one batch\n",
139
+ "\n",
140
+ "X_batch, y_batch = next(iter(train_loader))\n",
141
+ "print(f\"Training batch input shape: {X_batch.shape}\")\n",
142
+ "print(f\"Training batch labels shape: {y_batch.shape}\")"
143
+ ],
144
+ "execution_count": null,
145
+ "outputs": []
146
+ },
147
+ {
148
+ "cell_type": "code",
149
+ "metadata": {},
150
+ "source": [
151
+ "# 5. Display sample images\n",
152
+ "\n",
153
+ "# Get one batch of images and labels\n",
154
+ "images, labels = next(iter(train_loader))\n",
155
+ "\n",
156
+ "# Display the first 6 images in the batch\n",
157
+ "plt.figure(figsize=(8, 4))\n",
158
+ "image = images.squeeze()\n",
159
+ "image = image[32,3, :]\n",
160
+ "plt.imshow(images.squeeze())\n",
161
+ "plt.axis('off')\n",
162
+ "\n",
163
+ "plt.tight_layout()\n",
164
+ "plt.show()\n"
165
+ ],
166
+ "execution_count": null,
167
+ "outputs": []
168
+ },
169
+ {
170
+ "cell_type": "code",
171
+ "metadata": {},
172
+ "source": [
173
+ "# Task 1: Write your model class here:\n",
174
+ "class NN4Layer(nn.Module):\n",
175
+ "\n",
176
+ " def __init__(self, input_dim, hidden_dim, output_dim):\n",
177
+ " super(NN4Layer, self).__init__()\n",
178
+ "\n",
179
+ " # First linear layer: input features -> hidden layer\n",
180
+ " self.layer1 = nn.Linear(input_dim, hidden_dim)\n",
181
+ "\n",
182
+ " # Second linear layer: hidden layer -> hidden layer\n",
183
+ " self.layer2 = nn.Linear(hidden_dim, hidden_dim)\n",
184
+ "\n",
185
+ " # 3rd linear layer: hidden layer -> hidden layer\n",
186
+ " self.layer3 = nn.Linear(hidden_dim, hidden_dim)\n",
187
+ "\n",
188
+ " # Output layer: hidden layer -> number of classes (logits)\n",
189
+ " self.layer4 = nn.Linear(hidden_dim, 1)\n",
190
+ "\n",
191
+ " # ReLU activation for non-linearity\n",
192
+ " self.relu = nn.ReLU()\n",
193
+ " #self.linear = nn.Linear()\n",
194
+ "\n",
195
+ " # Defines how input data flows through the network\n",
196
+ " def forward(self, x):\n",
197
+ " # First hidden layer\n",
198
+ " z1 = self.layer1(x)\n",
199
+ " a1 = self.relu(z1)\n",
200
+ "\n",
201
+ " # Second hidden layer\n",
202
+ " z2 = self.layer2(a1)\n",
203
+ " a2 = self.relu(z2)\n",
204
+ "\n",
205
+ " z3 = self.layer3(a2)\n",
206
+ " a3 = self.relu(z3)\n",
207
+ "\n",
208
+ " # Output layer (raw scores / logits)\n",
209
+ " output = self.linear(a3) # there is something missing here, remember? :)\n",
210
+ "\n",
211
+ " return output\n"
212
+ ],
213
+ "execution_count": null,
214
+ "outputs": []
215
+ },
216
+ {
217
+ "cell_type": "code",
218
+ "metadata": {},
219
+ "source": [
220
+ "# Task 2: Write your training loop here:\n",
221
+ "def train_one_epoch(model, optimizer, criterion, train_loader, device):\n",
222
+ " # Set the model to training mode\n",
223
+ " model.train()\n",
224
+ "\n",
225
+ " running_loss = 0.0\n",
226
+ "\n",
227
+ " for X_batch, y_batch in train_loader:\n",
228
+ " # Move batch to the selected device\n",
229
+ " X_batch = X_batch.view(X_batch.size(0), -1).to(device)\n",
230
+ " y_batch = y_batch.to(device)\n",
231
+ "\n",
232
+ " # Forward pass\n",
233
+ " outputs = model(X_batch) # shape: (batch_size, 10)\n",
234
+ " loss = criterion(outputs, y_batch)\n",
235
+ "\n",
236
+ " # Backward pass & optimization\n",
237
+ " optimizer.zero_grad() # Clear previous gradients\n",
238
+ " loss.backward() # Compute gradients\n",
239
+ " optimizer.step() # Update model parameters\n",
240
+ "\n",
241
+ " running_loss += loss.item()\n",
242
+ "\n",
243
+ " # Average loss over all batches\n",
244
+ " avg_loss = running_loss / len(train_loader)\n",
245
+ "\n",
246
+ " return avg_loss"
247
+ ],
248
+ "execution_count": null,
249
+ "outputs": []
250
+ },
251
+ {
252
+ "cell_type": "code",
253
+ "metadata": {},
254
+ "source": [
255
+ "# Task 3: Write your validation loop here:\n",
256
+ "def validate(model, criterion, test_loader, device):\n",
257
+ " # Set the model to evaluation mode\n",
258
+ " model.eval()\n",
259
+ "\n",
260
+ " running_loss = 0.0\n",
261
+ " correct = 0\n",
262
+ " total = 0\n",
263
+ "\n",
264
+ " with torch.no_grad():\n",
265
+ " for X_batch, y_batch in test_loader:\n",
266
+ " # Move data to device\n",
267
+ " X_batch = X_batch.view(X_batch.size(0), -1).to(device)\n",
268
+ " y_batch = y_batch.to(device)\n",
269
+ "\n",
270
+ " # Forward pass\n",
271
+ " outputs = model(X_batch) # shape: (batch_size, 10)\n",
272
+ " loss = criterion(outputs, y_batch)\n",
273
+ " running_loss += loss.item()\n",
274
+ "\n",
275
+ " # Apply Softmax to get probabilities\n",
276
+ " probabilities = F.softmax(outputs, dim=1)\n",
277
+ "\n",
278
+ " # Multiclass predictions\n",
279
+ " predicted = torch.argmax(probabilities, dim=1)\n",
280
+ "\n",
281
+ " # Accuracy calculation\n",
282
+ " correct += (predicted == y_batch).sum().item()\n",
283
+ " total += y_batch.size(0)\n",
284
+ "\n",
285
+ " avg_loss = running_loss / len(test_loader)\n",
286
+ " accuracy = correct / total\n",
287
+ "\n",
288
+ " return avg_loss, accuracy\n"
289
+ ],
290
+ "execution_count": null,
291
+ "outputs": []
292
+ },
293
+ {
294
+ "cell_type": "code",
295
+ "metadata": {},
296
+ "source": [
297
+ "# Task 4: Define device, model, loss, optimizer:\n",
298
+ "# Device setup\n",
299
+ "device = torch.device(\"cuda\" if torch.cuda.is_available() else \"cpu\")\n",
300
+ "\n",
301
+ "# Model parameters\n",
302
+ "input_dim = 36 * 36 # MNIST images flattened\n",
303
+ "hidden_dim = 64 # Design choice\n",
304
+ "output_dim = 1 # Digits 0–9\n",
305
+ "\n",
306
+ "# Instantiate model\n",
307
+ "model = NN4Layer(input_dim, hidden_dim, output_dim).to(device)\n",
308
+ "\n",
309
+ "# Print the model architecture\n",
310
+ "print(\"Model Architecture:\\n\")\n",
311
+ "print(model)\n",
312
+ "\n",
313
+ "# Calculate the total number of trainable parameters\n",
314
+ "total_params = sum(p.numel() for p in model.parameters() if p.requires_grad)\n",
315
+ "print(f\"\\nTotal trainable parameters: {total_params}\")"
316
+ ],
317
+ "execution_count": null,
318
+ "outputs": []
319
+ },
320
+ {
321
+ "cell_type": "code",
322
+ "metadata": {},
323
+ "source": [
324
+ "# Task 5: Start training for 20 epochs:\n",
325
+ "num_epochs = 20\n",
326
+ "learning_rate = 0.001\n",
327
+ "\n",
328
+ "# Define criterion (loss function) - using CrossEntropyLoss as model now outputs logits\n",
329
+ "criterion = nn.MSELoss()\n",
330
+ "# Define optimizer\n",
331
+ "optimizer = Adam(model.parameters(), learning_rate)\n",
332
+ "\n",
333
+ "\n",
334
+ "# Run Training\n",
335
+ "train_losses = []\n",
336
+ "val_losses = []\n",
337
+ "val_accuracies = []\n",
338
+ "\n",
339
+ "print('Starting Training...')\n",
340
+ "for epoch in range(num_epochs):\n",
341
+ " # Train one epoch\n",
342
+ " train_loss = train_one_epoch(model, optimizer, criterion, train_loader, device)\n",
343
+ "\n",
344
+ " # Validate\n",
345
+ " val_loss, val_accuracy = validate(model, criterion, test_loader, device)\n",
346
+ "\n",
347
+ " train_losses.append(train_loss)\n",
348
+ " val_losses.append(val_loss)\n",
349
+ " val_accuracies.append(val_accuracy)\n",
350
+ "\n",
351
+ " print(f'Epoch [{epoch+1}/{num_epochs}], Train Loss: {train_loss:.4f}, Val Loss: {val_loss:.4f}, Val Accuracy: {val_accuracy:.4f}')\n",
352
+ "\n",
353
+ "print('Training Complete!')"
354
+ ],
355
+ "execution_count": null,
356
+ "outputs": []
357
+ },
358
+ {
359
+ "cell_type": "code",
360
+ "metadata": {},
361
+ "source": [
362
+ "# Task 1: Write your code here:\n",
363
+ "# Plotting results\n",
364
+ "plt.figure(figsize=(7, 5))\n",
365
+ "\n",
366
+ "plt.plot(train_losses, label='Train Loss')\n",
367
+ "plt.plot(val_losses, label='Validation Loss')\n",
368
+ "plt.title('Loss over Epochs')\n",
369
+ "plt.xlabel('Epoch')\n",
370
+ "plt.ylabel('Loss')\n",
371
+ "plt.legend()\n",
372
+ "\n",
373
+ "plt.tight_layout()\n",
374
+ "plt.show()"
375
+ ],
376
+ "execution_count": null,
377
+ "outputs": []
378
+ },
379
+ {
380
+ "cell_type": "code",
381
+ "metadata": {},
382
+ "source": [
383
+ "# Task 2 (Bonus): Write your code here:"
384
+ ],
385
+ "execution_count": null,
386
+ "outputs": []
387
+ }
388
+ ],
389
+ "metadata": {
390
+ "kernelspec": {
391
+ "display_name": "Python 3",
392
+ "name": "python3"
393
+ },
394
+ "language_info": {
395
+ "name": "python"
396
+ }
397
+ },
398
+ "nbformat": 4,
399
+ "nbformat_minor": 0
400
+ }
submissions_extracted/1000/Q3.ipynb ADDED
@@ -0,0 +1,257 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "metadata": {},
6
+ "source": [
7
+ "import kagglehub\n",
8
+ "\n",
9
+ "\n",
10
+ "\n",
11
+ "# Download latest version\n",
12
+ "\n",
13
+ "path = kagglehub.dataset_download(\"ANON_OWNER/q3-exam-data\")\n",
14
+ "\n",
15
+ "\n",
16
+ "\n",
17
+ "print(\"Path to dataset files:\", path)"
18
+ ],
19
+ "execution_count": null,
20
+ "outputs": []
21
+ },
22
+ {
23
+ "cell_type": "code",
24
+ "metadata": {},
25
+ "source": [
26
+ "# Task 1: Write your code here:\n",
27
+ "import pandas\n",
28
+ "import os\n",
29
+ "q3_path = os.path.join(path, 'Q3_data.csv')\n",
30
+ "q3_dataset = pandas.read_csv(q3_path)"
31
+ ],
32
+ "execution_count": null,
33
+ "outputs": []
34
+ },
35
+ {
36
+ "cell_type": "code",
37
+ "metadata": {},
38
+ "source": [
39
+ "# Task 2: Write your code here:\n",
40
+ "q3_dataset.head(10)"
41
+ ],
42
+ "execution_count": null,
43
+ "outputs": []
44
+ },
45
+ {
46
+ "cell_type": "code",
47
+ "metadata": {},
48
+ "source": [
49
+ "# Task 3: Write your code here:\n",
50
+ "q3_dataset.info()"
51
+ ],
52
+ "execution_count": null,
53
+ "outputs": []
54
+ },
55
+ {
56
+ "cell_type": "code",
57
+ "metadata": {},
58
+ "source": [
59
+ "# Task 4: Write your code here:\n",
60
+ "q3_dataset.describe()"
61
+ ],
62
+ "execution_count": null,
63
+ "outputs": []
64
+ },
65
+ {
66
+ "cell_type": "code",
67
+ "metadata": {},
68
+ "source": [
69
+ "q3_dataset.shape"
70
+ ],
71
+ "execution_count": null,
72
+ "outputs": []
73
+ },
74
+ {
75
+ "cell_type": "code",
76
+ "metadata": {},
77
+ "source": [
78
+ "# Task 1: Write your code here:\n",
79
+ "q3_dataset.isna().sum()"
80
+ ],
81
+ "execution_count": null,
82
+ "outputs": []
83
+ },
84
+ {
85
+ "cell_type": "code",
86
+ "metadata": {},
87
+ "source": [
88
+ "q3_dataset = q3_dataset.dropna(axis = 1)\n",
89
+ "q3_dataset.isna().sum()"
90
+ ],
91
+ "execution_count": null,
92
+ "outputs": []
93
+ },
94
+ {
95
+ "cell_type": "code",
96
+ "metadata": {},
97
+ "source": [
98
+ "q3_dataset.shape"
99
+ ],
100
+ "execution_count": null,
101
+ "outputs": []
102
+ },
103
+ {
104
+ "cell_type": "code",
105
+ "metadata": {},
106
+ "source": [
107
+ "# Task 2: Write your code here:\n",
108
+ "q3_dataset = q3_dataset.drop_duplicates(keep=\"first\")\n",
109
+ "q3_dataset.shape"
110
+ ],
111
+ "execution_count": null,
112
+ "outputs": []
113
+ },
114
+ {
115
+ "cell_type": "code",
116
+ "metadata": {},
117
+ "source": [
118
+ "# Task 3: Write your code here: Encode categorical variables if needed\n",
119
+ "# No need its all not categorical variables to my knowledge nor endoded categorica that got labeled using lebel encoder to one hot (how do i know?)\n",
120
+ "q3_dataset.head()"
121
+ ],
122
+ "execution_count": null,
123
+ "outputs": []
124
+ },
125
+ {
126
+ "cell_type": "code",
127
+ "metadata": {},
128
+ "source": [
129
+ "# Task 4: Write your code here: Apply feature scaling to numerical features (Use StandardScaler)\n",
130
+ "\n",
131
+ "# Answer: Based on the describe table above most values looks to be already transformed!!\n",
132
+ "# Task 5: Write your code here:\n",
133
+ "from sklearn.preprocessing import StandardScaler\n",
134
+ "scaler = StandardScaler()\n",
135
+ "\n",
136
+ "dataset = scaler.fit_transform(q3_dataset.drop([\"Target\"], axis=1))\n"
137
+ ],
138
+ "execution_count": null,
139
+ "outputs": []
140
+ },
141
+ {
142
+ "cell_type": "code",
143
+ "metadata": {},
144
+ "source": [],
145
+ "execution_count": null,
146
+ "outputs": []
147
+ },
148
+ {
149
+ "cell_type": "code",
150
+ "metadata": {},
151
+ "source": [
152
+ "# Task 5: Write your code here: Check for target imbalance and state if it is imbalanced or not\n",
153
+ "q3_dataset[\"Target\"].plot(kind=\"hist\")\n",
154
+ "\n",
155
+ "# Its Unbalanced"
156
+ ],
157
+ "execution_count": null,
158
+ "outputs": []
159
+ },
160
+ {
161
+ "cell_type": "code",
162
+ "metadata": {},
163
+ "source": [
164
+ "# Task 1: Write your code here:\n",
165
+ "X_features = dataset\n",
166
+ "Y_target = q3_dataset[\"Target\"]\n",
167
+ "\n",
168
+ "# Task 1: Write your code here:\n",
169
+ "from sklearn.model_selection import train_test_split\n",
170
+ "\n",
171
+ "X_train, X_test, Y_train, Y_test = train_test_split(dataset, Y_target, test_size=0.2)"
172
+ ],
173
+ "execution_count": null,
174
+ "outputs": []
175
+ },
176
+ {
177
+ "cell_type": "code",
178
+ "metadata": {},
179
+ "source": [
180
+ "# Task 2,3,4,5: Write your code here:\n",
181
+ "#%pip install catboost\n",
182
+ "from catboost import CatBoostClassifier\n",
183
+ "\n",
184
+ "# Task 2,3,4,5: Write your code here:\n",
185
+ "from sklearn.model_selection import KFold\n",
186
+ "from sklearn.metrics import accuracy_score, f1_score\n",
187
+ "import numpy as np\n",
188
+ "\n",
189
+ "cat = CatBoostClassifier(iterations= 100, learning_rate= 0.001)\n",
190
+ "kf = KFold(n_splits=5, shuffle=True, random_state=30)\n",
191
+ "\n",
192
+ "acc_scores = []\n",
193
+ "f1_scores = []\n",
194
+ "\n",
195
+ "for train_idx, val_idx in kf.split(X_train):\n",
196
+ " X_fold_train, X_fold_val = X_train[train_idx], X_train[val_idx]\n",
197
+ " y_fold_train, y_fold_val = Y_train.iloc[train_idx], Y_train.iloc[val_idx]\n",
198
+ "\n",
199
+ " # Train and predict\n",
200
+ " cat.fit(X_fold_train, y_fold_train)\n",
201
+ " y_fold_pred = cat.predict(X_fold_val)\n",
202
+ "\n",
203
+ " # Calculate metrics\n",
204
+ " acc_scores.append(accuracy_score(y_fold_val, y_fold_pred))\n",
205
+ " f1_scores.append(np.sqrt(accuracy_score(y_fold_val, y_fold_pred)))\n",
206
+ "\n",
207
+ "acc_scores = np.array(acc_scores)\n",
208
+ "f1_scores = np.array(f1_scores)\n",
209
+ "\n",
210
+ "print(f\"5-Fold CV Results:\")\n",
211
+ "print(f\"Mean F1 across folds (Primary Metric Due to unbalance): %{(f1_scores.mean()*100):,.2f}\")\n",
212
+ "print(f\"Mean Accuracy Score: %{(acc_scores.mean()*100):,.2f}\")\n"
213
+ ],
214
+ "execution_count": null,
215
+ "outputs": []
216
+ },
217
+ {
218
+ "cell_type": "code",
219
+ "metadata": {},
220
+ "source": [
221
+ "# Task 1: Write your code here:\n",
222
+ "cat.feature_importances_"
223
+ ],
224
+ "execution_count": null,
225
+ "outputs": []
226
+ },
227
+ {
228
+ "cell_type": "code",
229
+ "metadata": {},
230
+ "source": [
231
+ "# Task 2: Write your code here:"
232
+ ],
233
+ "execution_count": null,
234
+ "outputs": []
235
+ },
236
+ {
237
+ "cell_type": "code",
238
+ "metadata": {},
239
+ "source": [
240
+ "# Task Bonus: Write your code here:"
241
+ ],
242
+ "execution_count": null,
243
+ "outputs": []
244
+ }
245
+ ],
246
+ "metadata": {
247
+ "kernelspec": {
248
+ "display_name": "Python 3",
249
+ "name": "python3"
250
+ },
251
+ "language_info": {
252
+ "name": "python"
253
+ }
254
+ },
255
+ "nbformat": 4,
256
+ "nbformat_minor": 0
257
+ }
submissions_extracted/1001/Q1.ipynb ADDED
@@ -0,0 +1,229 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "metadata": {},
6
+ "source": [
7
+ "import pandas as pd\n",
8
+ "import numpy as np\n",
9
+ "import matplotlib.pyplot as plt\n",
10
+ "import seaborn as sns\n",
11
+ "import kagglehub\n",
12
+ "import os\n",
13
+ "from tqdm import tqdm\n",
14
+ "\n",
15
+ "from sklearn.preprocessing import OneHotEncoder\n",
16
+ "from sklearn.model_selection import train_test_split\n",
17
+ "\n",
18
+ "%matplotlib inline"
19
+ ],
20
+ "execution_count": null,
21
+ "outputs": []
22
+ },
23
+ {
24
+ "cell_type": "code",
25
+ "metadata": {},
26
+ "source": [
27
+ "# Download latest version\n",
28
+ "path = kagglehub.dataset_download(\"ANON_OWNER/q1-exam-data\")\n",
29
+ "\n",
30
+ "print(\"Path to dataset files:\", path)"
31
+ ],
32
+ "execution_count": null,
33
+ "outputs": []
34
+ },
35
+ {
36
+ "cell_type": "code",
37
+ "metadata": {},
38
+ "source": [
39
+ "# Task 1: Write your code here:\n",
40
+ "csv_path = os.path.join(path, 'Q1_data.csv')\n",
41
+ "df = pd.read_csv(csv_path)"
42
+ ],
43
+ "execution_count": null,
44
+ "outputs": []
45
+ },
46
+ {
47
+ "cell_type": "code",
48
+ "metadata": {},
49
+ "source": [
50
+ "# Task 2: Write your code here:\n",
51
+ "df.head()"
52
+ ],
53
+ "execution_count": null,
54
+ "outputs": []
55
+ },
56
+ {
57
+ "cell_type": "code",
58
+ "metadata": {},
59
+ "source": [
60
+ "# Task 3: Write your code here:\n",
61
+ "df.info()"
62
+ ],
63
+ "execution_count": null,
64
+ "outputs": []
65
+ },
66
+ {
67
+ "cell_type": "code",
68
+ "metadata": {},
69
+ "source": [
70
+ "# Task 4: Write your code here:\n",
71
+ "df.describe()"
72
+ ],
73
+ "execution_count": null,
74
+ "outputs": []
75
+ },
76
+ {
77
+ "cell_type": "code",
78
+ "metadata": {},
79
+ "source": [
80
+ "# Task 5: Write your code here:\n",
81
+ "def check_target_distribution(df, target_column):\n",
82
+ " df[target_column].hist(bins=30, edgecolor='black')\n",
83
+ "\n",
84
+ " plt.title(f\"Target Distribution ({target_column})\")\n",
85
+ " plt.xlabel(target_column)\n",
86
+ " plt.ylabel(\"Delivery_Time\")\n",
87
+ " plt.grid(False)\n",
88
+ "\n",
89
+ " plt.show()\n",
90
+ "\n",
91
+ "check_target_distribution(df, \"Delivery_Time\")"
92
+ ],
93
+ "execution_count": null,
94
+ "outputs": []
95
+ },
96
+ {
97
+ "cell_type": "code",
98
+ "metadata": {},
99
+ "source": [
100
+ "# Task 1: Write your code here:\n",
101
+ "df.drop(columns=['Order_ID'])"
102
+ ],
103
+ "execution_count": null,
104
+ "outputs": []
105
+ },
106
+ {
107
+ "cell_type": "code",
108
+ "metadata": {},
109
+ "source": [
110
+ "# Task 2: Write your code here:\n",
111
+ "# Missing values\n",
112
+ "print(\"Missing values:\")\n",
113
+ "print(df.isnull().sum())"
114
+ ],
115
+ "execution_count": null,
116
+ "outputs": []
117
+ },
118
+ {
119
+ "cell_type": "code",
120
+ "metadata": {},
121
+ "source": [
122
+ "# Task 3: Write your code here:\n",
123
+ "# Duplicates\n",
124
+ "print(\"Duplicates:\")\n",
125
+ "print(df.duplicated().sum())"
126
+ ],
127
+ "execution_count": null,
128
+ "outputs": []
129
+ },
130
+ {
131
+ "cell_type": "code",
132
+ "metadata": {},
133
+ "source": [
134
+ "#Remove duplicates\n",
135
+ "df.drop_duplicates(inplace=True)"
136
+ ],
137
+ "execution_count": null,
138
+ "outputs": []
139
+ },
140
+ {
141
+ "cell_type": "code",
142
+ "metadata": {},
143
+ "source": [
144
+ "# Task 4: Write your code here:\n",
145
+ "categorical_cols = df.select_dtypes(include=[\"object\"]).columns\n",
146
+ "\n",
147
+ "print(\"Categorical Columns:\", list(categorical_cols))"
148
+ ],
149
+ "execution_count": null,
150
+ "outputs": []
151
+ },
152
+ {
153
+ "cell_type": "code",
154
+ "metadata": {},
155
+ "source": [
156
+ "# Task 5: Write your code here:"
157
+ ],
158
+ "execution_count": null,
159
+ "outputs": []
160
+ },
161
+ {
162
+ "cell_type": "code",
163
+ "metadata": {},
164
+ "source": [
165
+ "# Task 6: Write your code here:"
166
+ ],
167
+ "execution_count": null,
168
+ "outputs": []
169
+ },
170
+ {
171
+ "cell_type": "code",
172
+ "metadata": {},
173
+ "source": [
174
+ "# Task 1: Write your code here:\n",
175
+ "X = df\n",
176
+ "y = df"
177
+ ],
178
+ "execution_count": null,
179
+ "outputs": []
180
+ },
181
+ {
182
+ "cell_type": "code",
183
+ "metadata": {},
184
+ "source": [
185
+ "# Task 2,3,4,5: Write your code here:"
186
+ ],
187
+ "execution_count": null,
188
+ "outputs": []
189
+ },
190
+ {
191
+ "cell_type": "code",
192
+ "metadata": {},
193
+ "source": [
194
+ "# Task 1: Write your code here:"
195
+ ],
196
+ "execution_count": null,
197
+ "outputs": []
198
+ },
199
+ {
200
+ "cell_type": "code",
201
+ "metadata": {},
202
+ "source": [
203
+ "# Task 2: Write your code here:"
204
+ ],
205
+ "execution_count": null,
206
+ "outputs": []
207
+ },
208
+ {
209
+ "cell_type": "code",
210
+ "metadata": {},
211
+ "source": [
212
+ "# Task Bonus: Write your code here:"
213
+ ],
214
+ "execution_count": null,
215
+ "outputs": []
216
+ }
217
+ ],
218
+ "metadata": {
219
+ "kernelspec": {
220
+ "display_name": "Python 3",
221
+ "name": "python3"
222
+ },
223
+ "language_info": {
224
+ "name": "python"
225
+ }
226
+ },
227
+ "nbformat": 4,
228
+ "nbformat_minor": 0
229
+ }
submissions_extracted/1001/Q2.ipynb ADDED
@@ -0,0 +1,198 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "metadata": {},
6
+ "source": [
7
+ "import kagglehub\n",
8
+ "\n",
9
+ "# Download latest version\n",
10
+ "path = kagglehub.dataset_download(\"ANON_OWNER/q2-exam-data\")\n",
11
+ "\n",
12
+ "print(\"Path to dataset files:\", path)"
13
+ ],
14
+ "execution_count": null,
15
+ "outputs": []
16
+ },
17
+ {
18
+ "cell_type": "code",
19
+ "metadata": {},
20
+ "source": [
21
+ "import os\n",
22
+ "import pandas as pd\n",
23
+ "import numpy as np\n",
24
+ "from PIL import Image\n",
25
+ "from sklearn.model_selection import train_test_split\n",
26
+ "\n",
27
+ "# Load Labels\n",
28
+ "labels_df = pd.read_csv(os.path.join(path, \"labels.csv\"))\n",
29
+ "img_dir = os.path.join(path, \"images\")\n",
30
+ "\n",
31
+ "images = []\n",
32
+ "ages = []\n",
33
+ "\n",
34
+ "# Load Images and Resize\n",
35
+ "print(\"Loading images...\")\n",
36
+ "for index, row in labels_df.iterrows():\n",
37
+ " img_name = row.iloc[0]\n",
38
+ " age = row.iloc[1]\n",
39
+ " img_path = os.path.join(img_dir, img_name)\n",
40
+ "\n",
41
+ " if os.path.exists(img_path):\n",
42
+ " img = Image.open(img_path).convert('RGB')\n",
43
+ " img_array = np.array(img) / 255.0 # Normalize pixel values to [0, 1]\n",
44
+ " images.append(img_array)\n",
45
+ " ages.append(age)\n",
46
+ "\n",
47
+ "X = np.array(images)\n",
48
+ "y = np.array(ages)\n",
49
+ "\n",
50
+ "# Transpose image dimensions to match PyTorch format (N, C, H, W)\n",
51
+ "X = np.transpose(X, (0, 3, 1, 2))\n",
52
+ "\n",
53
+ "# Split Data\n",
54
+ "X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)\n",
55
+ "\n",
56
+ "print(f\"X_train shape: {X_train.shape}\")\n",
57
+ "print(f\"X_test shape: {X_test.shape}\")\n",
58
+ "print(f\"y_train shape: {y_train.shape}\")\n",
59
+ "print(f\"y_test shape: {y_test.shape}\")"
60
+ ],
61
+ "execution_count": null,
62
+ "outputs": []
63
+ },
64
+ {
65
+ "cell_type": "code",
66
+ "metadata": {},
67
+ "source": [
68
+ "# 1. Convert Numpy arrays to PyTorch Tensors\n",
69
+ "import torch\n",
70
+ "\n",
71
+ "# Create tensors\n",
72
+ "X_train = torch.tensor([1.0, 2.0, 3.0])\n",
73
+ "y_train = torch.randn(3)\n",
74
+ "print(\"x:\", x)\n",
75
+ "print(\"y:\", y)\n",
76
+ "\n"
77
+ ],
78
+ "execution_count": null,
79
+ "outputs": []
80
+ },
81
+ {
82
+ "cell_type": "code",
83
+ "metadata": {},
84
+ "source": [
85
+ "# 2. Create TensorDataset objects\n",
86
+ "\n",
87
+ "\n"
88
+ ],
89
+ "execution_count": null,
90
+ "outputs": []
91
+ },
92
+ {
93
+ "cell_type": "code",
94
+ "metadata": {},
95
+ "source": [
96
+ "# 3. Create DataLoaders\n",
97
+ "\n",
98
+ "\n"
99
+ ],
100
+ "execution_count": null,
101
+ "outputs": []
102
+ },
103
+ {
104
+ "cell_type": "code",
105
+ "metadata": {},
106
+ "source": [
107
+ "# 4. Print shape of one batch\n",
108
+ "\n"
109
+ ],
110
+ "execution_count": null,
111
+ "outputs": []
112
+ },
113
+ {
114
+ "cell_type": "code",
115
+ "metadata": {},
116
+ "source": [
117
+ "# 5. Display sample images\n",
118
+ "\n"
119
+ ],
120
+ "execution_count": null,
121
+ "outputs": []
122
+ },
123
+ {
124
+ "cell_type": "code",
125
+ "metadata": {},
126
+ "source": [
127
+ "# Task 1: Write your model class here:"
128
+ ],
129
+ "execution_count": null,
130
+ "outputs": []
131
+ },
132
+ {
133
+ "cell_type": "code",
134
+ "metadata": {},
135
+ "source": [
136
+ "# Task 2: Write your training loop here:"
137
+ ],
138
+ "execution_count": null,
139
+ "outputs": []
140
+ },
141
+ {
142
+ "cell_type": "code",
143
+ "metadata": {},
144
+ "source": [
145
+ "# Task 3: Write your validation loop here:"
146
+ ],
147
+ "execution_count": null,
148
+ "outputs": []
149
+ },
150
+ {
151
+ "cell_type": "code",
152
+ "metadata": {},
153
+ "source": [
154
+ "# Task 4: Define device, model, loss, optimizer:"
155
+ ],
156
+ "execution_count": null,
157
+ "outputs": []
158
+ },
159
+ {
160
+ "cell_type": "code",
161
+ "metadata": {},
162
+ "source": [
163
+ "# Task 5: Start training for 20 epochs:"
164
+ ],
165
+ "execution_count": null,
166
+ "outputs": []
167
+ },
168
+ {
169
+ "cell_type": "code",
170
+ "metadata": {},
171
+ "source": [
172
+ "# Task 1: Write your code here:"
173
+ ],
174
+ "execution_count": null,
175
+ "outputs": []
176
+ },
177
+ {
178
+ "cell_type": "code",
179
+ "metadata": {},
180
+ "source": [
181
+ "# Task 2 (Bonus): Write your code here:"
182
+ ],
183
+ "execution_count": null,
184
+ "outputs": []
185
+ }
186
+ ],
187
+ "metadata": {
188
+ "kernelspec": {
189
+ "display_name": "Python 3",
190
+ "name": "python3"
191
+ },
192
+ "language_info": {
193
+ "name": "python"
194
+ }
195
+ },
196
+ "nbformat": 4,
197
+ "nbformat_minor": 0
198
+ }
submissions_extracted/1001/Q3.ipynb ADDED
@@ -0,0 +1,160 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "metadata": {},
6
+ "source": [
7
+ "import kagglehub\n",
8
+ "\n",
9
+ "\n",
10
+ "\n",
11
+ "# Download latest version\n",
12
+ "\n",
13
+ "path = kagglehub.dataset_download(\"ANON_OWNER/q3-exam-data\")\n",
14
+ "\n",
15
+ "\n",
16
+ "\n",
17
+ "print(\"Path to dataset files:\", path)"
18
+ ],
19
+ "execution_count": null,
20
+ "outputs": []
21
+ },
22
+ {
23
+ "cell_type": "code",
24
+ "metadata": {},
25
+ "source": [
26
+ "# Task 1: Write your code here:"
27
+ ],
28
+ "execution_count": null,
29
+ "outputs": []
30
+ },
31
+ {
32
+ "cell_type": "code",
33
+ "metadata": {},
34
+ "source": [
35
+ "# Task 2: Write your code here:"
36
+ ],
37
+ "execution_count": null,
38
+ "outputs": []
39
+ },
40
+ {
41
+ "cell_type": "code",
42
+ "metadata": {},
43
+ "source": [
44
+ "# Task 3: Write your code here:"
45
+ ],
46
+ "execution_count": null,
47
+ "outputs": []
48
+ },
49
+ {
50
+ "cell_type": "code",
51
+ "metadata": {},
52
+ "source": [
53
+ "# Task 4: Write your code here:"
54
+ ],
55
+ "execution_count": null,
56
+ "outputs": []
57
+ },
58
+ {
59
+ "cell_type": "code",
60
+ "metadata": {},
61
+ "source": [
62
+ "# Task 1: Write your code here:"
63
+ ],
64
+ "execution_count": null,
65
+ "outputs": []
66
+ },
67
+ {
68
+ "cell_type": "code",
69
+ "metadata": {},
70
+ "source": [
71
+ "# Task 2: Write your code here:"
72
+ ],
73
+ "execution_count": null,
74
+ "outputs": []
75
+ },
76
+ {
77
+ "cell_type": "code",
78
+ "metadata": {},
79
+ "source": [
80
+ "# Task 3: Write your code here:"
81
+ ],
82
+ "execution_count": null,
83
+ "outputs": []
84
+ },
85
+ {
86
+ "cell_type": "code",
87
+ "metadata": {},
88
+ "source": [
89
+ "# Task 4: Write your code here:"
90
+ ],
91
+ "execution_count": null,
92
+ "outputs": []
93
+ },
94
+ {
95
+ "cell_type": "code",
96
+ "metadata": {},
97
+ "source": [
98
+ "# Task 5: Write your code here:"
99
+ ],
100
+ "execution_count": null,
101
+ "outputs": []
102
+ },
103
+ {
104
+ "cell_type": "code",
105
+ "metadata": {},
106
+ "source": [
107
+ "# Task 1: Write your code here:"
108
+ ],
109
+ "execution_count": null,
110
+ "outputs": []
111
+ },
112
+ {
113
+ "cell_type": "code",
114
+ "metadata": {},
115
+ "source": [
116
+ "# Task 2,3,4,5: Write your code here:"
117
+ ],
118
+ "execution_count": null,
119
+ "outputs": []
120
+ },
121
+ {
122
+ "cell_type": "code",
123
+ "metadata": {},
124
+ "source": [
125
+ "# Task 1: Write your code here:"
126
+ ],
127
+ "execution_count": null,
128
+ "outputs": []
129
+ },
130
+ {
131
+ "cell_type": "code",
132
+ "metadata": {},
133
+ "source": [
134
+ "# Task 2: Write your code here:"
135
+ ],
136
+ "execution_count": null,
137
+ "outputs": []
138
+ },
139
+ {
140
+ "cell_type": "code",
141
+ "metadata": {},
142
+ "source": [
143
+ "# Task Bonus: Write your code here:"
144
+ ],
145
+ "execution_count": null,
146
+ "outputs": []
147
+ }
148
+ ],
149
+ "metadata": {
150
+ "kernelspec": {
151
+ "display_name": "Python 3",
152
+ "name": "python3"
153
+ },
154
+ "language_info": {
155
+ "name": "python"
156
+ }
157
+ },
158
+ "nbformat": 4,
159
+ "nbformat_minor": 0
160
+ }
submissions_extracted/1002/Q1.ipynb ADDED
@@ -0,0 +1,286 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "metadata": {},
6
+ "source": [
7
+ "import kagglehub\n",
8
+ "import os\n",
9
+ "import pandas as pd\n",
10
+ "import numpy as np\n",
11
+ "import matplotlib.pyplot as plt\n",
12
+ "%matplotlib inline\n",
13
+ "from sklearn.model_selection import train_test_split, KFold, cross_val_score\n",
14
+ "from sklearn.preprocessing import LabelEncoder, OneHotEncoder, StandardScaler\n",
15
+ "from sklearn.metrics import accuracy_score, precision_score, recall_score, f1_score, confusion_matrix\n",
16
+ "from sklearn.linear_model import LogisticRegression\n",
17
+ "from sklearn.tree import DecisionTreeClassifier\n",
18
+ "from sklearn.ensemble import RandomForestClassifier\n",
19
+ "from sklearn.svm import SVC\n",
20
+ "import seaborn as sns\n",
21
+ "\n",
22
+ "# Download latest version\n",
23
+ "path = kagglehub.dataset_download(\"ANON_OWNER/q1-exam-data\")\n",
24
+ "\n",
25
+ "print(\"Path to dataset files:\", path)\n"
26
+ ],
27
+ "execution_count": null,
28
+ "outputs": []
29
+ },
30
+ {
31
+ "cell_type": "code",
32
+ "metadata": {},
33
+ "source": [
34
+ "# Task 1: Write your code here:\n",
35
+ "\n",
36
+ "path = os.path.join(path, \"Q1_data.csv\")\n",
37
+ "df = pd.read_csv(path)"
38
+ ],
39
+ "execution_count": null,
40
+ "outputs": []
41
+ },
42
+ {
43
+ "cell_type": "code",
44
+ "metadata": {},
45
+ "source": [
46
+ "# Task 2: Write your code here:\n",
47
+ "df.head()"
48
+ ],
49
+ "execution_count": null,
50
+ "outputs": []
51
+ },
52
+ {
53
+ "cell_type": "code",
54
+ "metadata": {},
55
+ "source": [
56
+ "# Task 3: Write your code here:\n",
57
+ "df.info()"
58
+ ],
59
+ "execution_count": null,
60
+ "outputs": []
61
+ },
62
+ {
63
+ "cell_type": "code",
64
+ "metadata": {},
65
+ "source": [
66
+ "# Task 4: Write your code here:\n",
67
+ "df.describe()"
68
+ ],
69
+ "execution_count": null,
70
+ "outputs": []
71
+ },
72
+ {
73
+ "cell_type": "code",
74
+ "metadata": {},
75
+ "source": [
76
+ "# Task 5: Write your code here:\n",
77
+ "def check_target_distribution(df, target_column):\n",
78
+ " df[target_column].hist(bins=30, edgecolor='black')\n",
79
+ "\n",
80
+ " plt.title(f\"Target Distribution ({target_column})\")\n",
81
+ " plt.xlabel(target_column)\n",
82
+ " plt.ylabel(\"Frequency\")\n",
83
+ " plt.grid(False)\n",
84
+ "\n",
85
+ " plt.show()\n",
86
+ "\n",
87
+ "check_target_distribution(df, \"Delivery_Time\")"
88
+ ],
89
+ "execution_count": null,
90
+ "outputs": []
91
+ },
92
+ {
93
+ "cell_type": "code",
94
+ "metadata": {},
95
+ "source": [
96
+ "# Task 1: Write your code here:\n",
97
+ "df = df.drop(columns=\"Order_ID\", axis=1)"
98
+ ],
99
+ "execution_count": null,
100
+ "outputs": []
101
+ },
102
+ {
103
+ "cell_type": "code",
104
+ "metadata": {},
105
+ "source": [
106
+ "# Task 2: Write your code here:\n",
107
+ "def check_missing_values(df):\n",
108
+ " missing_values = df.isnull().sum()\n",
109
+ " print(\"Missing Values per Column:\")\n",
110
+ " print(missing_values[missing_values > 0])\n",
111
+ " if missing_values.any():\n",
112
+ " print(\"\\nHandle Missing Values as needed.\")\n",
113
+ " else:\n",
114
+ " print(\"\\nNo Missing Values Found.\")\n",
115
+ "\n",
116
+ "check_missing_values(df)"
117
+ ],
118
+ "execution_count": null,
119
+ "outputs": []
120
+ },
121
+ {
122
+ "cell_type": "code",
123
+ "metadata": {},
124
+ "source": [
125
+ "# Task 3: Write your code here:\n",
126
+ "def check_duplicates(df):\n",
127
+ " duplicates = df.duplicated().sum()\n",
128
+ " print(f\"Number of Duplicate Samples: {duplicates}\")\n",
129
+ " if duplicates > 0:\n",
130
+ " print(\"Dropping Duplicates...\")\n",
131
+ " df.drop_duplicates(inplace=True)\n",
132
+ " print(\"Duplicates Dropped.\")\n",
133
+ " else:\n",
134
+ " print(\"No Duplicate Samples Found.\")"
135
+ ],
136
+ "execution_count": null,
137
+ "outputs": []
138
+ },
139
+ {
140
+ "cell_type": "code",
141
+ "metadata": {},
142
+ "source": [
143
+ "# Task 4: Write your code here:\n",
144
+ "onehot_encoder = OneHotEncoder(handle_unknown='ignore', sparse_output=False)"
145
+ ],
146
+ "execution_count": null,
147
+ "outputs": []
148
+ },
149
+ {
150
+ "cell_type": "code",
151
+ "metadata": {},
152
+ "source": [
153
+ "# Task 5: Write your code here:\n",
154
+ "\n",
155
+ "data_cols = df.select_dtypes(include=[\"int64\", \"float64\"]).columns.drop(\"Delivery_Time\") # DON'T SCALE THE TARGET\n",
156
+ "\n",
157
+ "scaler = StandardScaler()\n",
158
+ "df[data_cols] = scaler.fit_transform(df[data_cols])"
159
+ ],
160
+ "execution_count": null,
161
+ "outputs": []
162
+ },
163
+ {
164
+ "cell_type": "code",
165
+ "metadata": {},
166
+ "source": [
167
+ "# Task 6: Write your code here:\n",
168
+ "def check_target_imbalance(df, data_cols):\n",
169
+ " print(\"Target Distribution:\")\n",
170
+ " print(df[data_cols].value_counts(normalize=True))\n",
171
+ " sns.countplot(x=df[data_cols])\n",
172
+ " plt.title(\"Target Distribution\")\n",
173
+ " plt.show()\n",
174
+ "\n",
175
+ "check_target_imbalance(df, \"Delivery_Time\")"
176
+ ],
177
+ "execution_count": null,
178
+ "outputs": []
179
+ },
180
+ {
181
+ "cell_type": "code",
182
+ "metadata": {},
183
+ "source": [
184
+ "# Task 1: Write your code here:\n",
185
+ "\n",
186
+ "X = df.drop(\"Delivery_Time\", axis=1)\n",
187
+ "y = df['Delivery_Time'].astype(float)"
188
+ ],
189
+ "execution_count": null,
190
+ "outputs": []
191
+ },
192
+ {
193
+ "cell_type": "code",
194
+ "metadata": {},
195
+ "source": [
196
+ "# Task 2,3,4,5: Write your code here:\n",
197
+ "\n",
198
+ "from sklearn.ensemble import RandomForestRegressor\n",
199
+ "from sklearn.model_selection import KFold, StratifiedKFold, cross_val_score\n",
200
+ "\n",
201
+ "\n",
202
+ "n_splits = 5 # K=5 Folds\n",
203
+ "\n",
204
+ "\n",
205
+ "scores_accuracy = []\n",
206
+ "scores_f1 = []\n",
207
+ "\n",
208
+ "# Stratified 5-Fold Cross-Validation initiation\n",
209
+ "skf = StratifiedKFold(n_splits=5, shuffle=False)\n",
210
+ "for train_index, test_index in skf.split(X, y):\n",
211
+ " # Split data into training and testing sets using the indices defined by the KFold\n",
212
+ " X_Train, X_Test = X.loc[train_index, :], X.loc[test_index, :]\n",
213
+ " y_Train, y_Test = y.iloc[train_index], y.iloc[test_index]\n",
214
+ "\n",
215
+ " # Train the model on the training data\n",
216
+ " model = RandomForestClassifier(n_estimators=100, random_state=42)\n",
217
+ " # Predict on the test set\n",
218
+ " y_pred = model.predict(X_Test)\n",
219
+ "\n",
220
+ " # Metric from the sklearn.metrics package\n",
221
+ " scores_accuracy.append(accuracy_score(y_Test, y_pred))\n",
222
+ "\n"
223
+ ],
224
+ "execution_count": null,
225
+ "outputs": []
226
+ },
227
+ {
228
+ "cell_type": "code",
229
+ "metadata": {},
230
+ "source": [
231
+ "# Task 1: Write your code here:\n",
232
+ "import matplotlib.pyplot as plt\n",
233
+ "\n",
234
+ "# Retrieve our model's coefficients and sort by absolute importance\n",
235
+ "l_importance = list(zip(X.columns, model.coef_[0]))\n",
236
+ "mportance = sorted(logistic_importance, key=lambda x: abs(x[1]), reverse=True)\n",
237
+ "\n",
238
+ "importance = importance[:10] # Choosing the highest 10 features\n",
239
+ "\n",
240
+ "\n",
241
+ "# Extract sorted features and their coefficients\n",
242
+ "features, coefficients = zip(*importance)\n",
243
+ "\n"
244
+ ],
245
+ "execution_count": null,
246
+ "outputs": []
247
+ },
248
+ {
249
+ "cell_type": "code",
250
+ "metadata": {},
251
+ "source": [
252
+ "# Task 2: Write your code here:\n",
253
+ "# Plot feature importances\n",
254
+ "plt.figure(figsize=(10, 6))\n",
255
+ "plt.barh(features, np.abs(coefficients), color='darkblue')\n",
256
+ "plt.xlabel('delivery time ')\n",
257
+ "plt.ylabel('Features')\n",
258
+ "plt.title(' Regression Feature Importance')\n",
259
+ "plt.gca().invert_yaxis() # Invert y-axis to show the most important features at the top\n",
260
+ "plt.show()"
261
+ ],
262
+ "execution_count": null,
263
+ "outputs": []
264
+ },
265
+ {
266
+ "cell_type": "code",
267
+ "metadata": {},
268
+ "source": [
269
+ "# Task Bonus: Write your code here:"
270
+ ],
271
+ "execution_count": null,
272
+ "outputs": []
273
+ }
274
+ ],
275
+ "metadata": {
276
+ "kernelspec": {
277
+ "display_name": "Python 3",
278
+ "name": "python3"
279
+ },
280
+ "language_info": {
281
+ "name": "python"
282
+ }
283
+ },
284
+ "nbformat": 4,
285
+ "nbformat_minor": 0
286
+ }
submissions_extracted/1002/Q2.ipynb ADDED
@@ -0,0 +1,406 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "metadata": {},
6
+ "source": [
7
+ "import kagglehub\n",
8
+ "import torch\n",
9
+ "import torch.nn as nn\n",
10
+ "from torchvision.datasets import MNIST\n",
11
+ "from torch.utils.data import DataLoader\n",
12
+ "from torch.optim import Adam\n",
13
+ "from torchvision.transforms.functional import to_tensor\n",
14
+ "import torch.nn.functional as F\n",
15
+ "import matplotlib.pyplot as plt\n",
16
+ "# Download latest version\n",
17
+ "path = kagglehub.dataset_download(\"ANON_OWNER/q2-exam-data\")\n",
18
+ "\n",
19
+ "print(\"Path to dataset files:\", path)"
20
+ ],
21
+ "execution_count": null,
22
+ "outputs": []
23
+ },
24
+ {
25
+ "cell_type": "code",
26
+ "metadata": {},
27
+ "source": [
28
+ "import os\n",
29
+ "import pandas as pd\n",
30
+ "import numpy as np\n",
31
+ "from PIL import Image\n",
32
+ "from sklearn.model_selection import train_test_split\n",
33
+ "\n",
34
+ "\n",
35
+ "\n",
36
+ "# Load Labels\n",
37
+ "labels_df = pd.read_csv(os.path.join(path, \"labels.csv\"))\n",
38
+ "img_dir = os.path.join(path, \"images\")\n",
39
+ "\n",
40
+ "images = []\n",
41
+ "ages = []\n",
42
+ "\n",
43
+ "# Load Images and Resize\n",
44
+ "print(\"Loading images...\")\n",
45
+ "for index, row in labels_df.iterrows():\n",
46
+ " img_name = row.iloc[0]\n",
47
+ " age = row.iloc[1]\n",
48
+ " img_path = os.path.join(img_dir, img_name)\n",
49
+ "\n",
50
+ " if os.path.exists(img_path):\n",
51
+ " img = Image.open(img_path).convert('RGB')\n",
52
+ " img_array = np.array(img) / 255.0 # Normalize pixel values to [0, 1]\n",
53
+ " images.append(img_array)\n",
54
+ " ages.append(age)\n",
55
+ "\n",
56
+ "X = np.array(images)\n",
57
+ "y = np.array(ages)\n",
58
+ "\n",
59
+ "# Transpose image dimensions to match PyTorch format (N, C, H, W)\n",
60
+ "X = np.transpose(X, (0, 3, 1, 2))\n",
61
+ "\n",
62
+ "# Split Data\n",
63
+ "X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)\n",
64
+ "\n",
65
+ "print(f\"X_train shape: {X_train.shape}\")\n",
66
+ "print(f\"X_test shape: {X_test.shape}\")\n",
67
+ "print(f\"y_train shape: {y_train.shape}\")\n",
68
+ "print(f\"y_test shape: {y_test.shape}\")"
69
+ ],
70
+ "execution_count": null,
71
+ "outputs": []
72
+ },
73
+ {
74
+ "cell_type": "code",
75
+ "metadata": {},
76
+ "source": [
77
+ "# 1. Convert Numpy arrays to PyTorch Tensors\n",
78
+ "\n",
79
+ "X_train = torch.tensor(X_train, dtype=torch.float32)\n",
80
+ "X_test = torch.tensor(X_test, dtype=torch.float32)\n",
81
+ "y_train = torch.tensor(y_train, dtype=torch.long)\n",
82
+ "y_test = torch.tensor(y_test, dtype=torch.long)\n",
83
+ "\n"
84
+ ],
85
+ "execution_count": null,
86
+ "outputs": []
87
+ },
88
+ {
89
+ "cell_type": "code",
90
+ "metadata": {},
91
+ "source": [
92
+ "# 2. Create TensorDataset objects\n",
93
+ "in_dataset = MNIST(\n",
94
+ " root='./datasets', # Dataset storage path\n",
95
+ " train=True, # Use training data\n",
96
+ " transform=to_tensor, # Convert images to tensors\n",
97
+ " download=True # Download if not available\n",
98
+ ")\n",
99
+ "\n",
100
+ "# Testing dataset\n",
101
+ "test_dataset = MNIST(\n",
102
+ " root='./datasets', # Dataset storage path\n",
103
+ " train=False, # Use test data\n",
104
+ " transform=to_tensor, # Convert images to tensors\n",
105
+ " download=True # Download if not available\n",
106
+ ")\n"
107
+ ],
108
+ "execution_count": null,
109
+ "outputs": []
110
+ },
111
+ {
112
+ "cell_type": "code",
113
+ "metadata": {},
114
+ "source": [
115
+ "# 3. Create DataLoaders\n",
116
+ "\n",
117
+ "from torch.utils.data import DataLoader\n",
118
+ "\n",
119
+ "# DataLoader for training data\n",
120
+ "train_loader = DataLoader(\n",
121
+ " in_dataset,\n",
122
+ " batch_size=32,\n",
123
+ " shuffle=True,\n",
124
+ " num_workers=2\n",
125
+ ")\n",
126
+ "# DataLoader for test/validation data\n",
127
+ "test_loader = DataLoader(\n",
128
+ " test_dataset,\n",
129
+ " batch_size=32,\n",
130
+ " shuffle=False,\n",
131
+ " num_workers=2\n",
132
+ ")\n",
133
+ "# Get the first batch from the training DataLoader\n",
134
+ "X_batch, y_batch = next(iter(train_loader))\n",
135
+ "print(f\"Training batch input shape: {X_batch.shape}\")\n",
136
+ "print(f\"Training batch labels shape: {y_batch.shape}\")"
137
+ ],
138
+ "execution_count": null,
139
+ "outputs": []
140
+ },
141
+ {
142
+ "cell_type": "code",
143
+ "metadata": {},
144
+ "source": [
145
+ "# 4. Print shape of one batch\n",
146
+ "X_batch, y_batch = next(iter(train_loader))\n",
147
+ "print(f\"Training batch input shape: {X_batch.shape}\")\n",
148
+ "print(f\"Training batch labels shape: {y_batch.shape}\")\n"
149
+ ],
150
+ "execution_count": null,
151
+ "outputs": []
152
+ },
153
+ {
154
+ "cell_type": "code",
155
+ "metadata": {},
156
+ "source": [
157
+ "# 5. Display sample images\n",
158
+ "\n",
159
+ "images, labels = next(iter(train_loader))\n",
160
+ "\n",
161
+ "# Display the first 6 images in the batch\n",
162
+ "plt.figure(figsize=(8, 4))\n",
163
+ "\n",
164
+ "for i in range(6):\n",
165
+ " plt.subplot(2, 3, i + 1)\n",
166
+ " plt.imshow(images[i].squeeze(), cmap='gray')\n",
167
+ " plt.title(f\"Label: {labels[i].item()}\")\n",
168
+ " plt.axis('off')\n",
169
+ "\n",
170
+ "plt.tight_layout()\n",
171
+ "plt.show()"
172
+ ],
173
+ "execution_count": null,
174
+ "outputs": []
175
+ },
176
+ {
177
+ "cell_type": "code",
178
+ "metadata": {},
179
+ "source": [
180
+ "# Task 1: Write your model class here:\n",
181
+ "def __init__(self, input_dim, hidden_dim, output_dim):\n",
182
+ " super(NN4Layer, self).__init__()\n",
183
+ "\n",
184
+ " # TODO: What are the dimensions of the first layer? (hint: features? hidden neurons?)\n",
185
+ " self.layer1 = nn.Linear(input_dim, hidden_dim)\n",
186
+ "\n",
187
+ " # TODO: What are the dimensions from previous and next layer?\n",
188
+ " self.layer2 = nn.Linear(hidden_dim, hidden_dim)\n",
189
+ "\n",
190
+ " # TODO: What are the dimensions from previous and next layer?\n",
191
+ " self.layer3 = nn.Linear(hidden_dim, hidden_dim)\n",
192
+ "\n",
193
+ "\n",
194
+ " # TODO: What are the dimensions of previous and output layer? (hint: hidden neurons? num of classes?)\n",
195
+ " self.layer4 = nn.Linear(hidden_dim, output_dim)\n",
196
+ "\n",
197
+ " # activation function for non-linearity\n",
198
+ " self.relu = nn.ReLU()\n",
199
+ "def forward(self, x):\n",
200
+ " # Layer 1: TODO\n",
201
+ " z1 = self.layer1(x)\n",
202
+ " a1 = self.relu(z1)\n",
203
+ "\n",
204
+ " # Layer 2 TODO\n",
205
+ " z2 = self.layer2(a1)\n",
206
+ " a2 = self.relu(z2)\n",
207
+ "\n",
208
+ " # Layer 3 TODO\n",
209
+ " z3 = self.layer3(a2)\n",
210
+ " a3 = self.relu(z3)\n",
211
+ "\n",
212
+ "\n",
213
+ "\n",
214
+ " # Output layer TODO\n",
215
+ " z4 = self.layer5(a3)\n",
216
+ "\n",
217
+ " # TODO: are we missing output activation function? (hint: Loss Function)\n",
218
+ "\n",
219
+ " return z4"
220
+ ],
221
+ "execution_count": null,
222
+ "outputs": []
223
+ },
224
+ {
225
+ "cell_type": "code",
226
+ "metadata": {},
227
+ "source": [
228
+ "# Task 2: Write your training loop here:\n",
229
+ "def train_one_epoch(model, optimizer, criterion, train_loader, device):\n",
230
+ " # Set the model to training mode\n",
231
+ " model.train()\n",
232
+ "\n",
233
+ " running_loss = 0.0\n",
234
+ "\n",
235
+ " for X_batch, y_batch in train_loader:\n",
236
+ " # Move batch to the selected device\n",
237
+ " X_batch = X_batch.view(X_batch.size(0), -1).to(device)\n",
238
+ " y_batch = y_batch.to(device)\n",
239
+ "\n",
240
+ " # Forward pass\n",
241
+ " # TODO: make predictions\n",
242
+ " outputs = model(X_batch) # shape: (batch_size, 10)\n",
243
+ " # TODO: compute loss\n",
244
+ " loss = criterion(outputs, y_batch)\n",
245
+ "\n",
246
+ " # Backward pass & optimization\n",
247
+ " optimizer.zero_grad() # Clear previous gradients\n",
248
+ " loss.backward() # Compute gradients\n",
249
+ " optimizer.step() # Update model parameters\n",
250
+ "\n",
251
+ " running_loss += loss.item()\n",
252
+ "\n",
253
+ " # Average loss over all batches\n",
254
+ " avg_loss = running_loss / len(train_loader)\n",
255
+ "\n",
256
+ " return avg_loss"
257
+ ],
258
+ "execution_count": null,
259
+ "outputs": []
260
+ },
261
+ {
262
+ "cell_type": "code",
263
+ "metadata": {},
264
+ "source": [
265
+ "# Task 3: Write your validation loop here:\n",
266
+ "def validate(model, criterion, test_loader, device):\n",
267
+ " # Set the model to evaluation mode\n",
268
+ " model.eval()\n",
269
+ "\n",
270
+ " running_loss = 0.0\n",
271
+ " correct = 0\n",
272
+ " total = 0\n",
273
+ "\n",
274
+ " with torch.no_grad():\n",
275
+ " for X_batch, y_batch in test_loader:\n",
276
+ " # Move data to device\n",
277
+ " X_batch = X_batch.view(X_batch.size(0), -1).to(device)\n",
278
+ " y_batch = y_batch.to(device)\n",
279
+ "\n",
280
+ " # Forward pass\n",
281
+ " # TODO: make predictions\n",
282
+ " outputs = model(X_batch) # shape: (batch_size, 10)\n",
283
+ " # TODO: compute loss\n",
284
+ " loss = criterion(outputs, y_batch)\n",
285
+ " running_loss += loss.item()\n",
286
+ "\n",
287
+ " # TODO: Apply Softmax to get probabilities\n",
288
+ " probabilities = F.softmax(outputs, dim=1)\n",
289
+ "\n",
290
+ " # TODO: Multiclass predictions\n",
291
+ " predicted = torch.argmax(probabilities, dim=1)\n",
292
+ "\n",
293
+ " # Accuracy calculation\n",
294
+ " correct += (predicted == y_batch).sum().item()\n",
295
+ " total += y_batch.size(0)\n",
296
+ "\n",
297
+ " avg_loss = running_loss / len(test_loader)\n",
298
+ " # TODO: how do we calculate accuracy?\n",
299
+ " accuracy = correct / total\n",
300
+ "\n",
301
+ " return avg_loss, accuracy"
302
+ ],
303
+ "execution_count": null,
304
+ "outputs": []
305
+ },
306
+ {
307
+ "cell_type": "code",
308
+ "metadata": {},
309
+ "source": [
310
+ "# Task 4: Define device, model, loss, optimizer:\n",
311
+ "device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')\n",
312
+ "print(f\"Using device: {device}\")\n",
313
+ "\n",
314
+ "num_epochs = 50\n",
315
+ "learning_rate = 0.001\n",
316
+ "\n"
317
+ ],
318
+ "execution_count": null,
319
+ "outputs": []
320
+ },
321
+ {
322
+ "cell_type": "code",
323
+ "metadata": {},
324
+ "source": [
325
+ "# Task 5: Start training for 20 epochs:\n",
326
+ "num_epochs = 20\n",
327
+ "\n",
328
+ "learning_rate = 0.001\n",
329
+ "\n",
330
+ "optimizer = AdamW(model.parameters(), learning_rate)\n"
331
+ ],
332
+ "execution_count": null,
333
+ "outputs": []
334
+ },
335
+ {
336
+ "cell_type": "code",
337
+ "metadata": {},
338
+ "source": [
339
+ "def validate(model, criterion, test_loader, device):\n",
340
+ " # Set the model to evaluation mode\n",
341
+ " model.eval()\n",
342
+ "\n",
343
+ " running_loss = 0.0\n",
344
+ " correct = 0\n",
345
+ " total = 0\n",
346
+ "\n",
347
+ " with torch.no_grad(): # Disable gradient computation\n",
348
+ " for X_batch, y_batch in test_loader:\n",
349
+ " # Move batch to the selected device\n",
350
+ " X_batch = X_batch.to(device)\n",
351
+ " y_batch = y_batch.view(-1, 1).to(device)\n",
352
+ "\n",
353
+ " # Forward pass\n",
354
+ " outputs = model(X_batch)\n",
355
+ " loss = criterion(outputs, y_batch)\n",
356
+ " running_loss += loss.item()\n",
357
+ "\n",
358
+ " # Binary predictions\n",
359
+ " predicted = (outputs > 0.5).float()\n",
360
+ "\n",
361
+ " # Accuracy calculation\n",
362
+ " correct += (predicted == y_batch).sum().item()\n",
363
+ " total += y_batch.size(0)\n",
364
+ "\n",
365
+ " avg_loss = running_loss / len(test_loader)\n",
366
+ " accuracy = correct / total\n",
367
+ "\n",
368
+ " return avg_loss, accuracy\n"
369
+ ],
370
+ "execution_count": null,
371
+ "outputs": []
372
+ },
373
+ {
374
+ "cell_type": "code",
375
+ "metadata": {},
376
+ "source": [
377
+ "# Task 2 (Bonus): Write your code here:\n",
378
+ "# Plotting results\n",
379
+ "plt.figure(figsize=(7, 5))\n",
380
+ "\n",
381
+ "plt.plot(train_losses, label='Train Loss')\n",
382
+ "plt.plot(val_losses, label='Validation Loss')\n",
383
+ "plt.title('Loss over Epochs')\n",
384
+ "plt.xlabel('Epoch')\n",
385
+ "plt.ylabel('Loss')\n",
386
+ "plt.legend()\n",
387
+ "\n",
388
+ "plt.tight_layout()\n",
389
+ "plt.show()"
390
+ ],
391
+ "execution_count": null,
392
+ "outputs": []
393
+ }
394
+ ],
395
+ "metadata": {
396
+ "kernelspec": {
397
+ "display_name": "Python 3",
398
+ "name": "python3"
399
+ },
400
+ "language_info": {
401
+ "name": "python"
402
+ }
403
+ },
404
+ "nbformat": 4,
405
+ "nbformat_minor": 0
406
+ }
submissions_extracted/1002/Q3.ipynb ADDED
@@ -0,0 +1,275 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "metadata": {},
6
+ "source": [
7
+ "import kagglehub\n",
8
+ "import os\n",
9
+ "import pandas as pd\n",
10
+ "import numpy as np\n",
11
+ "import matplotlib.pyplot as plt\n",
12
+ "%matplotlib inline\n",
13
+ "from sklearn.model_selection import train_test_split, KFold, cross_val_score\n",
14
+ "from sklearn.preprocessing import LabelEncoder, OneHotEncoder, StandardScaler\n",
15
+ "from sklearn.metrics import accuracy_score, precision_score, recall_score, f1_score, confusion_matrix\n",
16
+ "from sklearn.linear_model import LogisticRegression\n",
17
+ "from sklearn.tree import DecisionTreeClassifier\n",
18
+ "from sklearn.ensemble import RandomForestClassifier\n",
19
+ "from sklearn.svm import SVC\n",
20
+ "import seaborn as sns\n",
21
+ "\n",
22
+ "\n",
23
+ "# Download latest version\n",
24
+ "\n",
25
+ "path = kagglehub.dataset_download(\"ANON_OWNER/q3-exam-data\")\n",
26
+ "\n",
27
+ "\n",
28
+ "\n",
29
+ "print(\"Path to dataset files:\", path)"
30
+ ],
31
+ "execution_count": null,
32
+ "outputs": []
33
+ },
34
+ {
35
+ "cell_type": "code",
36
+ "metadata": {},
37
+ "source": [
38
+ "# Task 1: Write your code here:\n",
39
+ "path = os.path.join(path, \"Q3_data.csv\")\n",
40
+ "df = pd.read_csv(path)"
41
+ ],
42
+ "execution_count": null,
43
+ "outputs": []
44
+ },
45
+ {
46
+ "cell_type": "code",
47
+ "metadata": {},
48
+ "source": [
49
+ "# Task 2: Write your code here:\n",
50
+ "df.head()"
51
+ ],
52
+ "execution_count": null,
53
+ "outputs": []
54
+ },
55
+ {
56
+ "cell_type": "code",
57
+ "metadata": {},
58
+ "source": [
59
+ "# Task 3: Write your code here:\n",
60
+ "df.info()"
61
+ ],
62
+ "execution_count": null,
63
+ "outputs": []
64
+ },
65
+ {
66
+ "cell_type": "code",
67
+ "metadata": {},
68
+ "source": [
69
+ "# Task 4: Write your code here:\n",
70
+ "df.describe()"
71
+ ],
72
+ "execution_count": null,
73
+ "outputs": []
74
+ },
75
+ {
76
+ "cell_type": "code",
77
+ "metadata": {},
78
+ "source": [
79
+ "# Task 1: Write your code here:\n",
80
+ "\n",
81
+ "def check_missing_values(df):\n",
82
+ " missing_values = df.isnull().sum()\n",
83
+ " print(\"Missing Values per Column:\")\n",
84
+ " print(missing_values[missing_values > 0])\n",
85
+ " if missing_values.any():\n",
86
+ " print(\"\\nHandle Missing Values as needed.\")\n",
87
+ " else:\n",
88
+ " print(\"\\nNo Missing Values Found.\")\n",
89
+ "\n",
90
+ "check_missing_values(df)"
91
+ ],
92
+ "execution_count": null,
93
+ "outputs": []
94
+ },
95
+ {
96
+ "cell_type": "code",
97
+ "metadata": {},
98
+ "source": [
99
+ "# Task 2: Write your code here:\n",
100
+ "def check_duplicates(df):\n",
101
+ " duplicates = df.duplicated().sum()\n",
102
+ " print(f\"Number of Duplicate Samples: {duplicates}\")\n",
103
+ " if duplicates > 0:\n",
104
+ " print(\"Dropping Duplicates...\")\n",
105
+ " df.drop_duplicates(inplace=True)\n",
106
+ " print(\"Duplicates Dropped.\")\n",
107
+ " else:\n",
108
+ " print(\"No Duplicate Samples Found.\")"
109
+ ],
110
+ "execution_count": null,
111
+ "outputs": []
112
+ },
113
+ {
114
+ "cell_type": "code",
115
+ "metadata": {},
116
+ "source": [
117
+ "# Task 3: Write your code here:\n",
118
+ "categorical_cols = df.select_dtypes(include=[\"object\"]).columns\n",
119
+ "\n",
120
+ "print(\"Categorical Columns:\", list(categorical_cols))"
121
+ ],
122
+ "execution_count": null,
123
+ "outputs": []
124
+ },
125
+ {
126
+ "cell_type": "code",
127
+ "metadata": {},
128
+ "source": [
129
+ "# Task 4: Write your code here:\n",
130
+ "data = df.select_dtypes(include=[\"int64\", \"float64\"]).columns.drop(\"Target\")\n",
131
+ "scaler = StandardScaler()\n",
132
+ "df = scaler.fit_transform(df[data])"
133
+ ],
134
+ "execution_count": null,
135
+ "outputs": []
136
+ },
137
+ {
138
+ "cell_type": "code",
139
+ "metadata": {},
140
+ "source": [
141
+ "# Task 5: Write your code here:\n",
142
+ "def check_target_imbalance(df, target_col):\n",
143
+ " print(\"Target Distribution:\")\n",
144
+ " print(target_col.value_counts(normalize=True))\n",
145
+ " sns.countplot(x=df[data])\n",
146
+ " plt.title(\"Target Distribution\")\n",
147
+ " plt.show()\n",
148
+ "\n",
149
+ "check_target_imbalance(df,target_col)"
150
+ ],
151
+ "execution_count": null,
152
+ "outputs": []
153
+ },
154
+ {
155
+ "cell_type": "code",
156
+ "metadata": {},
157
+ "source": [
158
+ "# Task 1: Write your code here:\n",
159
+ "X = df.drop(\"Target\", axis=1).astype(float)\n",
160
+ "y = df['Target'].astype(float)"
161
+ ],
162
+ "execution_count": null,
163
+ "outputs": []
164
+ },
165
+ {
166
+ "cell_type": "code",
167
+ "metadata": {},
168
+ "source": [
169
+ "# Task 2,3,4,5: Write your code here:\n",
170
+ "from sklearn.model_selection import StratifiedKFold\n",
171
+ "from xgboost import XGBClassifier\n",
172
+ "from sklearn.metrics import accuracy_score, precision_score, recall_score, f1_score\n",
173
+ "n_splits = 5 # K=5 Folds\n",
174
+ "\n",
175
+ "# Stratified 5-Fold Cross-Validation, shuffled\n",
176
+ "skf = StratifiedKFold(n_splits=n_splits, shuffle=True, random_state=42)\n",
177
+ "or fold_idx, (train_index, test_index) in enumerate(skf.split(X, y)):\n",
178
+ " print(f\"\\nFold {fold_idx + 1}/{n_splits}\")\n",
179
+ "\n",
180
+ " X_train, X_test = X.iloc[train_index], X.iloc[test_index]\n",
181
+ " y_train, y_test = y.iloc[train_index], y.iloc[test_index]\n",
182
+ "\n",
183
+ " # Train\n",
184
+ " theta, losses = gradient_descent(X_train, y_train, learning_rate=0.5, n_iters=500)\n",
185
+ "\n",
186
+ " # Validate\n",
187
+ " y_pred_proba = sigmoid(np.dot(X_test, theta))\n",
188
+ " y_pred = (y_pred_proba >= 0.5).astype(int)\n",
189
+ "\n",
190
+ " # Calculate evaluation metrics\n",
191
+ " accuracy = accuracy_score(y_test, y_pred)\n",
192
+ " precision = precision_score(y_test, y_pred, zero_division=0)\n",
193
+ " recall = recall_score(y_test, y_pred, zero_division=0)\n",
194
+ " f1 = f1_score(y_test, y_pred, zero_division=0)\n",
195
+ "\n",
196
+ " # Store results\n",
197
+ " lr_losses.append(losses)\n",
198
+ " lr_accuracy.append(accuracy)\n",
199
+ " lr_precision.append(precision)\n",
200
+ " lr_recall.append(recall)\n",
201
+ " lr_f1.append(f1)\n",
202
+ "\n",
203
+ "\n",
204
+ "\n",
205
+ "model = XGBClassifier(\n",
206
+ " verbosity=0,\n",
207
+ " n_estimators=300, # Number of boosting rounds\n",
208
+ " max_depth=5,\n",
209
+ " learning_rate=0.05\n",
210
+ "\n"
211
+ ],
212
+ "execution_count": null,
213
+ "outputs": []
214
+ },
215
+ {
216
+ "cell_type": "code",
217
+ "metadata": {},
218
+ "source": [
219
+ "# Task 1: Write your code here:\n",
220
+ "# Task 1: Write your code here:\n",
221
+ "import matplotlib.pyplot as plt\n",
222
+ "\n",
223
+ "# Retrieve our model's coefficients and sort by absolute importance\n",
224
+ "l_importance = list(zip(X.columns, model.coef_[0]))\n",
225
+ "mportance = sorted(logistic_importance, key=lambda x: abs(x[1]), reverse=True)\n",
226
+ "\n",
227
+ "importance = importance[:10] # Choosing the highest 10 features\n",
228
+ "\n",
229
+ "\n",
230
+ "# Extract sorted features and their coefficients\n",
231
+ "features, coefficients = zip(*importance)\n",
232
+ "\n"
233
+ ],
234
+ "execution_count": null,
235
+ "outputs": []
236
+ },
237
+ {
238
+ "cell_type": "code",
239
+ "metadata": {},
240
+ "source": [
241
+ "# Task 2: Write your code here:\n",
242
+ "# Plot feature importances\n",
243
+ "plt.figure(figsize=(10, 6))\n",
244
+ "plt.barh(features, np.abs(coefficients), color='darkblue')\n",
245
+ "plt.xlabel('Golden Feature ')\n",
246
+ "plt.ylabel('Features')\n",
247
+ "plt.title(' Feature Importance')\n",
248
+ "plt.gca().invert_yaxis() # Invert y-axis to show the most important features at the top\n",
249
+ "plt.show()"
250
+ ],
251
+ "execution_count": null,
252
+ "outputs": []
253
+ },
254
+ {
255
+ "cell_type": "code",
256
+ "metadata": {},
257
+ "source": [
258
+ "# Task Bonus: Write your code here:\n"
259
+ ],
260
+ "execution_count": null,
261
+ "outputs": []
262
+ }
263
+ ],
264
+ "metadata": {
265
+ "kernelspec": {
266
+ "display_name": "Python 3",
267
+ "name": "python3"
268
+ },
269
+ "language_info": {
270
+ "name": "python"
271
+ }
272
+ },
273
+ "nbformat": 4,
274
+ "nbformat_minor": 0
275
+ }
submissions_extracted/1003/Q1.ipynb ADDED
@@ -0,0 +1,259 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "metadata": {},
6
+ "source": [
7
+ "import kagglehub\n",
8
+ "\n",
9
+ "# Download latest version\n",
10
+ "path = kagglehub.dataset_download(\"ANON_OWNER/q1-exam-data\")\n",
11
+ "\n",
12
+ "print(\"Path to dataset files:\", path)"
13
+ ],
14
+ "execution_count": null,
15
+ "outputs": []
16
+ },
17
+ {
18
+ "cell_type": "code",
19
+ "metadata": {},
20
+ "source": [
21
+ "# Task 1: Write your code here:\n",
22
+ "import numpy as np\n",
23
+ "import pandas as pd\n",
24
+ "import os\n",
25
+ "\n",
26
+ "\n",
27
+ "Q1_path = os.path.join(path, 'Q1_data.csv')\n",
28
+ "df_delivery = pd.read_csv(Q1_path)\n",
29
+ "\n",
30
+ "print(f\"Shape: {df_delivery.shape}\")\n"
31
+ ],
32
+ "execution_count": null,
33
+ "outputs": []
34
+ },
35
+ {
36
+ "cell_type": "code",
37
+ "metadata": {},
38
+ "source": [
39
+ "# Task 2: Write your code here:\n",
40
+ "df_delivery.head()"
41
+ ],
42
+ "execution_count": null,
43
+ "outputs": []
44
+ },
45
+ {
46
+ "cell_type": "code",
47
+ "metadata": {},
48
+ "source": [
49
+ "# Task 3: Write your code here:\n",
50
+ "df_delivery.info()"
51
+ ],
52
+ "execution_count": null,
53
+ "outputs": []
54
+ },
55
+ {
56
+ "cell_type": "code",
57
+ "metadata": {},
58
+ "source": [
59
+ "# Task 4: Write your code here:\n",
60
+ "df_delivery.describe()"
61
+ ],
62
+ "execution_count": null,
63
+ "outputs": []
64
+ },
65
+ {
66
+ "cell_type": "code",
67
+ "metadata": {},
68
+ "source": [
69
+ "# Task 5: Write your code here:\n",
70
+ "import matplotlib.pyplot as plt\n",
71
+ "plt.figure(figsize=(10, 5))\n",
72
+ "plt.hist(df_delivery['Delivery_Time'].dropna(), bins=50, edgecolor='black')\n",
73
+ "plt.title('Delivery Time Distribution')\n",
74
+ "plt.xlabel('Delivery Time')\n",
75
+ "plt.ylabel('Frequency')\n",
76
+ "plt.show()"
77
+ ],
78
+ "execution_count": null,
79
+ "outputs": []
80
+ },
81
+ {
82
+ "cell_type": "code",
83
+ "metadata": {},
84
+ "source": [
85
+ "# Task 1: Write your code here:\n",
86
+ "df_clean = df_delivery\n",
87
+ "df_clean= df_clean.drop('Order_ID',axis=1)\n",
88
+ "df_clean.head()"
89
+ ],
90
+ "execution_count": null,
91
+ "outputs": []
92
+ },
93
+ {
94
+ "cell_type": "code",
95
+ "metadata": {},
96
+ "source": [
97
+ "# Task 2: Write your code here:\n",
98
+ "df_clean = df_clean.dropna(subset=['Weather','Traffic_Level','Time_of_Day','Courier_Experience_yrs','Delivery_Time'])\n",
99
+ "df_clean.isnull().sum()\n"
100
+ ],
101
+ "execution_count": null,
102
+ "outputs": []
103
+ },
104
+ {
105
+ "cell_type": "code",
106
+ "metadata": {},
107
+ "source": [
108
+ "# Task 3: Write your code here:\n",
109
+ "df_clean.duplicated()\n",
110
+ "df_clean = df_clean.drop_duplicates()\n"
111
+ ],
112
+ "execution_count": null,
113
+ "outputs": []
114
+ },
115
+ {
116
+ "cell_type": "code",
117
+ "metadata": {},
118
+ "source": [
119
+ "# Task 4: Write your code here:\n",
120
+ "from sklearn.preprocessing import OneHotEncoder\n",
121
+ "encoder = OneHotEncoder(sparse_output=False)\n",
122
+ "encoded = encoder.fit_transform(df_clean)\n",
123
+ "print(\"before:\", df_clean)\n",
124
+ "print(\"after:\\n\", encoded)\n"
125
+ ],
126
+ "execution_count": null,
127
+ "outputs": []
128
+ },
129
+ {
130
+ "cell_type": "code",
131
+ "metadata": {},
132
+ "source": [
133
+ "# Task 5: Write your code here:\n",
134
+ "from sklearn.preprocessing import StandardScaler\n",
135
+ "scaler = StandardScaler()\n",
136
+ "scaled = scaler.fit_transform(encoded)\n",
137
+ "print(scaled)"
138
+ ],
139
+ "execution_count": null,
140
+ "outputs": []
141
+ },
142
+ {
143
+ "cell_type": "code",
144
+ "metadata": {},
145
+ "source": [
146
+ "# Task 6: Write your code here:\n",
147
+ "counts = df_clean['Delivery_Time'].value_counts()\n",
148
+ "print(counts)\n"
149
+ ],
150
+ "execution_count": null,
151
+ "outputs": []
152
+ },
153
+ {
154
+ "cell_type": "code",
155
+ "metadata": {},
156
+ "source": [
157
+ "# Task 1: Write your code here:\n",
158
+ "from sklearn.model_selection import train_test_split\n",
159
+ "X= df_clean.drop('Delivery_Time', axis=1)\n",
160
+ "y=df_clean['Delivery_Time']\n",
161
+ "X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)\n",
162
+ "print(f\"Train: {X_train.shape}, Test: {X_test.shape}\")\n",
163
+ "\n"
164
+ ],
165
+ "execution_count": null,
166
+ "outputs": []
167
+ },
168
+ {
169
+ "cell_type": "code",
170
+ "metadata": {},
171
+ "source": [
172
+ "# Task 2,3,4,5: Write your code here:\n",
173
+ "from sklearn.model_selection import StratifiedKFold, cross_val_score\n",
174
+ "from sklearn.tree import DecisionTreeRegressor\n",
175
+ "from sklearn.ensemble import RandomForestClassifier\n",
176
+ "from sklearn.metrics import accuracy_score\n",
177
+ "from sklearn.metrics import mean_absolute_error\n",
178
+ "\n",
179
+ "\n",
180
+ "full_ratio = (y.value_counts(normalize=True) * 100).sort_index()\n",
181
+ "print(\"Full Dataset Class Distribution\")\n",
182
+ "print(\" y class percentages:\", {k: f\"{v:.2f}%\" for k, v in full_ratio.items()})\n",
183
+ "print(\"-\" * 40)\n",
184
+ "\n",
185
+ "skf = StratifiedKFold(n_splits=5, shuffle=True, random_state=42)\n",
186
+ "\n",
187
+ "\n",
188
+ "for fold, (train_idx, test_idx) in enumerate(skf.split(X, y), start=1):\n",
189
+ " X_train, X_test = X.iloc[train_idx], X.iloc[test_idx]\n",
190
+ " y_train, y_test = y.iloc[train_idx], y.iloc[test_idx]\n",
191
+ "\n",
192
+ " print(f\"Fold {fold}\")\n",
193
+ " print(\" X_train shape:\", X_train.shape)\n",
194
+ " print(\" X_test shape :\", X_test.shape)\n",
195
+ " print(\" y_train shape:\", y_train.shape)\n",
196
+ " print(\" y_test shape :\", y_test.shape)\n",
197
+ "\n",
198
+ " train_ratio = (y_train.value_counts(normalize=True) * 100).sort_index()\n",
199
+ " test_ratio = (y_test.value_counts(normalize=True) * 100).sort_index()\n",
200
+ "\n",
201
+ " print(\" y_train class percentages:\", {k: f\"{v:.2f}%\" for k, v in train_ratio.items()})\n",
202
+ " print(\" y_test class percentages :\", {k: f\"{v:.2f}%\" for k, v in test_ratio.items()})\n",
203
+ "\n",
204
+ "rf = RandomForestClassifier(n_estimators=100, max_depth=5, random_state=42)\n",
205
+ "rf.fit(X_train, y_train)\n",
206
+ "rf_pred = rf.predict(X_test)\n",
207
+ "print(\"Random Forest Accuracy:\", accuracy_score(y_test, rf_pred))\n",
208
+ "\n",
209
+ "mae = mean_absolute_error(y_true, y_pred)\n",
210
+ "print(f\"MAE: {mae:.2f}\")\n",
211
+ "\n",
212
+ "\n",
213
+ "scores = cross_val_score(model, X, y, cv=kfold, scoring='accuracy')\n",
214
+ "print(\"KFold scores:\", scores)\n",
215
+ "print(f\"Mean accuracy: {scores.mean():.3f} (+/- {scores.std():.3f})\")"
216
+ ],
217
+ "execution_count": null,
218
+ "outputs": []
219
+ },
220
+ {
221
+ "cell_type": "code",
222
+ "metadata": {},
223
+ "source": [
224
+ "# Task 1: Write your code here:\n"
225
+ ],
226
+ "execution_count": null,
227
+ "outputs": []
228
+ },
229
+ {
230
+ "cell_type": "code",
231
+ "metadata": {},
232
+ "source": [
233
+ "# Task 2: Write your code here:"
234
+ ],
235
+ "execution_count": null,
236
+ "outputs": []
237
+ },
238
+ {
239
+ "cell_type": "code",
240
+ "metadata": {},
241
+ "source": [
242
+ "# Task Bonus: Write your code here:"
243
+ ],
244
+ "execution_count": null,
245
+ "outputs": []
246
+ }
247
+ ],
248
+ "metadata": {
249
+ "kernelspec": {
250
+ "display_name": "Python 3",
251
+ "name": "python3"
252
+ },
253
+ "language_info": {
254
+ "name": "python"
255
+ }
256
+ },
257
+ "nbformat": 4,
258
+ "nbformat_minor": 0
259
+ }
submissions_extracted/1004/Q1.ipynb ADDED
@@ -0,0 +1,286 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "metadata": {},
6
+ "source": [
7
+ "import kagglehub\n",
8
+ "\n",
9
+ "# Download latest version\n",
10
+ "path = kagglehub.dataset_download(\"ANON_OWNER/q1-exam-data\")\n",
11
+ "\n",
12
+ "print(\"Path to dataset files:\", path)"
13
+ ],
14
+ "execution_count": null,
15
+ "outputs": []
16
+ },
17
+ {
18
+ "cell_type": "code",
19
+ "metadata": {},
20
+ "source": [
21
+ "# Task 1: Write your code here:\n",
22
+ "import pandas as pd\n",
23
+ "\n",
24
+ "df = pd.read_csv(f\"{path}/Q1_data.csv\")"
25
+ ],
26
+ "execution_count": null,
27
+ "outputs": []
28
+ },
29
+ {
30
+ "cell_type": "code",
31
+ "metadata": {},
32
+ "source": [
33
+ "# Task 2: Write your code here:\n",
34
+ "df.head()"
35
+ ],
36
+ "execution_count": null,
37
+ "outputs": []
38
+ },
39
+ {
40
+ "cell_type": "code",
41
+ "metadata": {},
42
+ "source": [
43
+ "# Task 3: Write your code here:\n",
44
+ "df.info()"
45
+ ],
46
+ "execution_count": null,
47
+ "outputs": []
48
+ },
49
+ {
50
+ "cell_type": "code",
51
+ "metadata": {},
52
+ "source": [
53
+ "# Task 4: Write your code here:\n",
54
+ "df.describe()"
55
+ ],
56
+ "execution_count": null,
57
+ "outputs": []
58
+ },
59
+ {
60
+ "cell_type": "code",
61
+ "metadata": {},
62
+ "source": [
63
+ "# Task 5: Write your code here:\n",
64
+ "import matplotlib.pyplot as plt\n",
65
+ "\n",
66
+ "plt.hist(df[\"Delivery_Time\"], bins=30)\n",
67
+ "plt.xlabel(\"Delivery Time (minutes)\")\n",
68
+ "plt.ylabel(\"Frequency\")\n",
69
+ "plt.title(\"Distribution of Delivery Time\")\n",
70
+ "plt.show()\n"
71
+ ],
72
+ "execution_count": null,
73
+ "outputs": []
74
+ },
75
+ {
76
+ "cell_type": "code",
77
+ "metadata": {},
78
+ "source": [
79
+ "# Task 1: Write your code here:\n",
80
+ "df = df.drop(columns=[\"Order_ID\"])\n"
81
+ ],
82
+ "execution_count": null,
83
+ "outputs": []
84
+ },
85
+ {
86
+ "cell_type": "code",
87
+ "metadata": {},
88
+ "source": [
89
+ "# Task 2: Write your code here:\n",
90
+ "for col in df.columns:\n",
91
+ " if df[col].dtype == \"object\":\n",
92
+ " df[col] = df[col].fillna(df[col].mode()[0])\n",
93
+ " else:\n",
94
+ " df[col] = df[col].fillna(df[col].median())\n"
95
+ ],
96
+ "execution_count": null,
97
+ "outputs": []
98
+ },
99
+ {
100
+ "cell_type": "code",
101
+ "metadata": {},
102
+ "source": [
103
+ "# Task 3: Write your code here:\n",
104
+ "df = df.drop_duplicates()\n"
105
+ ],
106
+ "execution_count": null,
107
+ "outputs": []
108
+ },
109
+ {
110
+ "cell_type": "code",
111
+ "metadata": {},
112
+ "source": [
113
+ "# Task 4: Write your code here:\n",
114
+ "df = pd.get_dummies(df, drop_first=True)\n"
115
+ ],
116
+ "execution_count": null,
117
+ "outputs": []
118
+ },
119
+ {
120
+ "cell_type": "code",
121
+ "metadata": {},
122
+ "source": [
123
+ "# Task 5: Write your code here:\n",
124
+ "from sklearn.preprocessing import StandardScaler\n",
125
+ "\n",
126
+ "X = df.drop(columns=[\"Delivery_Time\"])\n",
127
+ "y = df[\"Delivery_Time\"]\n",
128
+ "\n",
129
+ "scaler = StandardScaler()\n",
130
+ "X_scaled = scaler.fit_transform(X)\n"
131
+ ],
132
+ "execution_count": null,
133
+ "outputs": []
134
+ },
135
+ {
136
+ "cell_type": "code",
137
+ "metadata": {},
138
+ "source": [
139
+ "# Task 1: Write your code here:\n",
140
+ "import numpy as np\n",
141
+ "from sklearn.model_selection import KFold, cross_val_score\n",
142
+ "from sklearn.ensemble import RandomForestRegressor\n",
143
+ "\n",
144
+ "X = df.drop(columns=[\"Delivery_Time\"])\n",
145
+ "y = df[\"Delivery_Time\"]\n"
146
+ ],
147
+ "execution_count": null,
148
+ "outputs": []
149
+ },
150
+ {
151
+ "cell_type": "code",
152
+ "metadata": {},
153
+ "source": [
154
+ "# Task 2,3,4,5: Write your code here:\n",
155
+ "kf = KFold(n_splits=5, shuffle=True, random_state=42)\n",
156
+ "\n",
157
+ "model = RandomForestRegressor(\n",
158
+ " n_estimators=300,\n",
159
+ " random_state=42,\n",
160
+ " n_jobs=-1\n",
161
+ ")\n",
162
+ "\n",
163
+ "mae_scores = -cross_val_score(model, X, y, cv=kf, scoring=\"neg_mean_absolute_error\")\n",
164
+ "\n",
165
+ "print(\"MAE per fold:\", mae_scores)\n",
166
+ "print(\"Average MAE:\", mae_scores.mean())\n"
167
+ ],
168
+ "execution_count": null,
169
+ "outputs": []
170
+ },
171
+ {
172
+ "cell_type": "code",
173
+ "metadata": {},
174
+ "source": [
175
+ "# Task 1: Write your code here:\n",
176
+ "import numpy as np\n",
177
+ "import matplotlib.pyplot as plt\n",
178
+ "from sklearn.model_selection import train_test_split\n",
179
+ "from sklearn.ensemble import RandomForestRegressor\n",
180
+ "\n",
181
+ "X = df.drop(columns=[\"Delivery_Time\"])\n",
182
+ "y = df[\"Delivery_Time\"]\n",
183
+ "\n",
184
+ "X_train, X_test, y_train, y_test = train_test_split(\n",
185
+ " X, y, test_size=0.2, random_state=42\n",
186
+ ")\n",
187
+ "\n",
188
+ "model = RandomForestRegressor(n_estimators=300, random_state=42, n_jobs=-1)\n",
189
+ "model.fit(X_train, y_train)\n",
190
+ "\n",
191
+ "importances = model.feature_importances_\n",
192
+ "idx = np.argsort(importances)[-15:] # top 15\n",
193
+ "\n",
194
+ "plt.barh(X.columns[idx], importances[idx])\n",
195
+ "plt.xlabel(\"Importance\")\n",
196
+ "plt.title(\"Top Feature Importances (RandomForest)\")\n",
197
+ "plt.show()\n"
198
+ ],
199
+ "execution_count": null,
200
+ "outputs": []
201
+ },
202
+ {
203
+ "cell_type": "code",
204
+ "metadata": {},
205
+ "source": [
206
+ "# Task 2: Write your code here:\n",
207
+ "y_pred = model.predict(X_test)\n",
208
+ "\n",
209
+ "plt.hist(y_pred, bins=30)\n",
210
+ "plt.xlabel(\"Predicted Delivery Time (minutes)\")\n",
211
+ "plt.ylabel(\"Frequency\")\n",
212
+ "plt.title(\"Histogram of Predicted Delivery Time\")\n",
213
+ "plt.show()\n"
214
+ ],
215
+ "execution_count": null,
216
+ "outputs": []
217
+ },
218
+ {
219
+ "cell_type": "code",
220
+ "metadata": {},
221
+ "source": [
222
+ "!pip -q install catboost\n"
223
+ ],
224
+ "execution_count": null,
225
+ "outputs": []
226
+ },
227
+ {
228
+ "cell_type": "code",
229
+ "metadata": {},
230
+ "source": [
231
+ "# Task Bonus: Write your code here:\n",
232
+ "import numpy as np\n",
233
+ "from sklearn.model_selection import KFold\n",
234
+ "from sklearn.ensemble import RandomForestRegressor\n",
235
+ "from sklearn.metrics import mean_absolute_error\n",
236
+ "from catboost import CatBoostRegressor\n",
237
+ "X = df.drop(columns=[\"Delivery_Time\"]).values\n",
238
+ "y = df[\"Delivery_Time\"].values\n",
239
+ "\n",
240
+ "kf = KFold(n_splits=5, shuffle=True, random_state=42)\n",
241
+ "\n",
242
+ "mae_scores = []\n",
243
+ "\n",
244
+ "for train_idx, val_idx in kf.split(X):\n",
245
+ " X_train, X_val = X[train_idx], X[val_idx]\n",
246
+ " y_train, y_val = y[train_idx], y[val_idx]\n",
247
+ "\n",
248
+ " rf = RandomForestRegressor(n_estimators=300, random_state=42, n_jobs=-1)\n",
249
+ " cb = CatBoostRegressor(iterations=500, learning_rate=0.05, depth=8, verbose=0, random_state=42)\n",
250
+ "\n",
251
+ " rf.fit(X_train, y_train)\n",
252
+ " cb.fit(X_train, y_train)\n",
253
+ "\n",
254
+ " pred_rf = rf.predict(X_val)\n",
255
+ " pred_cb = cb.predict(X_val)\n",
256
+ "\n",
257
+ " pred_avg = (pred_rf + pred_cb) / 2.0\n",
258
+ "\n",
259
+ " mae_scores.append(mean_absolute_error(y_val, pred_avg))\n",
260
+ "\n",
261
+ "print(\"MAE per fold:\", mae_scores)\n",
262
+ "print(\"Average MAE:\", np.mean(mae_scores))\n"
263
+ ],
264
+ "execution_count": null,
265
+ "outputs": []
266
+ },
267
+ {
268
+ "cell_type": "code",
269
+ "metadata": {},
270
+ "source": [],
271
+ "execution_count": null,
272
+ "outputs": []
273
+ }
274
+ ],
275
+ "metadata": {
276
+ "kernelspec": {
277
+ "display_name": "Python 3",
278
+ "name": "python3"
279
+ },
280
+ "language_info": {
281
+ "name": "python"
282
+ }
283
+ },
284
+ "nbformat": 4,
285
+ "nbformat_minor": 0
286
+ }
submissions_extracted/1004/Q2.ipynb ADDED
@@ -0,0 +1,330 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "metadata": {},
6
+ "source": [
7
+ "import kagglehub\n",
8
+ "\n",
9
+ "# Download latest version\n",
10
+ "path = kagglehub.dataset_download(\"ANON_OWNER/q2-exam-data\")\n",
11
+ "\n",
12
+ "print(\"Path to dataset files:\", path)"
13
+ ],
14
+ "execution_count": null,
15
+ "outputs": []
16
+ },
17
+ {
18
+ "cell_type": "code",
19
+ "metadata": {},
20
+ "source": [
21
+ "import os\n",
22
+ "import pandas as pd\n",
23
+ "import numpy as np\n",
24
+ "from PIL import Image\n",
25
+ "from sklearn.model_selection import train_test_split\n",
26
+ "\n",
27
+ "# Load Labels\n",
28
+ "labels_df = pd.read_csv(os.path.join(path, \"labels.csv\"))\n",
29
+ "img_dir = os.path.join(path, \"images\")\n",
30
+ "\n",
31
+ "images = []\n",
32
+ "ages = []\n",
33
+ "\n",
34
+ "# Load Images and Resize\n",
35
+ "print(\"Loading images...\")\n",
36
+ "for index, row in labels_df.iterrows():\n",
37
+ " img_name = row.iloc[0]\n",
38
+ " age = row.iloc[1]\n",
39
+ " img_path = os.path.join(img_dir, img_name)\n",
40
+ "\n",
41
+ " if os.path.exists(img_path):\n",
42
+ " img = Image.open(img_path).convert('RGB')\n",
43
+ " img_array = np.array(img) / 255.0 # Normalize pixel values to [0, 1]\n",
44
+ " images.append(img_array)\n",
45
+ " ages.append(age)\n",
46
+ "\n",
47
+ "X = np.array(images)\n",
48
+ "y = np.array(ages)\n",
49
+ "\n",
50
+ "# Transpose image dimensions to match PyTorch format (N, C, H, W)\n",
51
+ "X = np.transpose(X, (0, 3, 1, 2))\n",
52
+ "\n",
53
+ "# Split Data\n",
54
+ "X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)\n",
55
+ "\n",
56
+ "print(f\"X_train shape: {X_train.shape}\")\n",
57
+ "print(f\"X_test shape: {X_test.shape}\")\n",
58
+ "print(f\"y_train shape: {y_train.shape}\")\n",
59
+ "print(f\"y_test shape: {y_test.shape}\")"
60
+ ],
61
+ "execution_count": null,
62
+ "outputs": []
63
+ },
64
+ {
65
+ "cell_type": "code",
66
+ "metadata": {},
67
+ "source": [
68
+ "# 1. Convert Numpy arrays to PyTorch Tensors\n",
69
+ "\n",
70
+ "import torch\n",
71
+ "from torch.utils.data import TensorDataset, DataLoader\n",
72
+ "import matplotlib.pyplot as plt\n",
73
+ "\n"
74
+ ],
75
+ "execution_count": null,
76
+ "outputs": []
77
+ },
78
+ {
79
+ "cell_type": "code",
80
+ "metadata": {},
81
+ "source": [
82
+ "# 2. Create TensorDataset objects\n",
83
+ "\n",
84
+ "X_train_t = torch.tensor(X_train, dtype=torch.float32)\n",
85
+ "X_test_t = torch.tensor(X_test, dtype=torch.float32)\n",
86
+ "\n",
87
+ "y_train_t = torch.tensor(y_train, dtype=torch.float32).view(-1, 1)\n",
88
+ "y_test_t = torch.tensor(y_test, dtype=torch.float32).view(-1, 1)\n",
89
+ "\n",
90
+ "train_dataset = TensorDataset(X_train_t, y_train_t)\n",
91
+ "test_dataset = TensorDataset(X_test_t, y_test_t)\n",
92
+ "\n"
93
+ ],
94
+ "execution_count": null,
95
+ "outputs": []
96
+ },
97
+ {
98
+ "cell_type": "code",
99
+ "metadata": {},
100
+ "source": [
101
+ "# 3. Create DataLoaders\n",
102
+ "\n",
103
+ "train_loader = DataLoader(train_dataset, batch_size=32, shuffle=True)\n",
104
+ "test_loader = DataLoader(test_dataset, batch_size=32, shuffle=False)\n",
105
+ "\n"
106
+ ],
107
+ "execution_count": null,
108
+ "outputs": []
109
+ },
110
+ {
111
+ "cell_type": "code",
112
+ "metadata": {},
113
+ "source": [
114
+ "# 4. Print shape of one batch\n",
115
+ "\n",
116
+ "xb, yb = next(iter(train_loader))\n",
117
+ "print(\"X batch:\", xb.shape)\n",
118
+ "print(\"y batch:\", yb.shape)\n"
119
+ ],
120
+ "execution_count": null,
121
+ "outputs": []
122
+ },
123
+ {
124
+ "cell_type": "code",
125
+ "metadata": {},
126
+ "source": [
127
+ "# 5. Display sample images\n",
128
+ "\n",
129
+ "xb, yb = next(iter(train_loader))\n",
130
+ "\n",
131
+ "plt.figure(figsize=(8, 3))\n",
132
+ "for i in range(6):\n",
133
+ " plt.subplot(2, 3, i+1)\n",
134
+ " img = xb[i].permute(1, 2, 0).numpy()\n",
135
+ " plt.imshow(img)\n",
136
+ " plt.title(f\"age={yb[i].item():.0f}\")\n",
137
+ " plt.axis(\"off\")\n",
138
+ "plt.tight_layout()\n",
139
+ "plt.show()\n"
140
+ ],
141
+ "execution_count": null,
142
+ "outputs": []
143
+ },
144
+ {
145
+ "cell_type": "code",
146
+ "metadata": {},
147
+ "source": [
148
+ "# Task 1: Write your model class here:\n",
149
+ "import torch\n",
150
+ "import torch.nn as nn\n",
151
+ "\n",
152
+ "class AgeRegressor(nn.Module):\n",
153
+ " def __init__(self):\n",
154
+ " super().__init__()\n",
155
+ " self.net = nn.Sequential(\n",
156
+ " nn.Flatten(),\n",
157
+ " nn.Linear(3*36*36, 512),\n",
158
+ " nn.ReLU(),\n",
159
+ " nn.Linear(512, 256),\n",
160
+ " nn.ReLU(),\n",
161
+ " nn.Linear(256, 128),\n",
162
+ " nn.ReLU(),\n",
163
+ " nn.Linear(128, 1)\n",
164
+ " )\n",
165
+ "\n",
166
+ " def forward(self, x):\n",
167
+ " return self.net(x)\n"
168
+ ],
169
+ "execution_count": null,
170
+ "outputs": []
171
+ },
172
+ {
173
+ "cell_type": "code",
174
+ "metadata": {},
175
+ "source": [
176
+ "# Task 2: Write your training loop here:\n",
177
+ "def train_one_epoch(model, loader, criterion, optimizer, device):\n",
178
+ " model.train()\n",
179
+ " running_loss = 0.0\n",
180
+ " n = 0\n",
181
+ "\n",
182
+ " for xb, yb in loader:\n",
183
+ " xb = xb.to(device)\n",
184
+ " yb = yb.to(device)\n",
185
+ "\n",
186
+ " optimizer.zero_grad()\n",
187
+ " preds = model(xb)\n",
188
+ " loss = criterion(preds, yb)\n",
189
+ " loss.backward()\n",
190
+ " optimizer.step()\n",
191
+ "\n",
192
+ " bs = xb.size(0)\n",
193
+ " running_loss += loss.item() * bs\n",
194
+ " n += bs\n",
195
+ "\n",
196
+ " return running_loss / n\n"
197
+ ],
198
+ "execution_count": null,
199
+ "outputs": []
200
+ },
201
+ {
202
+ "cell_type": "code",
203
+ "metadata": {},
204
+ "source": [
205
+ "# Task 3: Write your validation loop here:\n",
206
+ "def validate(model, loader, criterion, device):\n",
207
+ " model.eval()\n",
208
+ " running_loss = 0.0\n",
209
+ " n = 0\n",
210
+ "\n",
211
+ " with torch.no_grad():\n",
212
+ " for xb, yb in loader:\n",
213
+ " xb = xb.to(device)\n",
214
+ " yb = yb.to(device)\n",
215
+ "\n",
216
+ " preds = model(xb)\n",
217
+ " loss = criterion(preds, yb)\n",
218
+ "\n",
219
+ " bs = xb.size(0)\n",
220
+ " running_loss += loss.item() * bs\n",
221
+ " n += bs\n",
222
+ "\n",
223
+ " return running_loss / n\n"
224
+ ],
225
+ "execution_count": null,
226
+ "outputs": []
227
+ },
228
+ {
229
+ "cell_type": "code",
230
+ "metadata": {},
231
+ "source": [
232
+ "# Task 4: Define device, model, loss, optimizer:\n",
233
+ "device = torch.device(\"cuda\" if torch.cuda.is_available() else \"cpu\")\n",
234
+ "\n",
235
+ "model = AgeRegressor().to(device)\n",
236
+ "criterion = nn.L1Loss() # MAE loss\n",
237
+ "optimizer = torch.optim.Adam(model.parameters(), lr=1e-3)\n"
238
+ ],
239
+ "execution_count": null,
240
+ "outputs": []
241
+ },
242
+ {
243
+ "cell_type": "code",
244
+ "metadata": {},
245
+ "source": [
246
+ "# Task 5: Start training for 20 epochs:\n",
247
+ "train_losses = []\n",
248
+ "val_losses = []\n",
249
+ "\n",
250
+ "for epoch in range(20):\n",
251
+ " tr_loss = train_one_epoch(model, train_loader, criterion, optimizer, device)\n",
252
+ " va_loss = validate(model, test_loader, criterion, device)\n",
253
+ "\n",
254
+ " train_losses.append(tr_loss)\n",
255
+ " val_losses.append(va_loss)\n",
256
+ "\n",
257
+ " print(f\"Epoch {epoch+1:02d} | Train MAE: {tr_loss:.4f} | Val MAE: {va_loss:.4f}\")\n"
258
+ ],
259
+ "execution_count": null,
260
+ "outputs": []
261
+ },
262
+ {
263
+ "cell_type": "code",
264
+ "metadata": {},
265
+ "source": [
266
+ "# Task 1: Write your code here:\n",
267
+ "import matplotlib.pyplot as plt\n",
268
+ "\n",
269
+ "plt.plot(train_losses, label=\"train\")\n",
270
+ "plt.plot(val_losses, label=\"val\")\n",
271
+ "plt.xlabel(\"Epoch\")\n",
272
+ "plt.ylabel(\"MAE Loss\")\n",
273
+ "plt.title(\"Training vs Validation Loss\")\n",
274
+ "plt.legend()\n",
275
+ "plt.show()\n"
276
+ ],
277
+ "execution_count": null,
278
+ "outputs": []
279
+ },
280
+ {
281
+ "cell_type": "code",
282
+ "metadata": {},
283
+ "source": [
284
+ "# Task 2 (Bonus): Write your code here:\n",
285
+ "model.eval()\n",
286
+ "\n",
287
+ "xb, yb = next(iter(test_loader))\n",
288
+ "xb = xb.to(device)\n",
289
+ "yb = yb.to(device)\n",
290
+ "\n",
291
+ "with torch.no_grad():\n",
292
+ " preds = model(xb)\n",
293
+ "\n",
294
+ "xb = xb.cpu()\n",
295
+ "yb = yb.cpu()\n",
296
+ "preds = preds.cpu()\n",
297
+ "\n",
298
+ "plt.figure(figsize=(10, 4))\n",
299
+ "for i in range(6):\n",
300
+ " plt.subplot(2, 3, i+1)\n",
301
+ " img = xb[i].permute(1, 2, 0).numpy()\n",
302
+ " plt.imshow(img)\n",
303
+ " plt.title(f\"Pred={preds[i].item():.1f} | True={yb[i].item():.1f}\")\n",
304
+ " plt.axis(\"off\")\n",
305
+ "plt.tight_layout()\n",
306
+ "plt.show()\n"
307
+ ],
308
+ "execution_count": null,
309
+ "outputs": []
310
+ },
311
+ {
312
+ "cell_type": "code",
313
+ "metadata": {},
314
+ "source": [],
315
+ "execution_count": null,
316
+ "outputs": []
317
+ }
318
+ ],
319
+ "metadata": {
320
+ "kernelspec": {
321
+ "display_name": "Python 3",
322
+ "name": "python3"
323
+ },
324
+ "language_info": {
325
+ "name": "python"
326
+ }
327
+ },
328
+ "nbformat": 4,
329
+ "nbformat_minor": 0
330
+ }
submissions_extracted/1004/Q3.ipynb ADDED
@@ -0,0 +1,250 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "metadata": {},
6
+ "source": [
7
+ "import kagglehub\n",
8
+ "\n",
9
+ "\n",
10
+ "\n",
11
+ "# Download latest version\n",
12
+ "\n",
13
+ "path = kagglehub.dataset_download(\"ANON_OWNER/q3-exam-data\")\n",
14
+ "\n",
15
+ "\n",
16
+ "\n",
17
+ "print(\"Path to dataset files:\", path)"
18
+ ],
19
+ "execution_count": null,
20
+ "outputs": []
21
+ },
22
+ {
23
+ "cell_type": "code",
24
+ "metadata": {},
25
+ "source": [
26
+ "# Task 1: Write your code here:\n",
27
+ "import pandas as pd\n",
28
+ "\n",
29
+ "df = pd.read_csv(f\"{path}/Q3_data.csv\")\n"
30
+ ],
31
+ "execution_count": null,
32
+ "outputs": []
33
+ },
34
+ {
35
+ "cell_type": "code",
36
+ "metadata": {},
37
+ "source": [
38
+ "# Task 2: Write your code here:\n",
39
+ "df.head()\n"
40
+ ],
41
+ "execution_count": null,
42
+ "outputs": []
43
+ },
44
+ {
45
+ "cell_type": "code",
46
+ "metadata": {},
47
+ "source": [
48
+ "# Task 3: Write your code here:\n",
49
+ "df.info()\n"
50
+ ],
51
+ "execution_count": null,
52
+ "outputs": []
53
+ },
54
+ {
55
+ "cell_type": "code",
56
+ "metadata": {},
57
+ "source": [
58
+ "# Task 4: Write your code here:\n",
59
+ "df.describe()\n"
60
+ ],
61
+ "execution_count": null,
62
+ "outputs": []
63
+ },
64
+ {
65
+ "cell_type": "code",
66
+ "metadata": {},
67
+ "source": [
68
+ "# Task 1: Write your code here:\n",
69
+ "df.columns = df.columns.str.strip().str.lower()\n",
70
+ "for col in df.columns:\n",
71
+ " if df[col].dtype == \"object\":\n",
72
+ " df[col] = df[col].fillna(df[col].mode()[0])\n",
73
+ " else:\n",
74
+ " df[col] = df[col].fillna(df[col].median())\n"
75
+ ],
76
+ "execution_count": null,
77
+ "outputs": []
78
+ },
79
+ {
80
+ "cell_type": "code",
81
+ "metadata": {},
82
+ "source": [
83
+ "# Task 2: Write your code here:\n",
84
+ "df = df.drop_duplicates()\n"
85
+ ],
86
+ "execution_count": null,
87
+ "outputs": []
88
+ },
89
+ {
90
+ "cell_type": "code",
91
+ "metadata": {},
92
+ "source": [
93
+ "# Task 3: Write your code here:\n",
94
+ "df = pd.get_dummies(df, drop_first=True)\n"
95
+ ],
96
+ "execution_count": null,
97
+ "outputs": []
98
+ },
99
+ {
100
+ "cell_type": "code",
101
+ "metadata": {},
102
+ "source": [
103
+ "# Task 4: Write your code here:\n",
104
+ "# حدد عمود الهدف الصحيح\n",
105
+ "target_col = \"Target\" if \"Target\" in df.columns else \"target\"\n",
106
+ "\n",
107
+ "X = df.drop(columns=[target_col])\n",
108
+ "y = df[target_col]\n",
109
+ "\n",
110
+ "from sklearn.preprocessing import StandardScaler\n",
111
+ "scaler = StandardScaler()\n",
112
+ "X_scaled = scaler.fit_transform(X)\n"
113
+ ],
114
+ "execution_count": null,
115
+ "outputs": []
116
+ },
117
+ {
118
+ "cell_type": "code",
119
+ "metadata": {},
120
+ "source": [
121
+ "# Task 5: Write your code here:\n",
122
+ "target_col = \"Target\" if \"Target\" in df.columns else \"target\"\n",
123
+ "\n",
124
+ "df[target_col].value_counts(normalize=True)\n"
125
+ ],
126
+ "execution_count": null,
127
+ "outputs": []
128
+ },
129
+ {
130
+ "cell_type": "code",
131
+ "metadata": {},
132
+ "source": [
133
+ "# Task 1: Write your code here:\n",
134
+ "target_col = \"Target\" if \"Target\" in df.columns else \"target\"\n",
135
+ "\n",
136
+ "X = df.drop(columns=[target_col])\n",
137
+ "y = df[target_col]\n"
138
+ ],
139
+ "execution_count": null,
140
+ "outputs": []
141
+ },
142
+ {
143
+ "cell_type": "code",
144
+ "metadata": {},
145
+ "source": [
146
+ "# Task 2,3,4,5: Write your code here:\n",
147
+ "import numpy as np\n",
148
+ "from sklearn.model_selection import StratifiedKFold, cross_val_score\n",
149
+ "from sklearn.ensemble import RandomForestClassifier\n",
150
+ "\n",
151
+ "skf = StratifiedKFold(n_splits=3, shuffle=True, random_state=42)\n",
152
+ "\n",
153
+ "model = RandomForestClassifier(\n",
154
+ " n_estimators=100,\n",
155
+ " max_depth=12,\n",
156
+ " random_state=42,\n",
157
+ " n_jobs=1\n",
158
+ ")\n",
159
+ "\n",
160
+ "score_name = \"f1\" if y.value_counts(normalize=True).max() > 0.7 else \"accuracy\"\n",
161
+ "scores = cross_val_score(model, X, y, cv=skf, scoring=score_name)\n",
162
+ "\n",
163
+ "print(\"Metric:\", score_name)\n",
164
+ "print(\"Scores:\", scores)\n",
165
+ "print(\"Average:\", scores.mean())\n",
166
+ "\n"
167
+ ],
168
+ "execution_count": null,
169
+ "outputs": []
170
+ },
171
+ {
172
+ "cell_type": "code",
173
+ "metadata": {},
174
+ "source": [
175
+ "# Task 1: Write your code here:\n",
176
+ "import numpy as np\n",
177
+ "import matplotlib.pyplot as plt\n",
178
+ "from sklearn.ensemble import RandomForestClassifier\n",
179
+ "\n",
180
+ "model = RandomForestClassifier(n_estimators=200, random_state=42, n_jobs=1)\n",
181
+ "model.fit(X, y)\n",
182
+ "\n",
183
+ "importances = model.feature_importances_\n",
184
+ "idx = np.argsort(importances)[::-1]\n",
185
+ "\n",
186
+ "top = 15\n",
187
+ "plt.barh(X.columns[idx[:top]][::-1], importances[idx[:top]][::-1])\n",
188
+ "plt.xlabel(\"Importance\")\n",
189
+ "plt.title(\"Top Feature Importances\")\n",
190
+ "plt.show()\n"
191
+ ],
192
+ "execution_count": null,
193
+ "outputs": []
194
+ },
195
+ {
196
+ "cell_type": "code",
197
+ "metadata": {},
198
+ "source": [
199
+ "# Task 2: Write your code here:\n",
200
+ "golden_feature = X.columns[idx[0]]\n",
201
+ "print(\"Golden Feature:\", golden_feature)\n"
202
+ ],
203
+ "execution_count": null,
204
+ "outputs": []
205
+ },
206
+ {
207
+ "cell_type": "code",
208
+ "metadata": {},
209
+ "source": [
210
+ "# Task Bonus: Write your code here:\n",
211
+ "import numpy as np\n",
212
+ "from sklearn.model_selection import StratifiedKFold, cross_val_score\n",
213
+ "from sklearn.ensemble import RandomForestClassifier\n",
214
+ "\n",
215
+ "skf = StratifiedKFold(n_splits=5, shuffle=True, random_state=42)\n",
216
+ "\n",
217
+ "model_full = RandomForestClassifier(n_estimators=100, random_state=42, n_jobs=1)\n",
218
+ "acc_full = cross_val_score(model_full, X, y, cv=skf, scoring=\"accuracy\").mean()\n",
219
+ "\n",
220
+ "X_golden = X[[golden_feature]]\n",
221
+ "\n",
222
+ "model_golden = RandomForestClassifier(n_estimators=100, random_state=42, n_jobs=1)\n",
223
+ "acc_golden = cross_val_score(model_golden, X_golden, y, cv=skf, scoring=\"accuracy\").mean()\n",
224
+ "\n",
225
+ "print(\"Full model accuracy:\", acc_full)\n",
226
+ "print(\"Golden-only accuracy:\", acc_golden)\n"
227
+ ],
228
+ "execution_count": null,
229
+ "outputs": []
230
+ },
231
+ {
232
+ "cell_type": "code",
233
+ "metadata": {},
234
+ "source": [],
235
+ "execution_count": null,
236
+ "outputs": []
237
+ }
238
+ ],
239
+ "metadata": {
240
+ "kernelspec": {
241
+ "display_name": "Python 3",
242
+ "name": "python3"
243
+ },
244
+ "language_info": {
245
+ "name": "python"
246
+ }
247
+ },
248
+ "nbformat": 4,
249
+ "nbformat_minor": 0
250
+ }
submissions_extracted/1005/Q1.ipynb ADDED
@@ -0,0 +1,261 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "metadata": {},
6
+ "source": [
7
+ "import kagglehub\n",
8
+ "\n",
9
+ "# Download latest version\n",
10
+ "path = kagglehub.dataset_download(\"ANON_OWNER/q1-exam-data\")\n",
11
+ "\n",
12
+ "print(\"Path to dataset files:\", path)"
13
+ ],
14
+ "execution_count": null,
15
+ "outputs": []
16
+ },
17
+ {
18
+ "cell_type": "code",
19
+ "metadata": {},
20
+ "source": [
21
+ "# Task 1: Write your code here:\n",
22
+ "import pandas as pd\n",
23
+ "df = pd.read_csv(f\"{path}/Q1_data.csv\")\n"
24
+ ],
25
+ "execution_count": null,
26
+ "outputs": []
27
+ },
28
+ {
29
+ "cell_type": "code",
30
+ "metadata": {},
31
+ "source": [
32
+ "# Task 2: Write your code here:\n",
33
+ "df.head()"
34
+ ],
35
+ "execution_count": null,
36
+ "outputs": []
37
+ },
38
+ {
39
+ "cell_type": "code",
40
+ "metadata": {},
41
+ "source": [
42
+ "# Task 3: Write your code here:\n",
43
+ "df.info()"
44
+ ],
45
+ "execution_count": null,
46
+ "outputs": []
47
+ },
48
+ {
49
+ "cell_type": "code",
50
+ "metadata": {},
51
+ "source": [
52
+ "# Task 4: Write your code here:\n",
53
+ "df.describe()"
54
+ ],
55
+ "execution_count": null,
56
+ "outputs": []
57
+ },
58
+ {
59
+ "cell_type": "code",
60
+ "metadata": {},
61
+ "source": [
62
+ "# Task 5: Write your code here:\n",
63
+ "# Plot the target distribution (delivery_time)\n",
64
+ "import matplotlib.pyplot as plt\n",
65
+ "\n",
66
+ "plt.figure(figsize=(10,5))\n",
67
+ "plt.hist(df['Delivery_Time'].dropna(),bins=30,edgecolor='black')\n",
68
+ "plt.title('delivery time')\n",
69
+ "plt.xlabel('delivery time')\n",
70
+ "plt.ylabel('time')\n",
71
+ "plt.show()"
72
+ ],
73
+ "execution_count": null,
74
+ "outputs": []
75
+ },
76
+ {
77
+ "cell_type": "code",
78
+ "metadata": {},
79
+ "source": [
80
+ "# Task 1: Write your code here:\n",
81
+ "# Drop the 'Order_ID' column from the data\n",
82
+ "y = df['Order_ID']\n",
83
+ "df= df.drop(\"Order_ID\",axis=1)\n"
84
+ ],
85
+ "execution_count": null,
86
+ "outputs": []
87
+ },
88
+ {
89
+ "cell_type": "code",
90
+ "metadata": {},
91
+ "source": [
92
+ "# Task 2: Write your code here:\n",
93
+ "# Handle missing values appropriately (Hint: I guess you want to have a closer look at the columns with missing values :) )\n",
94
+ "cols =['Weather','Traffic_Level','Time_of_Day','Courier_Experience_yrs','Delivery_Time']\n",
95
+ "df_clean = df.copy()\n",
96
+ "# Drop rows where target (price) or key features a\n",
97
+ "print(f\"Before:{df_clean.shape}\")\n",
98
+ "df_clean = df_clean.dropna(subset=['Weather','Traffic_Level','Time_of_Day','Courier_Experience_yrs','Delivery_Time'])\n",
99
+ "print(f\"After dropping missing:{df_clean.shape}\")"
100
+ ],
101
+ "execution_count": null,
102
+ "outputs": []
103
+ },
104
+ {
105
+ "cell_type": "code",
106
+ "metadata": {},
107
+ "source": [
108
+ "from numpy import diff\n",
109
+ "# Task 3: Write your code here:\n",
110
+ "# Check and remove duplicates if any exist\n",
111
+ "def check_duplicates(df):\n",
112
+ " duplicates = df.duplicated().sum()\n",
113
+ " print(f\"Number of Duplicate Samples: {duplicates}\")\n",
114
+ " if duplicates > 0:\n",
115
+ " print(\"Dropping Duplicates...\")\n",
116
+ " df.drop_duplicates(inplace=True)\n",
117
+ " print(\"Duplicates Dropped.\")\n",
118
+ " else:\n",
119
+ " print(\"No Duplicate Samples Found.\")\n",
120
+ "\n",
121
+ "check_duplicates(df_clean)"
122
+ ],
123
+ "execution_count": null,
124
+ "outputs": []
125
+ },
126
+ {
127
+ "cell_type": "code",
128
+ "metadata": {},
129
+ "source": [
130
+ "# Task 4: Write your code here:\n",
131
+ "# Encode categorical variables if needed (Bonus if used One Hot Encoding)\n",
132
+ "from sklearn.model_selection import train_test_split,KFold\n",
133
+ "from sklearn.preprocessing import StandardScaler,LabelEncoder\n",
134
+ "from sklearn.ensemble import RandomForestRegressor\n",
135
+ "categorical_cols = df.select_dtypes(include=[\"object\"]).columns\n",
136
+ "print(\"Categorical Columns:\",list(categorical_cols))\n",
137
+ "for col in categorical_cols:\n",
138
+ " le = LabelEncoder()\n",
139
+ " df_clean[col] = le.fit_transform(df_clean[col].astype(str))\n",
140
+ "df_clean.head()"
141
+ ],
142
+ "execution_count": null,
143
+ "outputs": []
144
+ },
145
+ {
146
+ "cell_type": "code",
147
+ "metadata": {},
148
+ "source": [
149
+ "# Task 5: Write your code here:\n",
150
+ "# Apply feature scaling for all features (Use StandardScaler)\n",
151
+ "numerical_cols = df_clean.select_dtypes(include=[\"number\"]).columns.drop(\"Delivery_Time\")\n",
152
+ "scaler = StandardScaler()\n",
153
+ "# scale the `numerical_cols`\n",
154
+ "df_clean[numerical_cols] = scaler.fit_transform(df_clean[numerical_cols])\n",
155
+ "df_clean.head()"
156
+ ],
157
+ "execution_count": null,
158
+ "outputs": []
159
+ },
160
+ {
161
+ "cell_type": "code",
162
+ "metadata": {},
163
+ "source": [
164
+ "# Task 6: Write your code here:\n",
165
+ "# Check for target imbalance and state if it is imbalanced or not (keep this cell empty if not needed)"
166
+ ],
167
+ "execution_count": null,
168
+ "outputs": []
169
+ },
170
+ {
171
+ "cell_type": "code",
172
+ "metadata": {},
173
+ "source": [
174
+ "# Task 1: Write your code here:\n",
175
+ "X = df_clean.drop(\"Delivery_Time\", axis=1).astype(float)\n",
176
+ "y = df_clean[\"Delivery_Time\"].astype(float)"
177
+ ],
178
+ "execution_count": null,
179
+ "outputs": []
180
+ },
181
+ {
182
+ "cell_type": "code",
183
+ "metadata": {},
184
+ "source": [
185
+ "# Task 2,3,4,5: Write your code here:\n",
186
+ "import numpy as np\n",
187
+ "from sklearn.ensemble import RandomForestClassifier\n",
188
+ "from sklearn.metrics import classification_report, confusion_matrix, accuracy_score,mean_squared_error as sklearn_mse\n",
189
+ "\n",
190
+ "\n",
191
+ "X_train,X_test,y_train,y_test = train_test_split(X,y,test_size=0.2,random_state=42)\n",
192
+ "print(f\"Train:{X_train.shape}, Test:{X_test.shape}\")\n",
193
+ "print(f\"Legendary in train: {y_train.sum()}, in test: {y_test.sum()}\")\n",
194
+ "\n",
195
+ "model = RandomForestClassifier(n_estimators=100,max_depth=15,class_weight='balanced',\n",
196
+ "random_state=42)\n",
197
+ "model.fit(X_train,y_train)\n",
198
+ "print(\"Model trained!\")\n",
199
+ "y_pred = model.predict(X_test)\n",
200
+ "\n",
201
+ "mse = sklearn_mse(y_test,y_pred)\n",
202
+ "# Evaluate the baseline\n",
203
+ "print(np.sqrt(mse))"
204
+ ],
205
+ "execution_count": null,
206
+ "outputs": []
207
+ },
208
+ {
209
+ "cell_type": "code",
210
+ "metadata": {},
211
+ "source": [
212
+ "# Task 1: Write your code here:\n",
213
+ "\n",
214
+ "plt.figure(figsize=(10,5))\n",
215
+ "plt.hist(df['Traffic_Leve'].dropna(),bins=30,edgecolor='black')\n",
216
+ "plt.title('Traffic_Level')\n",
217
+ "plt.xlabel('Traffic Level')\n",
218
+ "plt.ylabel('time')\n",
219
+ "plt.show()"
220
+ ],
221
+ "execution_count": null,
222
+ "outputs": []
223
+ },
224
+ {
225
+ "cell_type": "code",
226
+ "metadata": {},
227
+ "source": [
228
+ "# Task 2: Write your code here:\n",
229
+ "\n",
230
+ "plt.figure(figsize=(10,5))\n",
231
+ "plt.hist(df_clean['Delivery_Time'].dropna(),bins=30,edgecolor='black')\n",
232
+ "plt.title('delivery time')\n",
233
+ "plt.xlabel('delivery time')\n",
234
+ "plt.ylabel('time')\n",
235
+ "plt.show()"
236
+ ],
237
+ "execution_count": null,
238
+ "outputs": []
239
+ },
240
+ {
241
+ "cell_type": "code",
242
+ "metadata": {},
243
+ "source": [
244
+ "# Task Bonus: Write your code here:"
245
+ ],
246
+ "execution_count": null,
247
+ "outputs": []
248
+ }
249
+ ],
250
+ "metadata": {
251
+ "kernelspec": {
252
+ "display_name": "Python 3",
253
+ "name": "python3"
254
+ },
255
+ "language_info": {
256
+ "name": "python"
257
+ }
258
+ },
259
+ "nbformat": 4,
260
+ "nbformat_minor": 0
261
+ }
submissions_extracted/1005/Q2.ipynb ADDED
@@ -0,0 +1,410 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "metadata": {},
6
+ "source": [
7
+ "import kagglehub\n",
8
+ "\n",
9
+ "# Download latest version\n",
10
+ "path = kagglehub.dataset_download(\"ANON_OWNER/q2-exam-data\")\n",
11
+ "\n",
12
+ "print(\"Path to dataset files:\", path)"
13
+ ],
14
+ "execution_count": null,
15
+ "outputs": []
16
+ },
17
+ {
18
+ "cell_type": "code",
19
+ "metadata": {},
20
+ "source": [
21
+ "import os\n",
22
+ "import pandas as pd\n",
23
+ "import numpy as np\n",
24
+ "from PIL import Image\n",
25
+ "from sklearn.model_selection import train_test_split\n",
26
+ "\n",
27
+ "# Load Labels\n",
28
+ "labels_df = pd.read_csv(os.path.join(path, \"labels.csv\"))\n",
29
+ "img_dir = os.path.join(path, \"images\")\n",
30
+ "\n",
31
+ "images = []\n",
32
+ "ages = []\n",
33
+ "\n",
34
+ "# Load Images and Resize\n",
35
+ "print(\"Loading images...\")\n",
36
+ "for index, row in labels_df.iterrows():\n",
37
+ " img_name = row.iloc[0]\n",
38
+ " age = row.iloc[1]\n",
39
+ " img_path = os.path.join(img_dir, img_name)\n",
40
+ "\n",
41
+ " if os.path.exists(img_path):\n",
42
+ " img = Image.open(img_path).convert('RGB')\n",
43
+ " img_array = np.array(img) / 255.0 # Normalize pixel values to [0, 1]\n",
44
+ " images.append(img_array)\n",
45
+ " ages.append(age)\n",
46
+ "\n",
47
+ "X = np.array(images)\n",
48
+ "y = np.array(ages)\n",
49
+ "\n",
50
+ "# Transpose image dimensions to match PyTorch format (N, C, H, W)\n",
51
+ "X = np.transpose(X, (0, 3, 1, 2))\n",
52
+ "\n",
53
+ "# Split Data\n",
54
+ "X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)\n",
55
+ "\n",
56
+ "print(f\"X_train shape: {X_train.shape}\")\n",
57
+ "print(f\"X_test shape: {X_test.shape}\")\n",
58
+ "print(f\"y_train shape: {y_train.shape}\")\n",
59
+ "print(f\"y_test shape: {y_test.shape}\")"
60
+ ],
61
+ "execution_count": null,
62
+ "outputs": []
63
+ },
64
+ {
65
+ "cell_type": "code",
66
+ "metadata": {},
67
+ "source": [
68
+ "import torch\n",
69
+ "import torch.nn as nn\n",
70
+ "from torch.optim import AdamW\n",
71
+ "from torchvision.datasets import MNIST\n",
72
+ "from torch.optim import Adam\n",
73
+ "from torchvision.transforms.functional import to_tensor\n",
74
+ "import torch.nn.functional as F\n",
75
+ "import matplotlib.pyplot as plt\n",
76
+ "from torch.utils.data import DataLoader, TensorDataset"
77
+ ],
78
+ "execution_count": null,
79
+ "outputs": []
80
+ },
81
+ {
82
+ "cell_type": "code",
83
+ "metadata": {},
84
+ "source": [],
85
+ "execution_count": null,
86
+ "outputs": []
87
+ },
88
+ {
89
+ "cell_type": "code",
90
+ "metadata": {},
91
+ "source": [
92
+ "# 1. Convert Numpy arrays to PyTorch Tensors\n",
93
+ "# Create TensorDatasets for training and testing\n",
94
+ "# transform to tensors\n",
95
+ "X_train = torch.tensor(X_train, dtype=torch.float32)\n",
96
+ "X_test = torch.tensor(X_test, dtype=torch.float32)\n",
97
+ "y_train = torch.tensor(y_train, dtype=torch.float32)\n",
98
+ "y_test = torch.tensor(y_test, dtype=torch.float32)\n",
99
+ "\n",
100
+ "\n",
101
+ "\n"
102
+ ],
103
+ "execution_count": null,
104
+ "outputs": []
105
+ },
106
+ {
107
+ "cell_type": "code",
108
+ "metadata": {},
109
+ "source": [
110
+ "# 2. Create TensorDataset objects\n",
111
+ "\n",
112
+ "train_dataset = TensorDataset(X_train, y_train)\n",
113
+ "test_dataset = TensorDataset(X_test, y_test)\n",
114
+ "\n",
115
+ "\n"
116
+ ],
117
+ "execution_count": null,
118
+ "outputs": []
119
+ },
120
+ {
121
+ "cell_type": "code",
122
+ "metadata": {},
123
+ "source": [
124
+ "# 3. Create DataLoaders\n",
125
+ "# DataLoader for training data\n",
126
+ "train_loader = DataLoader(\n",
127
+ " train_dataset,\n",
128
+ " batch_size=32,\n",
129
+ " shuffle=True,\n",
130
+ " num_workers=2\n",
131
+ ")\n",
132
+ "# DataLoader for test/validation data\n",
133
+ "test_loader = DataLoader(\n",
134
+ " test_dataset,\n",
135
+ " batch_size=32,\n",
136
+ " shuffle=False,\n",
137
+ " num_workers=2\n",
138
+ ")\n"
139
+ ],
140
+ "execution_count": null,
141
+ "outputs": []
142
+ },
143
+ {
144
+ "cell_type": "code",
145
+ "metadata": {},
146
+ "source": [
147
+ "# 4. Print shape of one batch\n",
148
+ "# Get the first batch from the training DataLoader\n",
149
+ "X_batch, y_batch = next(iter(train_loader))\n",
150
+ "print(f\"Training batch input shape: {X_batch.shape}\")\n",
151
+ "print(f\"Training batch labels shape: {y_batch.shape}\")"
152
+ ],
153
+ "execution_count": null,
154
+ "outputs": []
155
+ },
156
+ {
157
+ "cell_type": "code",
158
+ "metadata": {},
159
+ "source": [
160
+ "# 5. Display sample images\n",
161
+ "\n",
162
+ "# Get one batch of images and labels\n",
163
+ "images, labels = next(iter(train_loader))\n",
164
+ "\n",
165
+ "# Display the first 6 images in the batch\n",
166
+ "plt.figure(figsize=(8, 4))\n",
167
+ "\n",
168
+ "for i in range(6):\n",
169
+ " plt.subplot(2, 3, i + 1)\n",
170
+ " img=images[i].permute(1,2,0)\n",
171
+ " plt.imshow(img)\n",
172
+ " plt.title(f\"Label: {labels[i].item()}\")\n",
173
+ " plt.axis('off')\n",
174
+ "\n",
175
+ "plt.tight_layout()\n",
176
+ "plt.show()"
177
+ ],
178
+ "execution_count": null,
179
+ "outputs": []
180
+ },
181
+ {
182
+ "cell_type": "code",
183
+ "metadata": {},
184
+ "source": [
185
+ "# Task 1: Write your model class here:\n",
186
+ "\n",
187
+ "class NN4Layer(nn.Module):\n",
188
+ "\n",
189
+ " def __init__(self, input_dim, hidden_dim, output_dim):\n",
190
+ " super(NN4Layer, self).__init__()\n",
191
+ "\n",
192
+ " # First linear layer: input features -> hidden layer\n",
193
+ " self.layer1 = nn.Linear(input_dim, hidden_dim)\n",
194
+ "\n",
195
+ " # Second linear layer: hidden layer -> hidden layer\n",
196
+ " self.layer2 = nn.Linear(hidden_dim, hidden_dim)\n",
197
+ " # 3 linear layer: hidden layer -> hidden layer\n",
198
+ " self.layer3 = nn.Linear(hidden_dim, hidden_dim)\n",
199
+ "\n",
200
+ "\n",
201
+ " # Output layer: hidden layer -> number of classes (logits)\n",
202
+ " self.layer4 = nn.Linear(hidden_dim, output_dim)\n",
203
+ "\n",
204
+ " # ReLU activation for non-linearity\n",
205
+ " self.relu = nn.ReLU()\n",
206
+ "\n",
207
+ " # Defines how input data flows through the network\n",
208
+ " def forward(self, x):\n",
209
+ " # First hidden layer\n",
210
+ " z1 = self.layer1(x)\n",
211
+ " a1 = self.relu(z1)\n",
212
+ "\n",
213
+ " # Second hidden layer\n",
214
+ " z2 = self.layer2(a1)\n",
215
+ " a2 = self.relu(z2)\n",
216
+ " # Second hidden layer\n",
217
+ " z3 = self.layer2(a2)\n",
218
+ " a3 = self.relu(z3)\n",
219
+ "\n",
220
+ " # Output layer (raw scores / logits)\n",
221
+ " output = self.layer3(a3) # there is something missing here, remember? :)\n",
222
+ "\n",
223
+ " return output\n"
224
+ ],
225
+ "execution_count": null,
226
+ "outputs": []
227
+ },
228
+ {
229
+ "cell_type": "code",
230
+ "metadata": {},
231
+ "source": [
232
+ "def train_one_epoch(model, optimizer, criterion, train_loader, device):\n",
233
+ " # Set the model to training mode\n",
234
+ " model.train()\n",
235
+ "\n",
236
+ " running_loss = 0.0\n",
237
+ "\n",
238
+ " for X_batch, y_batch in train_loader:\n",
239
+ " # Move batch to the selected device ,view(batch.size(0),-1) يخليها ليست\n",
240
+ " X_batch = X_batch.view(X_batch.size(0), -1).to(device)\n",
241
+ " y_batch = y_batch.to(device)\n",
242
+ "\n",
243
+ " # Forward pass\n",
244
+ " outputs = model(X_batch) # shape: (batch_size, 10)\n",
245
+ " loss = criterion(outputs, y_batch)\n",
246
+ "\n",
247
+ " # Backward pass & optimization\n",
248
+ " optimizer.zero_grad() # Clear previous gradients\n",
249
+ " loss.backward() # Compute gradients\n",
250
+ " optimizer.step() # Update model parameters\n",
251
+ "\n",
252
+ " running_loss += loss.item()\n",
253
+ "\n",
254
+ " # Average loss over all batches\n",
255
+ " avg_loss = running_loss / len(train_loader)\n",
256
+ "\n",
257
+ " return avg_loss"
258
+ ],
259
+ "execution_count": null,
260
+ "outputs": []
261
+ },
262
+ {
263
+ "cell_type": "code",
264
+ "metadata": {},
265
+ "source": [
266
+ "# Task 3: Write your validation loop here:\n",
267
+ "def validate(model, criterion, test_loader, device):\n",
268
+ " # Set the model to evaluation mode\n",
269
+ " model.eval()\n",
270
+ "\n",
271
+ " running_loss = 0.0\n",
272
+ " correct = 0\n",
273
+ " total = 0\n",
274
+ "\n",
275
+ " with torch.no_grad():\n",
276
+ " for X_batch, y_batch in test_loader:\n",
277
+ " # Move data to device\n",
278
+ " X_batch = X_batch.view(X_batch.size(0), -1).to(device)\n",
279
+ " y_batch = y_batch.to(device)\n",
280
+ "\n",
281
+ " # Forward pass\n",
282
+ " outputs = model(X_batch) # shape: (batch_size, 10)\n",
283
+ " loss = criterion(outputs, y_batch)\n",
284
+ " running_loss += loss.item()\n",
285
+ "\n",
286
+ " # Apply Softmax to get probabilities\n",
287
+ " probabilities = F.softmax(outputs, dim=1)\n",
288
+ "\n",
289
+ " # Multiclass predictions، هنا ياخد البروبرتي ويختار الاكبر ويضيفها في دمونشين ١\n",
290
+ " predicted = torch.argmax(probabilities, dim=1)\n",
291
+ "\n",
292
+ " # Accuracy calculation\n",
293
+ " correct += (predicted == y_batch).sum().item()\n",
294
+ " total += y_batch.size(0)\n",
295
+ "\n",
296
+ " avg_loss = running_loss / len(test_loader)\n",
297
+ " accuracy = correct / total\n",
298
+ "\n",
299
+ " return avg_loss, accuracy\n"
300
+ ],
301
+ "execution_count": null,
302
+ "outputs": []
303
+ },
304
+ {
305
+ "cell_type": "code",
306
+ "metadata": {},
307
+ "source": [
308
+ "# Task 4: Define device, model, loss, optimizer:\n",
309
+ "# Device setup\n",
310
+ "device = torch.device(\"cuda\" if torch.cuda.is_available() else \"cpu\")\n",
311
+ "\n",
312
+ "# Model parameters\n",
313
+ "input_dim = 3*32 * 32 # MNIST images flattened\n",
314
+ "hidden_dim = 64 # Design choice\n",
315
+ "output_dim = 10\n",
316
+ "# Instantiate model\n",
317
+ "model = NN4Layer(input_dim, hidden_dim, output_dim).to(device)\n",
318
+ "\n",
319
+ "# Print the model architecture\n",
320
+ "print(\"Model Architecture:\\n\")\n",
321
+ "print(model)\n",
322
+ "\n",
323
+ "num_epochs = 20\n",
324
+ "learning_rate = 0.001\n",
325
+ "# Calculate the total number of trainable parameters\n",
326
+ "total_params = sum(p.numel() for p in model.parameters() if p.requires_grad)\n",
327
+ "print(f\"\\nTotal trainable parameters: {total_params}\")\n",
328
+ "\n",
329
+ "# Define criterion (loss function) - using CrossEntropyLoss as model now outputs logits\n",
330
+ "criterion = nn.CrossEntropyLoss()\n",
331
+ "# Define optimizer\n",
332
+ "optimizer = AdamW(model.parameters(), learning_rate)\n"
333
+ ],
334
+ "execution_count": null,
335
+ "outputs": []
336
+ },
337
+ {
338
+ "cell_type": "code",
339
+ "metadata": {},
340
+ "source": [
341
+ "# Task 5: Start training for 20 epochs:\n",
342
+ "\n",
343
+ "\n",
344
+ "train_losses = []\n",
345
+ "val_losses = []\n",
346
+ "val_accuracies = []\n",
347
+ "\n",
348
+ "print('Starting Training...')\n",
349
+ "for epoch in range(num_epochs):\n",
350
+ " # Train one epoch\n",
351
+ " train_loss = train_one_epoch(model, optimizer, criterion, train_loader, device)\n",
352
+ "\n",
353
+ " # Validate\n",
354
+ " val_loss, val_accuracy = validate(model, criterion, test_loader, device)\n",
355
+ "\n",
356
+ " train_losses.append(train_loss)\n",
357
+ " val_losses.append(val_loss)\n",
358
+ " val_accuracies.append(val_accuracy)\n",
359
+ "\n",
360
+ " print(f'Epoch [{epoch+1}/{num_epochs}], Train Loss: {train_loss:.4f}, Val Loss: {val_loss:.4f}, Val Accuracy: {val_accuracy:.4f}')\n",
361
+ "\n",
362
+ "print('Training Complete!')"
363
+ ],
364
+ "execution_count": null,
365
+ "outputs": []
366
+ },
367
+ {
368
+ "cell_type": "code",
369
+ "metadata": {},
370
+ "source": [
371
+ "# Task 1: Write your code here:\n",
372
+ "# Plotting results\n",
373
+ "plt.figure(\n",
374
+ "figsize=(7,5))\n",
375
+ "plt.plot(train_losses,label='Train Loss')\n",
376
+ "plt.plot(val_losses,label='Validation Loss')\n",
377
+ "plt.title('Loss over Epochs')\n",
378
+ "plt.xlabel(\n",
379
+ "'Epoch')\n",
380
+ "plt.ylabel\n",
381
+ "('Loss')\n",
382
+ "plt.legend()\n",
383
+ "plt.tight_layout()\n",
384
+ "plt.show()"
385
+ ],
386
+ "execution_count": null,
387
+ "outputs": []
388
+ },
389
+ {
390
+ "cell_type": "code",
391
+ "metadata": {},
392
+ "source": [
393
+ "# Task 2 (Bonus): Write your code here:\n"
394
+ ],
395
+ "execution_count": null,
396
+ "outputs": []
397
+ }
398
+ ],
399
+ "metadata": {
400
+ "kernelspec": {
401
+ "display_name": "Python 3",
402
+ "name": "python3"
403
+ },
404
+ "language_info": {
405
+ "name": "python"
406
+ }
407
+ },
408
+ "nbformat": 4,
409
+ "nbformat_minor": 0
410
+ }
submissions_extracted/1006/Q1.ipynb ADDED
@@ -0,0 +1,434 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "metadata": {},
6
+ "source": [
7
+ "import kagglehub\n",
8
+ "\n",
9
+ "# Download latest version\n",
10
+ "path = kagglehub.dataset_download(\"ANON_OWNER/q1-exam-data\")\n",
11
+ "\n",
12
+ "print(\"Path to dataset files:\", path)"
13
+ ],
14
+ "execution_count": null,
15
+ "outputs": []
16
+ },
17
+ {
18
+ "cell_type": "code",
19
+ "metadata": {},
20
+ "source": [
21
+ "# Task 1: Write your code here:\n",
22
+ "\n",
23
+ "# Import Required Libraries\n",
24
+ "import numpy as np\n",
25
+ "import pandas as pd\n",
26
+ "import matplotlib.pyplot as plt\n",
27
+ "import kagglehub\n",
28
+ "from sklearn.preprocessing import StandardScaler, LabelEncoder\n",
29
+ "from sklearn.model_selection import KFold\n",
30
+ "from sklearn.linear_model import LinearRegression\n",
31
+ "from sklearn.metrics import mean_squared_error, mean_absolute_error\n",
32
+ "\n",
33
+ "\n",
34
+ "# Download dataset from Kaggle\n",
35
+ "path = kagglehub.dataset_download(\"ANON_OWNER/q1-exam-data\")\n",
36
+ "\n",
37
+ "# Load CSV file\n",
38
+ "df = pd.read_csv(f\"{path}/Q1_data.csv\")\n"
39
+ ],
40
+ "execution_count": null,
41
+ "outputs": []
42
+ },
43
+ {
44
+ "cell_type": "code",
45
+ "metadata": {},
46
+ "source": [
47
+ "# Task 2: Write your code here:\n",
48
+ "df.head()"
49
+ ],
50
+ "execution_count": null,
51
+ "outputs": []
52
+ },
53
+ {
54
+ "cell_type": "code",
55
+ "metadata": {},
56
+ "source": [
57
+ "# Task 3: Write your code here:\n",
58
+ "df.info()"
59
+ ],
60
+ "execution_count": null,
61
+ "outputs": []
62
+ },
63
+ {
64
+ "cell_type": "code",
65
+ "metadata": {},
66
+ "source": [
67
+ "# Task 4: Write your code here:\n",
68
+ "df.describe()"
69
+ ],
70
+ "execution_count": null,
71
+ "outputs": []
72
+ },
73
+ {
74
+ "cell_type": "code",
75
+ "metadata": {},
76
+ "source": [
77
+ "# Task 5: Write your code here:\n",
78
+ "# 1. What does our target variable (charges) look like?\n",
79
+ "def check_target_distribution(df, target_column):\n",
80
+ " df[target_column].hist(bins=30, edgecolor='black')\n",
81
+ "\n",
82
+ " plt.title(f\"Target Distribution ({target_column})\")\n",
83
+ " plt.xlabel(target_column)\n",
84
+ " plt.ylabel(\"Frequency\")\n",
85
+ " plt.grid(False)\n",
86
+ "\n",
87
+ " plt.show()\n",
88
+ "\n",
89
+ "check_target_distribution(df, \"Delivery_Time\")"
90
+ ],
91
+ "execution_count": null,
92
+ "outputs": []
93
+ },
94
+ {
95
+ "cell_type": "code",
96
+ "metadata": {},
97
+ "source": [
98
+ "# Task 1: Write your code here:\n",
99
+ "df.drop(columns=['Order_ID'])"
100
+ ],
101
+ "execution_count": null,
102
+ "outputs": []
103
+ },
104
+ {
105
+ "cell_type": "code",
106
+ "metadata": {},
107
+ "source": [
108
+ "# Task 2: Write your code here:\n",
109
+ "def check_missing_values(df):\n",
110
+ " missing_values = df.isnull().sum()\n",
111
+ " print(\"Missing Values per Column:\")\n",
112
+ " print(missing_values[missing_values > 0])\n",
113
+ " if missing_values.any():\n",
114
+ " print(\"\\nHandle Missing Values as needed.\")\n",
115
+ " else:\n",
116
+ " print(\"\\nNo Missing Values Found.\")\n",
117
+ "\n",
118
+ "check_missing_values(df)\n",
119
+ "\n",
120
+ "\n",
121
+ "####df.isnull().sum()"
122
+ ],
123
+ "execution_count": null,
124
+ "outputs": []
125
+ },
126
+ {
127
+ "cell_type": "code",
128
+ "metadata": {},
129
+ "source": [
130
+ "# Task 3: Write your code here:\n",
131
+ "def check_duplicates(df):\n",
132
+ " duplicates = df.duplicated().sum()\n",
133
+ " print(f\"Number of Duplicate Samples: {duplicates}\")\n",
134
+ " if duplicates > 0:\n",
135
+ " print(\"Dropping Duplicates...\")\n",
136
+ " df.drop_duplicates(inplace=True)\n",
137
+ " print(\"Duplicates Dropped.\")\n",
138
+ " else:\n",
139
+ " print(\"No Duplicate Samples Found.\")\n",
140
+ "\n",
141
+ "check_duplicates(df)"
142
+ ],
143
+ "execution_count": null,
144
+ "outputs": []
145
+ },
146
+ {
147
+ "cell_type": "code",
148
+ "metadata": {},
149
+ "source": [
150
+ "# Task 4: Write your code here:\n",
151
+ "from sklearn.preprocessing import LabelEncoder\n",
152
+ "\n",
153
+ "# 3. Do we have categorical columns?\n",
154
+ "categorical_cols = df.select_dtypes(include=[\"object\"]).columns\n",
155
+ "\n",
156
+ "print(\"Categorical Columns:\", list(categorical_cols))\n",
157
+ "\n",
158
+ "label_encoders = {}\n",
159
+ "for col in categorical_cols:\n",
160
+ " le = LabelEncoder()\n",
161
+ " df[col] = le.fit_transform(df[col])\n",
162
+ " label_encoders[col] = le\n",
163
+ "\n",
164
+ "df\n",
165
+ "\n",
166
+ "###### THE ONE-HOTENCODER USED DOWN ######"
167
+ ],
168
+ "execution_count": null,
169
+ "outputs": []
170
+ },
171
+ {
172
+ "cell_type": "code",
173
+ "metadata": {},
174
+ "source": [
175
+ "def one_hot_encode(y, num_classes):\n",
176
+ " y = np.array(y)\n",
177
+ " m = len(y)\n",
178
+ " # 1. Create a grid of all zeros (num_samples, num_classes)\n",
179
+ " one_hot = np.zeros((m, num_classes))\n",
180
+ "\n",
181
+ " # 2. Go through each sample one by one\n",
182
+ " for i in range(m):\n",
183
+ " # Identify which class this sample belongs to\n",
184
+ " class_label = int(y[i])\n",
185
+ "\n",
186
+ " # In this row (i), set the specific class column to 1\n",
187
+ " one_hot[i, class_label] = 1\n",
188
+ "\n",
189
+ " return one_hot"
190
+ ],
191
+ "execution_count": null,
192
+ "outputs": []
193
+ },
194
+ {
195
+ "cell_type": "code",
196
+ "metadata": {},
197
+ "source": [
198
+ "# Task 5: Write your code here:\n",
199
+ "\n",
200
+ "from sklearn.preprocessing import StandardScaler\n",
201
+ "\n",
202
+ "# Pick only the numerical columns, NOT the target\n",
203
+ "numerical_cols = df.select_dtypes(include=[\"number\"]).columns.drop(\"Delivery_Time\")\n",
204
+ "\n",
205
+ "scaler = StandardScaler()\n",
206
+ "\n",
207
+ "# scale the `numerical_cols`\n",
208
+ "df[numerical_cols] = scaler.fit_transform(df[numerical_cols])\n",
209
+ "\n",
210
+ "df.head()"
211
+ ],
212
+ "execution_count": null,
213
+ "outputs": []
214
+ },
215
+ {
216
+ "cell_type": "code",
217
+ "metadata": {},
218
+ "source": [
219
+ "# Task 6: Write your code here:\n",
220
+ "\n",
221
+ "def check_target_imbalance(df, target_column):\n",
222
+ " print(\"Target Distribution:\")\n",
223
+ "\n",
224
+ " df[target_column].hist() # Yeah you can just do this :)\n",
225
+ " plt.show()\n",
226
+ "\n",
227
+ "check_target_imbalance(df, \"Delivery_Time\")"
228
+ ],
229
+ "execution_count": null,
230
+ "outputs": []
231
+ },
232
+ {
233
+ "cell_type": "code",
234
+ "metadata": {},
235
+ "source": [
236
+ "# Task 1: Write your code here:\n",
237
+ "X = df.drop(\"Delivery_Time\", axis=1).astype(float)\n",
238
+ "y = df['Delivery_Time'].astype(float)"
239
+ ],
240
+ "execution_count": null,
241
+ "outputs": []
242
+ },
243
+ {
244
+ "cell_type": "code",
245
+ "metadata": {},
246
+ "source": [
247
+ "# Task 2,3,4,5: Write your code here:\n",
248
+ "from sklearn.ensemble import RandomForestRegressor\n",
249
+ "from sklearn.metrics import mean_absolute_error, mean_squared_error\n",
250
+ "\n",
251
+ "import warnings\n",
252
+ "warnings.filterwarnings('ignore')\n",
253
+ "\n",
254
+ "from sklearn.model_selection import KFold\n",
255
+ "\n",
256
+ "# Use previously generated random data (example: regression data)\n",
257
+ "X, y = X.copy(), y.copy()\n",
258
+ "\n",
259
+ "# Define K-Fold Cross Validation\n",
260
+ "kf = KFold(n_splits=5, shuffle=True, random_state=42)\n",
261
+ "\n",
262
+ "# Iterate through folds\n",
263
+ "for fold, (train_idx, test_idx) in enumerate(kf.split(X), start=1):\n",
264
+ " # indexing for each fold\n",
265
+ " X_train, X_test = X.iloc[train_idx], X.iloc[test_idx]\n",
266
+ " y_train, y_test = y.iloc[train_idx], y.iloc[test_idx]\n",
267
+ " # print shapes\n",
268
+ " print(f\"Fold {fold}\")\n",
269
+ " print(\" X_train shape:\", X_train.shape)\n",
270
+ " print(\" X_test shape :\", X_test.shape)\n",
271
+ " print(\" y_train shape:\", y_train.shape)\n",
272
+ " print(\" y_test shape :\", y_test.shape)\n",
273
+ " print(\"-\" * 30)\n",
274
+ "\n",
275
+ "# Train Random Forest Regressor\n",
276
+ "model = RandomForestRegressor(n_estimators=100, max_depth=20, random_state=42, n_jobs=-1)\n",
277
+ "model.fit(X_train, y_train)\n",
278
+ "print(\"Model trained!\")\n",
279
+ "\n",
280
+ "# Predict and evaluate\n",
281
+ "y_pred = model.predict(X_test_scaled)\n",
282
+ "\n",
283
+ "mae = mean_absolute_error(y_test, y_pred)\n",
284
+ "rmse = np.sqrt(mean_squared_error(y_test, y_pred))\n",
285
+ "\n",
286
+ "print(f\"MAE: ${mae:,.2f}\")\n",
287
+ "print(f\"RMSE: ${rmse:,.2f}\")\n",
288
+ "\n",
289
+ "# Feature importance\n",
290
+ "feature_importance = pd.DataFrame({\n",
291
+ " 'feature': feature_cols,\n",
292
+ " 'importance': model.feature_importances_\n",
293
+ "}).sort_values('importance', ascending=False)\n",
294
+ "\n",
295
+ "plt.figure(figsize=(10, 6))\n",
296
+ "plt.barh(feature_importance['feature'], feature_importance['importance'])\n",
297
+ "plt.xlabel('Importance')\n",
298
+ "plt.title('Feature Importance')\n",
299
+ "plt.gca().invert_yaxis()\n",
300
+ "plt.show()"
301
+ ],
302
+ "execution_count": null,
303
+ "outputs": []
304
+ },
305
+ {
306
+ "cell_type": "code",
307
+ "metadata": {},
308
+ "source": [
309
+ "# Task 1: Write your code here:\n",
310
+ "def check_target_imbalance(df, target_column):\n",
311
+ " print(\"Target Distribution:\")\n",
312
+ "\n",
313
+ " df[target_column].hist() # Yeah you can just do this :)\n",
314
+ " plt.show()\n",
315
+ "\n",
316
+ "check_target_imbalance(df, \"Delivery_Time\")"
317
+ ],
318
+ "execution_count": null,
319
+ "outputs": []
320
+ },
321
+ {
322
+ "cell_type": "code",
323
+ "metadata": {},
324
+ "source": [
325
+ "# Task 2: Write your code here:\n",
326
+ "def check_target_imbalance(df, target_column):\n",
327
+ " print(\"Target Distribution:\")\n",
328
+ "\n",
329
+ " df[target_column].hist() # Yeah you can just do this :)\n",
330
+ " plt.show()\n"
331
+ ],
332
+ "execution_count": null,
333
+ "outputs": []
334
+ },
335
+ {
336
+ "cell_type": "code",
337
+ "metadata": {},
338
+ "source": [
339
+ "# Task Bonus: Write your code here:\n",
340
+ "# Task Bonus: Write your code here:\n",
341
+ "# Import models\n",
342
+ "from sklearn.linear_model import LogisticRegression\n",
343
+ "from sklearn.neighbors import KNeighborsClassifier\n",
344
+ "from sklearn.svm import SVC\n",
345
+ "from sklearn.tree import DecisionTreeClassifier\n",
346
+ "from sklearn.ensemble import RandomForestClassifier\n",
347
+ "from xgboost import XGBClassifier\n",
348
+ "from catboost import CatBoostClassifier\n",
349
+ "\n",
350
+ "# TODO: Define models with hyperparameters of your choice\n",
351
+ "models = {\n",
352
+ " \"LR\": LogisticRegression(\n",
353
+ " max_iter=1000\n",
354
+ " ),\n",
355
+ " \"KNN\": KNeighborsClassifier(\n",
356
+ " n_neighbors=3,\n",
357
+ " ),\n",
358
+ " \"SVM\": SVC(\n",
359
+ " kernel='rbf',\n",
360
+ " C=1.0\n",
361
+ " ),\n",
362
+ " \"Decision Tree\": DecisionTreeClassifier(\n",
363
+ " max_depth=16\n",
364
+ " ),\n",
365
+ " \"Random Forest\": RandomForestClassifier(\n",
366
+ " n_estimators=200,\n",
367
+ " max_depth=10\n",
368
+ " ),\n",
369
+ " \"XGBoost\": XGBClassifier(\n",
370
+ " verbosity=0,\n",
371
+ " n_estimators=280,\n",
372
+ " max_depth=10,\n",
373
+ " ),\n",
374
+ " \"CatBoost\": CatBoostClassifier(\n",
375
+ " verbose=0,\n",
376
+ " n_estimators=200,\n",
377
+ " max_depth=4\n",
378
+ " )\n",
379
+ "}\n",
380
+ "\n",
381
+ "\n",
382
+ "\n",
383
+ "results = {}\n",
384
+ "\n",
385
+ "for model_name in models:\n",
386
+ " results[model_name] = {'accuracy': [], 'precision': [], 'recall': [], 'f1': []}\n",
387
+ "\n",
388
+ " for fold_idx, (train_index, test_index) in enumerate(skf.split(X, y)):\n",
389
+ " print(f\"\\nFold {fold_idx + 1}/{n_splits}\")\n",
390
+ "\n",
391
+ " # Get the train & test split for this fold\n",
392
+ " X_train, X_test = X.iloc[train_index], X.iloc[test_index]\n",
393
+ " y_train, y_test = y.iloc[train_index], y.iloc[test_index]\n",
394
+ "\n",
395
+ " # Train & Validate Models\n",
396
+ " for model_name, model in models.items():\n",
397
+ "\n",
398
+ " print(f\"Training {model_name}...\")\n",
399
+ "\n",
400
+ " # Fit the model on train data\n",
401
+ " model.fit(X_train, y_train)\n",
402
+ "\n",
403
+ " # Use the model to predict the test data\n",
404
+ " y_pred = model.predict(X_test)\n",
405
+ "\n",
406
+ " # Calculate evaluation metrics\n",
407
+ " accuracy = accuracy_score(y_test, y_pred)\n",
408
+ " f1 = f1_score(y_test, y_pred, average='macro') # for multiclass f1 score, you should set the average hyperparameter (\"macro\", \"micro\", \"weighted\")\n",
409
+ "\n",
410
+ " results[model_name]['accuracy'].append(accuracy)\n",
411
+ " results[model_name]['f1'].append(f1)\n",
412
+ "\n",
413
+ " for model_name in results:\n",
414
+ " print(f\"\\n{model_name}:\")\n",
415
+ " # Print the average of each evaluation metric across folds\n",
416
+ " print(f\" Accuracy: {np.mean(results[model_name]['accuracy']):.4f}\")\n",
417
+ " print(f\" F1-Score: {np.mean(results[model_name]['f1']):.4f}\")"
418
+ ],
419
+ "execution_count": null,
420
+ "outputs": []
421
+ }
422
+ ],
423
+ "metadata": {
424
+ "kernelspec": {
425
+ "display_name": "Python 3",
426
+ "name": "python3"
427
+ },
428
+ "language_info": {
429
+ "name": "python"
430
+ }
431
+ },
432
+ "nbformat": 4,
433
+ "nbformat_minor": 0
434
+ }
submissions_extracted/1006/Q2.ipynb ADDED
@@ -0,0 +1,204 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "metadata": {},
6
+ "source": [
7
+ "import kagglehub\n",
8
+ "\n",
9
+ "# Download latest version\n",
10
+ "path = kagglehub.dataset_download(\"ANON_OWNER/q2-exam-data\")\n",
11
+ "\n",
12
+ "print(\"Path to dataset files:\", path)"
13
+ ],
14
+ "execution_count": null,
15
+ "outputs": []
16
+ },
17
+ {
18
+ "cell_type": "code",
19
+ "metadata": {},
20
+ "source": [
21
+ "import os\n",
22
+ "import pandas as pd\n",
23
+ "import numpy as np\n",
24
+ "from PIL import Image\n",
25
+ "from sklearn.model_selection import train_test_split\n",
26
+ "\n",
27
+ "# Load Labels\n",
28
+ "labels_df = pd.read_csv(os.path.join(path, \"labels.csv\"))\n",
29
+ "img_dir = os.path.join(path, \"images\")\n",
30
+ "\n",
31
+ "images = []\n",
32
+ "ages = []\n",
33
+ "\n",
34
+ "# Load Images and Resize\n",
35
+ "print(\"Loading images...\")\n",
36
+ "for index, row in labels_df.iterrows():\n",
37
+ " img_name = row.iloc[0]\n",
38
+ " age = row.iloc[1]\n",
39
+ " img_path = os.path.join(img_dir, img_name)\n",
40
+ "\n",
41
+ " if os.path.exists(img_path):\n",
42
+ " img = Image.open(img_path).convert('RGB')\n",
43
+ " img_array = np.array(img) / 255.0 # Normalize pixel values to [0, 1]\n",
44
+ " images.append(img_array)\n",
45
+ " ages.append(age)\n",
46
+ "\n",
47
+ "X = np.array(images)\n",
48
+ "y = np.array(ages)\n",
49
+ "\n",
50
+ "# Transpose image dimensions to match PyTorch format (N, C, H, W)\n",
51
+ "X = np.transpose(X, (0, 3, 1, 2))\n",
52
+ "\n",
53
+ "# Split Data\n",
54
+ "X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)\n",
55
+ "\n",
56
+ "print(f\"X_train shape: {X_train.shape}\")\n",
57
+ "print(f\"X_test shape: {X_test.shape}\")\n",
58
+ "print(f\"y_train shape: {y_train.shape}\")\n",
59
+ "print(f\"y_test shape: {y_test.shape}\")"
60
+ ],
61
+ "execution_count": null,
62
+ "outputs": []
63
+ },
64
+ {
65
+ "cell_type": "code",
66
+ "metadata": {},
67
+ "source": [
68
+ "# 1. Convert Numpy arrays to PyTorch Tensors\n",
69
+ "\n",
70
+ "# split features from targets\n",
71
+ "X = df.drop(\"Weather Type\",axis=1) ## يعتمد هلى الراتا حقتي وش الليبل وش التارقيت\n",
72
+ "y = df['Weather Type']\n",
73
+ "\n",
74
+ "# Split the dataset into training and testing sets\n",
75
+ "X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42, stratify=y)\n",
76
+ "\n",
77
+ "# transform to tensorsA\n",
78
+ "X_train = torch.tensor(X_train.values, dtype=torch.float32)\n",
79
+ "X_test = torch.tensor(X_test.values, dtype=torch.float32)\n",
80
+ "y_train = torch.tensor(y_train.values, dtype=torch.long)\n",
81
+ "y_test = torch.tensor(y_test.values, dtype=torch.long)\n",
82
+ "\n"
83
+ ],
84
+ "execution_count": null,
85
+ "outputs": []
86
+ },
87
+ {
88
+ "cell_type": "code",
89
+ "metadata": {},
90
+ "source": [
91
+ "# 2. Create TensorDataset objects\n",
92
+ "\n",
93
+ "\n"
94
+ ],
95
+ "execution_count": null,
96
+ "outputs": []
97
+ },
98
+ {
99
+ "cell_type": "code",
100
+ "metadata": {},
101
+ "source": [
102
+ "# 3. Create DataLoaders\n",
103
+ "\n",
104
+ "\n"
105
+ ],
106
+ "execution_count": null,
107
+ "outputs": []
108
+ },
109
+ {
110
+ "cell_type": "code",
111
+ "metadata": {},
112
+ "source": [
113
+ "# 4. Print shape of one batch\n",
114
+ "\n"
115
+ ],
116
+ "execution_count": null,
117
+ "outputs": []
118
+ },
119
+ {
120
+ "cell_type": "code",
121
+ "metadata": {},
122
+ "source": [
123
+ "# 5. Display sample images\n",
124
+ "\n"
125
+ ],
126
+ "execution_count": null,
127
+ "outputs": []
128
+ },
129
+ {
130
+ "cell_type": "code",
131
+ "metadata": {},
132
+ "source": [
133
+ "# Task 1: Write your model class here:"
134
+ ],
135
+ "execution_count": null,
136
+ "outputs": []
137
+ },
138
+ {
139
+ "cell_type": "code",
140
+ "metadata": {},
141
+ "source": [
142
+ "# Task 2: Write your training loop here:"
143
+ ],
144
+ "execution_count": null,
145
+ "outputs": []
146
+ },
147
+ {
148
+ "cell_type": "code",
149
+ "metadata": {},
150
+ "source": [
151
+ "# Task 3: Write your validation loop here:"
152
+ ],
153
+ "execution_count": null,
154
+ "outputs": []
155
+ },
156
+ {
157
+ "cell_type": "code",
158
+ "metadata": {},
159
+ "source": [
160
+ "# Task 4: Define device, model, loss, optimizer:"
161
+ ],
162
+ "execution_count": null,
163
+ "outputs": []
164
+ },
165
+ {
166
+ "cell_type": "code",
167
+ "metadata": {},
168
+ "source": [
169
+ "# Task 5: Start training for 20 epochs:"
170
+ ],
171
+ "execution_count": null,
172
+ "outputs": []
173
+ },
174
+ {
175
+ "cell_type": "code",
176
+ "metadata": {},
177
+ "source": [
178
+ "# Task 1: Write your code here:"
179
+ ],
180
+ "execution_count": null,
181
+ "outputs": []
182
+ },
183
+ {
184
+ "cell_type": "code",
185
+ "metadata": {},
186
+ "source": [
187
+ "# Task 2 (Bonus): Write your code here:"
188
+ ],
189
+ "execution_count": null,
190
+ "outputs": []
191
+ }
192
+ ],
193
+ "metadata": {
194
+ "kernelspec": {
195
+ "display_name": "Python 3",
196
+ "name": "python3"
197
+ },
198
+ "language_info": {
199
+ "name": "python"
200
+ }
201
+ },
202
+ "nbformat": 4,
203
+ "nbformat_minor": 0
204
+ }
submissions_extracted/1006/Q3.ipynb ADDED
@@ -0,0 +1,321 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "metadata": {},
6
+ "source": [
7
+ "import kagglehub\n",
8
+ "\n",
9
+ "\n",
10
+ "\n",
11
+ "# Download latest version\n",
12
+ "\n",
13
+ "path = kagglehub.dataset_download(\"ANON_OWNER/q3-exam-data\")\n",
14
+ "\n",
15
+ "\n",
16
+ "\n",
17
+ "print(\"Path to dataset files:\", path)"
18
+ ],
19
+ "execution_count": null,
20
+ "outputs": []
21
+ },
22
+ {
23
+ "cell_type": "code",
24
+ "metadata": {},
25
+ "source": [
26
+ "# Task 1: Write your code here:\n",
27
+ "\n",
28
+ "# Import Required Libraries\n",
29
+ "import numpy as np\n",
30
+ "import pandas as pd\n",
31
+ "import matplotlib.pyplot as plt\n",
32
+ "import kagglehub\n",
33
+ "from sklearn.preprocessing import StandardScaler, LabelEncoder\n",
34
+ "from sklearn.model_selection import KFold\n",
35
+ "from sklearn.linear_model import LinearRegression\n",
36
+ "from sklearn.metrics import mean_squared_error, mean_absolute_error\n",
37
+ "\n",
38
+ "\n",
39
+ "# Download dataset from Kaggle\n",
40
+ "path = kagglehub.dataset_download(\"ANON_OWNER/q3-exam-data\")\n",
41
+ "\n",
42
+ "# Load CSV file\n",
43
+ "df = pd.read_csv(f\"{path}/Q3_data.csv\")"
44
+ ],
45
+ "execution_count": null,
46
+ "outputs": []
47
+ },
48
+ {
49
+ "cell_type": "code",
50
+ "metadata": {},
51
+ "source": [
52
+ "# Task 2: Write your code here:\n",
53
+ "df.head()"
54
+ ],
55
+ "execution_count": null,
56
+ "outputs": []
57
+ },
58
+ {
59
+ "cell_type": "code",
60
+ "metadata": {},
61
+ "source": [
62
+ "# Task 3: Write your code here:\n",
63
+ "df.info()"
64
+ ],
65
+ "execution_count": null,
66
+ "outputs": []
67
+ },
68
+ {
69
+ "cell_type": "code",
70
+ "metadata": {},
71
+ "source": [
72
+ "# Task 4: Write your code here:\n",
73
+ "df.describe()"
74
+ ],
75
+ "execution_count": null,
76
+ "outputs": []
77
+ },
78
+ {
79
+ "cell_type": "code",
80
+ "metadata": {},
81
+ "source": [
82
+ "# Task 1: Write your code here:\n",
83
+ "\n",
84
+ "def check_missing_values(df):\n",
85
+ " missing_values = df.isnull().sum()\n",
86
+ " print(\"Missing Values per Column:\")\n",
87
+ " print(missing_values[missing_values > 0])\n",
88
+ " if missing_values.any():\n",
89
+ " print(\"\\nHandle Missing Values as needed.\")\n",
90
+ " else:\n",
91
+ " print(\"\\nNo Missing Values Found.\")\n",
92
+ "\n",
93
+ "check_missing_values(df)\n",
94
+ "\n",
95
+ "\n",
96
+ "####df.isnull().sum()"
97
+ ],
98
+ "execution_count": null,
99
+ "outputs": []
100
+ },
101
+ {
102
+ "cell_type": "code",
103
+ "metadata": {},
104
+ "source": [
105
+ "# Task 2: Write your code here:\n",
106
+ "\n",
107
+ "def check_duplicates(df):\n",
108
+ " duplicates = df.duplicated().sum()\n",
109
+ " print(f\"Number of Duplicate Samples: {duplicates}\")\n",
110
+ " if duplicates > 0:\n",
111
+ " print(\"Dropping Duplicates...\")\n",
112
+ " df.drop_duplicates(inplace=True)\n",
113
+ " print(\"Duplicates Dropped.\")\n",
114
+ " else:\n",
115
+ " print(\"No Duplicate Samples Found.\")\n",
116
+ "\n",
117
+ "check_duplicates(df)"
118
+ ],
119
+ "execution_count": null,
120
+ "outputs": []
121
+ },
122
+ {
123
+ "cell_type": "code",
124
+ "metadata": {},
125
+ "source": [
126
+ "# Task 3: Write your code here:\n",
127
+ "\n",
128
+ "from sklearn.preprocessing import LabelEncoder\n",
129
+ "\n",
130
+ "# 3. Do we have categorical columns?\n",
131
+ "categorical_cols = df.select_dtypes(include=[\"object\"]).columns\n",
132
+ "\n",
133
+ "print(\"Categorical Columns:\", list(categorical_cols))\n",
134
+ "\n",
135
+ "label_encoders = {}\n",
136
+ "for col in categorical_cols:\n",
137
+ " le = LabelEncoder()\n",
138
+ " df[col] = le.fit_transform(df[col])\n",
139
+ " label_encoders[col] = le\n",
140
+ "\n",
141
+ "df"
142
+ ],
143
+ "execution_count": null,
144
+ "outputs": []
145
+ },
146
+ {
147
+ "cell_type": "code",
148
+ "metadata": {},
149
+ "source": [
150
+ "# Task 4: Write your code here:\n",
151
+ "\n",
152
+ "from sklearn.preprocessing import StandardScaler\n",
153
+ "\n",
154
+ "# Pick only the numerical columns, NOT the target\n",
155
+ "numerical_cols = df.select_dtypes(include=[\"number\"])\n",
156
+ "\n",
157
+ "scaler = StandardScaler()\n",
158
+ "\n",
159
+ "# scale the `numerical_cols`\n",
160
+ "df[numerical_cols] = scaler.fit_transform(df[numerical_cols])\n",
161
+ "\n",
162
+ "df.head()"
163
+ ],
164
+ "execution_count": null,
165
+ "outputs": []
166
+ },
167
+ {
168
+ "cell_type": "code",
169
+ "metadata": {},
170
+ "source": [
171
+ "# Task 5: Write your code here:\n",
172
+ "\n",
173
+ "def check_target_imbalance(df, target_column):\n",
174
+ " print(\"Target Distribution:\")\n",
175
+ "\n",
176
+ " df[target_column].hist() # Yeah you can just do this :)\n",
177
+ " plt.show()\n",
178
+ "\n",
179
+ "check_target_imbalance(df, \"D_1\")"
180
+ ],
181
+ "execution_count": null,
182
+ "outputs": []
183
+ },
184
+ {
185
+ "cell_type": "code",
186
+ "metadata": {},
187
+ "source": [
188
+ "# Task 1: Write your code here:\n",
189
+ "# Task 1: Write your code here:\n",
190
+ "X = df.drop(\"\", axis=1).astype(float)\n",
191
+ "y = df[''].astype(float)"
192
+ ],
193
+ "execution_count": null,
194
+ "outputs": []
195
+ },
196
+ {
197
+ "cell_type": "code",
198
+ "metadata": {},
199
+ "source": [
200
+ "# Task 2,3,4,5: Write your code here:\n",
201
+ "\n",
202
+ "\n",
203
+ "import warnings\n",
204
+ "warnings.filterwarnings('ignore')\n",
205
+ "\n",
206
+ "from sklearn.model_selection import KFold\n",
207
+ "\n",
208
+ "# Use previously generated random data (example: regression data)\n",
209
+ "X, y = X.copy(), y.copy()\n",
210
+ "\n",
211
+ "# Define K-Fold Cross Validation\n",
212
+ "kf = KFold(n_splits=5, shuffle=True, random_state=42)\n",
213
+ "\n",
214
+ "# Iterate through folds\n",
215
+ "for fold, (train_idx, test_idx) in enumerate(kf.split(X), start=1):\n",
216
+ " # indexing for each fold\n",
217
+ " X_train, X_test = X.iloc[train_idx], X.iloc[test_idx]\n",
218
+ " y_train, y_test = y.iloc[train_idx], y.iloc[test_idx]\n",
219
+ " # print shapes\n",
220
+ " print(f\"Fold {fold}\")\n",
221
+ " print(\" X_train shape:\", X_train.shape)\n",
222
+ " print(\" X_test shape :\", X_test.shape)\n",
223
+ " print(\" y_train shape:\", y_train.shape)\n",
224
+ " print(\" y_test shape :\", y_test.shape)\n",
225
+ " print(\"-\" * 30)\n",
226
+ "\n",
227
+ "# Train Random Forest Regressor\n",
228
+ "model = CatBoostClassifier()\n",
229
+ "model.fit(X_train, y_train)\n",
230
+ "print(\"Model trained!\")\n",
231
+ "\n",
232
+ "# Predict and evaluate\n",
233
+ "y_pred = model.predict(X_test_scaled)\n",
234
+ "\n",
235
+ "print(\"Evaluating models on the test set...\")\n",
236
+ "\n",
237
+ "# Dictionary to store performance metrics\n",
238
+ "model_performance = {}\n",
239
+ "\n",
240
+ "# Iterate through each trained model\n",
241
+ "for model_name, model in models.items():\n",
242
+ " print(f\"\\nEvaluating {model_name}...\")\n",
243
+ "\n",
244
+ " # Make predictions on the test set (hard labels)\n",
245
+ " y_pred = model.predict(X_test)\n",
246
+ "\n",
247
+ " # Calculate evaluation metrics\n",
248
+ " accuracy = accuracy_score(y_test, y_pred)\n",
249
+ " precision = precision_score(y_test, y_pred, average='weighted', zero_division=0)\n",
250
+ " recall = recall_score(y_test, y_pred, average='weighted', zero_division=0)\n",
251
+ " f1 = f1_score(y_test, y_pred, average='weighted', zero_division=0)\n",
252
+ "\n",
253
+ " # Store metrics\n",
254
+ " model_performance[model_name] = {\n",
255
+ " 'Accuracy': accuracy,\n",
256
+ " 'Precision': precision,\n",
257
+ " 'Recall': recall,\n",
258
+ " 'F1-Score': f1\n",
259
+ " }\n",
260
+ "\n",
261
+ " # Print metrics\n",
262
+ " print(f\" Accuracy: {accuracy:.4f}\")\n",
263
+ " print(f\" Precision: {precision:.4f}\")\n",
264
+ " print(f\" Recall: {recall:.4f}\")\n",
265
+ " print(f\" F1-Score: {f1:.4f}\")\n",
266
+ "\n",
267
+ " # Generate and visualize Confusion Matrix\n",
268
+ " cm = confusion_matrix(y_test, y_pred)\n",
269
+ " plt.figure(figsize=(6, 5))\n",
270
+ " sns.heatmap(cm, annot=True, fmt='d', cmap='Blues', cbar=False,\n",
271
+ " xticklabels=label_encoder.classes_, yticklabels=label_encoder.classes_)\n",
272
+ " plt.title(f'Confusion Matrix for {model_name}')\n",
273
+ " plt.xlabel('Predicted Label')\n",
274
+ " plt.ylabel('True Label')\n",
275
+ " plt.show()\n",
276
+ "\n",
277
+ "print(\"\\nAll models evaluated.\")"
278
+ ],
279
+ "execution_count": null,
280
+ "outputs": []
281
+ },
282
+ {
283
+ "cell_type": "code",
284
+ "metadata": {},
285
+ "source": [
286
+ "# Task 1: Write your code here:"
287
+ ],
288
+ "execution_count": null,
289
+ "outputs": []
290
+ },
291
+ {
292
+ "cell_type": "code",
293
+ "metadata": {},
294
+ "source": [
295
+ "# Task 2: Write your code here:"
296
+ ],
297
+ "execution_count": null,
298
+ "outputs": []
299
+ },
300
+ {
301
+ "cell_type": "code",
302
+ "metadata": {},
303
+ "source": [
304
+ "# Task Bonus: Write your code here:"
305
+ ],
306
+ "execution_count": null,
307
+ "outputs": []
308
+ }
309
+ ],
310
+ "metadata": {
311
+ "kernelspec": {
312
+ "display_name": "Python 3",
313
+ "name": "python3"
314
+ },
315
+ "language_info": {
316
+ "name": "python"
317
+ }
318
+ },
319
+ "nbformat": 4,
320
+ "nbformat_minor": 0
321
+ }
submissions_extracted/1007/Q1.ipynb ADDED
@@ -0,0 +1,399 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "metadata": {},
6
+ "source": [
7
+ "import kagglehub\n",
8
+ "\n",
9
+ "# Download latest version\n",
10
+ "path = kagglehub.dataset_download(\"ANON_OWNER/q1-exam-data\")\n",
11
+ "\n",
12
+ "print(\"Path to dataset files:\", path)"
13
+ ],
14
+ "execution_count": null,
15
+ "outputs": []
16
+ },
17
+ {
18
+ "cell_type": "code",
19
+ "metadata": {},
20
+ "source": [
21
+ "# Task 1: Write your code here:\n",
22
+ "import numpy as np\n",
23
+ "import pandas as pd\n",
24
+ "import matplotlib.pyplot as plt\n",
25
+ "import os\n",
26
+ "import kagglehub\n",
27
+ "\n",
28
+ "from sklearn.model_selection import train_test_split, KFold\n",
29
+ "from sklearn.preprocessing import StandardScaler, LabelEncoder\n",
30
+ "from sklearn.ensemble import RandomForestRegressor\n",
31
+ "from sklearn.metrics import mean_absolute_error, mean_squared_error\n"
32
+ ],
33
+ "execution_count": null,
34
+ "outputs": []
35
+ },
36
+ {
37
+ "cell_type": "code",
38
+ "metadata": {},
39
+ "source": [
40
+ "# Task 2: Write your code here:\n",
41
+ "ppath = os.path.join(path, 'Q1_data.csv')\n",
42
+ "df = pd.read_csv(ppath)"
43
+ ],
44
+ "execution_count": null,
45
+ "outputs": []
46
+ },
47
+ {
48
+ "cell_type": "code",
49
+ "metadata": {},
50
+ "source": [
51
+ "# Task 3: Write your code here:\n",
52
+ "df.head()"
53
+ ],
54
+ "execution_count": null,
55
+ "outputs": []
56
+ },
57
+ {
58
+ "cell_type": "code",
59
+ "metadata": {},
60
+ "source": [
61
+ "# Task 4: Write your code here:\n",
62
+ "df.info()"
63
+ ],
64
+ "execution_count": null,
65
+ "outputs": []
66
+ },
67
+ {
68
+ "cell_type": "code",
69
+ "metadata": {},
70
+ "source": [
71
+ "# Task 5: Write your code here:\n",
72
+ "df.describe()"
73
+ ],
74
+ "execution_count": null,
75
+ "outputs": []
76
+ },
77
+ {
78
+ "cell_type": "code",
79
+ "metadata": {},
80
+ "source": [
81
+ "# Task 1: Write your code here:\n",
82
+ "df.drop('Order_ID',axis = 1)"
83
+ ],
84
+ "execution_count": null,
85
+ "outputs": []
86
+ },
87
+ {
88
+ "cell_type": "code",
89
+ "metadata": {},
90
+ "source": [
91
+ "# Task 2: Write your code here:\n",
92
+ "#see the na and at this moment drop but we will see\n",
93
+ "df.isna().sum()\n",
94
+ "df.shape\n",
95
+ "dff = df.copy()\n",
96
+ "#df['Wether'].fillna(df['col'].mode()[0])\n",
97
+ "df = df.dropna()"
98
+ ],
99
+ "execution_count": null,
100
+ "outputs": []
101
+ },
102
+ {
103
+ "cell_type": "code",
104
+ "metadata": {},
105
+ "source": [
106
+ "# Task 3: Write your code here:\n",
107
+ "#check dups function\n",
108
+ "def check_duplicates(df):\n",
109
+ " duplicates = df.duplicated().sum()\n",
110
+ " print(f\"Number of Duplicate Samples: {duplicates}\")\n",
111
+ " if duplicates > 0:\n",
112
+ " print(\"Dropping Duplicates...\")\n",
113
+ " df.drop_duplicates(inplace=True)\n",
114
+ " print(\"Duplicates Dropped.\")\n",
115
+ " else:\n",
116
+ " print(\"No Duplicate Samples Found.\")\n",
117
+ "\n",
118
+ "check_duplicates(df)\n"
119
+ ],
120
+ "execution_count": null,
121
+ "outputs": []
122
+ },
123
+ {
124
+ "cell_type": "code",
125
+ "metadata": {},
126
+ "source": [
127
+ "# Task 4: Write your code here:\n",
128
+ "#df.info()\n",
129
+ "#here for the string features\n",
130
+ "categorical_cols = df.select_dtypes(include=[\"object\"]).columns\n",
131
+ "\n",
132
+ "print(\"Categorical Columns:\", list(categorical_cols))\n",
133
+ "def one_hot_encode(y, num_classes):\n",
134
+ " y = np.array(y)\n",
135
+ " m = len(y)\n",
136
+ " # 1. Create a grid of all zeros (num_samples, num_classes)\n",
137
+ " one_hot = np.zeros((m, num_classes))\n",
138
+ "\n",
139
+ " # 2. Go through each sample one by one\n",
140
+ " for i in range(m):\n",
141
+ " # Identify which class this sample belongs to\n",
142
+ " class_label = int(y[i])\n",
143
+ "\n",
144
+ " # In this row (i), set the specific class column to 1\n",
145
+ " one_hot[i, class_label] = 1\n",
146
+ "\n",
147
+ " return one_hot\n",
148
+ "\n",
149
+ " #i wanted to do onehot encoding but the time isnt in my hand\n",
150
+ "'''wv = df['Weather'].value_counts()\n",
151
+ "tv = df['Traffic_Level'].value_counts()\n",
152
+ "TIMv = df['Time_of_Day'].value_counts()\n",
153
+ "vv = df['Vehicle_Type'].value_counts()\n",
154
+ "print(wv,tv,TIMv,vv)\n",
155
+ "one_hot_encode(y, num_classes)\n",
156
+ "one_hot_encode(y, num_classes)\n",
157
+ "one_hot_encode(y, num_classes)\n",
158
+ "one_hot_encode(y, num_classes)'''\n",
159
+ "#for num in categorical_cols:\n",
160
+ "from sklearn.preprocessing import LabelEncoder\n",
161
+ "le = LabelEncoder()\n",
162
+ "for cat in categorical_cols:\n",
163
+ " df[cat] = le.fit_transform(df[cat])"
164
+ ],
165
+ "execution_count": null,
166
+ "outputs": []
167
+ },
168
+ {
169
+ "cell_type": "code",
170
+ "metadata": {},
171
+ "source": [
172
+ "# Task 5: Write your code here:\n",
173
+ "from sklearn.preprocessing import StandardScaler\n",
174
+ "\n",
175
+ "# Pick only the numerical columns, NOT the target\n",
176
+ "numerical_cols = df.select_dtypes(include=[\"number\"]).columns.drop(\"Delivery_Time\")\n",
177
+ "\n",
178
+ "scaler = StandardScaler()\n",
179
+ "\n",
180
+ "# scale the `numerical_cols`\n",
181
+ "df[numerical_cols] = scaler.fit_transform(df[numerical_cols])\n",
182
+ "\n",
183
+ "df.head()"
184
+ ],
185
+ "execution_count": null,
186
+ "outputs": []
187
+ },
188
+ {
189
+ "cell_type": "code",
190
+ "metadata": {},
191
+ "source": [
192
+ "# Task 6: Write your code here:\n",
193
+ "#for linear reggression the balance isnt a factor of it but outlier is see if its skewed apply a log transform"
194
+ ],
195
+ "execution_count": null,
196
+ "outputs": []
197
+ },
198
+ {
199
+ "cell_type": "code",
200
+ "metadata": {},
201
+ "source": [
202
+ "# Task 1: Write your code here:\n",
203
+ "X = df.drop(\"Delivery_Time\", axis=1).astype(float)\n",
204
+ "y = df[\"Delivery_Time\"].astype(float)"
205
+ ],
206
+ "execution_count": null,
207
+ "outputs": []
208
+ },
209
+ {
210
+ "cell_type": "code",
211
+ "metadata": {},
212
+ "source": [
213
+ "mae_e=[]\n",
214
+ "lr_losses=[]"
215
+ ],
216
+ "execution_count": null,
217
+ "outputs": []
218
+ },
219
+ {
220
+ "cell_type": "code",
221
+ "metadata": {},
222
+ "source": [],
223
+ "execution_count": null,
224
+ "outputs": []
225
+ },
226
+ {
227
+ "cell_type": "code",
228
+ "metadata": {},
229
+ "source": [
230
+ "# Task 2,3,4,5: Write your code here:\n",
231
+ "from sklearn.model_selection import KFold\n",
232
+ "from sklearn.ensemble import RandomForestClassifier\n",
233
+ "from sklearn.metrics import mean_absolute_error\n",
234
+ "n_splits = 5 # K=5 Folds\n",
235
+ "model = RandomForestRegressor()\n",
236
+ "# 5-Fold shuffled\n",
237
+ "kf = KFold(n_splits=n_splits, shuffle=True, random_state=42)\n",
238
+ "\n",
239
+ "for fold_idx, (train_index, test_index) in enumerate(kf.split(X, y)):\n",
240
+ " print(f\"\\nFold {fold_idx + 1}/{n_splits}\")\n",
241
+ "\n",
242
+ " # Get the train & test split for this fold\n",
243
+ " X_train, X_test = X.iloc[train_index], X.iloc[test_index]\n",
244
+ " y_train, y_test = y.iloc[train_index], y.iloc[test_index]\n",
245
+ "\n",
246
+ " # Train & Validate Models\n",
247
+ " # Fit the model on train data\n",
248
+ " model.fit(X_train, y_train)\n",
249
+ "\n",
250
+ " # Use the model to predict the test data\n",
251
+ " y_pred = model.predict(X_test)\n",
252
+ " loss = y_test-y_pred # it uses the resiual loss true - pred\n",
253
+ " mae = mean_absolute_error(y_test,y_pred)\n",
254
+ " mae_e.append(mae)\n",
255
+ " lr_losses.append(loss)\n",
256
+ "#lr_losses = lr_losses.value()\n",
257
+ "#average_losses = np.mean(lr_losses, axis=0)"
258
+ ],
259
+ "execution_count": null,
260
+ "outputs": []
261
+ },
262
+ {
263
+ "cell_type": "code",
264
+ "metadata": {},
265
+ "source": [
266
+ "# Task 1: Write your code here:\n",
267
+ "\n",
268
+ "importance_model= list(zip(X.columns, model.feature_importances_))\n",
269
+ "sorted_importance = sorted(importance_model, key=lambda x: x[1], reverse=True)\n",
270
+ "\n",
271
+ "# Extract features and their importances\n",
272
+ "features, importances = zip(*sorted_importance)\n",
273
+ "\n",
274
+ "# Plot feature importances\n",
275
+ "plt.figure(figsize=(18, 14))\n",
276
+ "plt.barh(features, importances, color='orange')\n",
277
+ "plt.xlabel('Importance Score')\n",
278
+ "plt.ylabel('Features')\n",
279
+ "plt.title('reandomforest importance Feature Importance')\n",
280
+ "plt.gca().invert_yaxis() # Invert y-axis to show the most important features at the top\n",
281
+ "plt.show()"
282
+ ],
283
+ "execution_count": null,
284
+ "outputs": []
285
+ },
286
+ {
287
+ "cell_type": "code",
288
+ "metadata": {},
289
+ "source": [
290
+ "# Task 2: Write your code here:\n"
291
+ ],
292
+ "execution_count": null,
293
+ "outputs": []
294
+ },
295
+ {
296
+ "cell_type": "code",
297
+ "metadata": {},
298
+ "source": [
299
+ "%pip install kagglehub catboost xgboost tqdm imbalanced-learn -q\n",
300
+ "\n"
301
+ ],
302
+ "execution_count": null,
303
+ "outputs": []
304
+ },
305
+ {
306
+ "cell_type": "code",
307
+ "metadata": {},
308
+ "source": [
309
+ "from catboost import CatBoostClassifier\n",
310
+ "from sklearn.metrics import accuracy_score, f1_score\n",
311
+ "models = {\n",
312
+ "\n",
313
+ " \"Random Forest\": RandomForestClassifier(\n",
314
+ " n_estimators=200,\n",
315
+ " max_depth=10\n",
316
+ " ),\n",
317
+ " \"CatBoost\": CatBoostClassifier(\n",
318
+ " verbose=0,\n",
319
+ " n_estimators=200,\n",
320
+ " max_depth=4\n",
321
+ " )\n",
322
+ "}"
323
+ ],
324
+ "execution_count": null,
325
+ "outputs": []
326
+ },
327
+ {
328
+ "cell_type": "code",
329
+ "metadata": {},
330
+ "source": [
331
+ "results = {}\n",
332
+ "\n",
333
+ "for model_name in models:\n",
334
+ " results[model_name] = {'accuracy': [], 'precision': [], 'recall': [], 'f1': [],'mae':[],}"
335
+ ],
336
+ "execution_count": null,
337
+ "outputs": []
338
+ },
339
+ {
340
+ "cell_type": "code",
341
+ "metadata": {},
342
+ "source": [
343
+ "# Task Bonus: Write your code here:\n",
344
+ "for fold_idx, (train_index, test_index) in enumerate(kf.split(X, y)):\n",
345
+ " print(f\"\\nFold {fold_idx + 1}/{n_splits}\")\n",
346
+ "\n",
347
+ " # Get the train & test split for this fold\n",
348
+ " X_train, X_test = X.iloc[train_index], X.iloc[test_index]\n",
349
+ " y_train, y_test = y.iloc[train_index], y.iloc[test_index]\n",
350
+ "\n",
351
+ " # Train & Validate Models\n",
352
+ " for model_name, model in models.items():\n",
353
+ "\n",
354
+ " print(f\"Training {model_name}...\")\n",
355
+ "\n",
356
+ " # Fit the model on train data\n",
357
+ " model.fit(X_train, y_train)\n",
358
+ "\n",
359
+ " # Use the model to predict the test data\n",
360
+ " y_pred = model.predict(X_test)\n",
361
+ "\n",
362
+ " # Calculate evaluation metrics\n",
363
+ " accuracy = accuracy_score(y_test, y_pred)\n",
364
+ " f1 = f1_score(y_test, y_pred, average='macro')\n",
365
+ " mae = mean_absolute_error(y_test,y_pred)\n",
366
+ " results[model_name]['accuracy'].append(accuracy)\n",
367
+ " results[model_name]['f1'].append(f1)\n",
368
+ " results[model_name]['mae'].append(mae)"
369
+ ],
370
+ "execution_count": null,
371
+ "outputs": []
372
+ },
373
+ {
374
+ "cell_type": "code",
375
+ "metadata": {},
376
+ "source": [
377
+ "for model_name in results:\n",
378
+ " print(f\"\\n{model_name}:\")\n",
379
+ " # Print the average of each evaluation metric across folds\n",
380
+ " print(f\" Accuracy: {np.mean(results[model_name]['accuracy']):.4f}\")\n",
381
+ " print(f\" F1-Score: {np.mean(results[model_name]['f1']):.4f}\")\n",
382
+ " #print(f\" mae: {np.mean(results[model_name]['mae']):.4f}\")"
383
+ ],
384
+ "execution_count": null,
385
+ "outputs": []
386
+ }
387
+ ],
388
+ "metadata": {
389
+ "kernelspec": {
390
+ "display_name": "Python 3",
391
+ "name": "python3"
392
+ },
393
+ "language_info": {
394
+ "name": "python"
395
+ }
396
+ },
397
+ "nbformat": 4,
398
+ "nbformat_minor": 0
399
+ }
submissions_extracted/1007/Q2.ipynb ADDED
@@ -0,0 +1,419 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "metadata": {},
6
+ "source": [
7
+ "import kagglehub\n",
8
+ "\n",
9
+ "# Download latest version\n",
10
+ "path = kagglehub.dataset_download(\"ANON_OWNER/q2-exam-data\")\n",
11
+ "\n",
12
+ "print(\"Path to dataset files:\", path)"
13
+ ],
14
+ "execution_count": null,
15
+ "outputs": []
16
+ },
17
+ {
18
+ "cell_type": "code",
19
+ "metadata": {},
20
+ "source": [
21
+ "import kagglehub\n",
22
+ "import pandas as pd\n",
23
+ "import torch\n",
24
+ "import torch.nn as nn\n",
25
+ "from torch.optim import AdamW\n",
26
+ "import matplotlib.pyplot as plt\n",
27
+ "import torch.nn.functional as F\n",
28
+ "from torch.utils.data import DataLoader, TensorDataset\n",
29
+ "from sklearn.model_selection import train_test_split\n",
30
+ "from sklearn.preprocessing import StandardScaler, LabelEncoder"
31
+ ],
32
+ "execution_count": null,
33
+ "outputs": []
34
+ },
35
+ {
36
+ "cell_type": "code",
37
+ "metadata": {},
38
+ "source": [
39
+ "import os\n",
40
+ "import pandas as pd\n",
41
+ "import numpy as np\n",
42
+ "from PIL import Image\n",
43
+ "from sklearn.model_selection import train_test_split\n",
44
+ "#import torch\n",
45
+ "# Load Labels\n",
46
+ "labels_df = pd.read_csv(os.path.join(path, \"labels.csv\"))\n",
47
+ "img_dir = os.path.join(path, \"images\")\n",
48
+ "\n",
49
+ "images = []\n",
50
+ "ages = []\n",
51
+ "\n",
52
+ "# Load Images and Resize\n",
53
+ "print(\"Loading images...\")\n",
54
+ "for index, row in labels_df.iterrows():\n",
55
+ " img_name = row.iloc[0]\n",
56
+ " age = row.iloc[1]\n",
57
+ " img_path = os.path.join(img_dir, img_name)\n",
58
+ "\n",
59
+ " if os.path.exists(img_path):\n",
60
+ " img = Image.open(img_path).convert('RGB')\n",
61
+ " img_array = np.array(img) / 255.0 # Normalize pixel values to [0, 1]\n",
62
+ " images.append(img_array)\n",
63
+ " ages.append(age)\n",
64
+ "\n",
65
+ "X = np.array(images)\n",
66
+ "y = np.array(ages)\n",
67
+ "\n",
68
+ "# Transpose image dimensions to match PyTorch format (N, C, H, W)\n",
69
+ "X = np.transpose(X, (0, 3, 1, 2))\n",
70
+ "\n",
71
+ "# Split Data\n",
72
+ "X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)\n",
73
+ "\n",
74
+ "print(f\"X_train shape: {X_train.shape}\")\n",
75
+ "print(f\"X_test shape: {X_test.shape}\")\n",
76
+ "print(f\"y_train shape: {y_train.shape}\")\n",
77
+ "print(f\"y_test shape: {y_test.shape}\")"
78
+ ],
79
+ "execution_count": null,
80
+ "outputs": []
81
+ },
82
+ {
83
+ "cell_type": "code",
84
+ "metadata": {},
85
+ "source": [
86
+ "# 1. Convert Numpy arrays to PyTorch Tensors\n",
87
+ "\n",
88
+ "# transform to tensors\n",
89
+ "X_train = torch.tensor(X_train, dtype=torch.float32)\n",
90
+ "X_test = torch.tensor(X_test, dtype=torch.float32)\n",
91
+ "y_train = torch.tensor(y_train, dtype=torch.long)\n",
92
+ "y_test = torch.tensor(y_test, dtype=torch.long)\n",
93
+ "\n"
94
+ ],
95
+ "execution_count": null,
96
+ "outputs": []
97
+ },
98
+ {
99
+ "cell_type": "code",
100
+ "metadata": {},
101
+ "source": [
102
+ "X_train.shape"
103
+ ],
104
+ "execution_count": null,
105
+ "outputs": []
106
+ },
107
+ {
108
+ "cell_type": "code",
109
+ "metadata": {},
110
+ "source": [
111
+ "# 2. Create TensorDataset objects\n",
112
+ "\n",
113
+ "train_dataset = TensorDataset(X_train, y_train)\n",
114
+ "test_dataset = TensorDataset(X_test, y_test)\n"
115
+ ],
116
+ "execution_count": null,
117
+ "outputs": []
118
+ },
119
+ {
120
+ "cell_type": "code",
121
+ "metadata": {},
122
+ "source": [
123
+ "# 3. Create DataLoaders\n",
124
+ "train_loader = DataLoader(train_dataset, batch_size=32, shuffle=True)\n",
125
+ "test_loader = DataLoader(test_dataset, batch_size=32, shuffle=False)\n",
126
+ "\n"
127
+ ],
128
+ "execution_count": null,
129
+ "outputs": []
130
+ },
131
+ {
132
+ "cell_type": "code",
133
+ "metadata": {},
134
+ "source": [
135
+ "# 4. Print shape of one batch\n",
136
+ "X_batch, y_batch = next(iter(train_loader))\n",
137
+ "print(f\"Training batch input shape: {X_batch.shape}\")\n",
138
+ "print(f\"Training batch labels shape: {y_batch.shape}\")\n"
139
+ ],
140
+ "execution_count": null,
141
+ "outputs": []
142
+ },
143
+ {
144
+ "cell_type": "code",
145
+ "metadata": {},
146
+ "source": [
147
+ "# 5. Display sample images\n",
148
+ "# Get one batch of images and labels\n",
149
+ "images, labels = next(iter(train_loader))\n",
150
+ "images.view(32,-1)\n",
151
+ "# Display the first 6 images in the batch\n",
152
+ "plt.figure(figsize=(8, 4))\n",
153
+ "\n",
154
+ "for i in range(6):\n",
155
+ "\n",
156
+ " print(images.shape)\n",
157
+ " plt.subplot(2, 3, i + 1)\n",
158
+ " #here the problem is how to remove the channel from the image so its h*w\n",
159
+ " plt.imshow(images[i].squeeze(), cmap='gray')\n",
160
+ " plt.title(f\"Label: {labels[i].item()}\")\n",
161
+ " plt.axis('off')\n",
162
+ "\n",
163
+ "plt.tight_layout()\n",
164
+ "plt.show()\n"
165
+ ],
166
+ "execution_count": null,
167
+ "outputs": []
168
+ },
169
+ {
170
+ "cell_type": "code",
171
+ "metadata": {},
172
+ "source": [
173
+ "# Task 1: Write your model class here:\n",
174
+ "class NN4Layer(nn.Module):\n",
175
+ "\n",
176
+ " def __init__(self, input_dim, hidden_dim, output_dim=1):\n",
177
+ " super(NN4Layer, self).__init__()\n",
178
+ "\n",
179
+ " # First linear layer: input features -> hidden layer\n",
180
+ " self.layer1 = nn.Linear(input_dim, hidden_dim)\n",
181
+ "\n",
182
+ " # Second linear layer: hidden layer -> hidden layer\n",
183
+ " self.layer2 = nn.Linear(hidden_dim, hidden_dim)\n",
184
+ "\n",
185
+ " # Third linear layer: hidden layer -> hidden layer\n",
186
+ " self.layer3 = nn.Linear(hidden_dim, hidden_dim)\n",
187
+ "\n",
188
+ " # Output layer: hidden layer -> 1 aka prediction for age\n",
189
+ " self.layer4 = nn.Linear(hidden_dim, output_dim)\n",
190
+ "\n",
191
+ " # ReLU activation for non-linearity\n",
192
+ " self.relu = nn.ReLU()\n",
193
+ "\n",
194
+ " # Defines how input data flows through the network\n",
195
+ " def forward(self, x):\n",
196
+ " # First hidden layer\n",
197
+ " a1 = self.relu(self.layer1(x))\n",
198
+ "\n",
199
+ " # Second hidden layer\n",
200
+ " a2 = self.relu(self.layer2(a1))\n",
201
+ "\n",
202
+ " # Third hidden layer\n",
203
+ " a3 = self.relu(self.layer3(a2))\n",
204
+ "\n",
205
+ "\n",
206
+ " output = self.layer4(a3)\n",
207
+ "\n",
208
+ " return output"
209
+ ],
210
+ "execution_count": null,
211
+ "outputs": []
212
+ },
213
+ {
214
+ "cell_type": "code",
215
+ "metadata": {},
216
+ "source": [
217
+ "def train_one_epoch(model, optimizer, criterion, train_loader, device):\n",
218
+ " # Set the model to training mode\n",
219
+ " model.train()\n",
220
+ "\n",
221
+ " running_loss = 0.0\n",
222
+ "\n",
223
+ " for X_batch, y_batch in train_loader:\n",
224
+ " # Move batch to the selected device\n",
225
+ " X_batch = X_batch.view(32,-1)\n",
226
+ " X_batch =torch.tensor(X_batch, dtype=torch.float32).to(device)\n",
227
+ " y_batch = y_batch.view(-1, 1).to(device)\n",
228
+ "\n",
229
+ " # Forward pass\n",
230
+ " outputs = model(X_batch)\n",
231
+ " loss = criterion(outputs, y_batch)\n",
232
+ "\n",
233
+ " # Backward pass & optimization\n",
234
+ " optimizer.zero_grad() # Clear previous gradients\n",
235
+ " loss.backward() # Compute gradients\n",
236
+ " optimizer.step() # Update model parameters\n",
237
+ "\n",
238
+ " running_loss += loss.item()\n",
239
+ "\n",
240
+ " # Average loss over all batches\n",
241
+ " avg_loss = running_loss / len(train_loader)\n",
242
+ "\n",
243
+ " return avg_loss"
244
+ ],
245
+ "execution_count": null,
246
+ "outputs": []
247
+ },
248
+ {
249
+ "cell_type": "code",
250
+ "metadata": {},
251
+ "source": [
252
+ "# Task 3: Write your validation loop here:\n",
253
+ "def validate(model, criterion, test_loader, device):\n",
254
+ " # Set the model to evaluation mode\n",
255
+ " model.eval()\n",
256
+ "\n",
257
+ " running_loss = 0.0\n",
258
+ " correct = 0\n",
259
+ " total = 0\n",
260
+ "\n",
261
+ " with torch.no_grad():\n",
262
+ " for X_batch, y_batch in test_loader:\n",
263
+ " # Move data to device\n",
264
+ " X_batch = X_batch.to(device) # shape: (batch_size, num_features)\n",
265
+ " y_batch = y_batch.to(device) # shape: (batch_size,)\n",
266
+ "\n",
267
+ " # Forward pass\n",
268
+ " outputs = model(X_batch)\n",
269
+ " loss = criterion(outputs, y_batch)\n",
270
+ " running_loss += loss.item()\n",
271
+ "\n",
272
+ "\n",
273
+ " total += y_batch.size(0)\n",
274
+ "\n",
275
+ " avg_loss = running_loss / len(test_loader)\n",
276
+ " accuracy = correct / total\n",
277
+ "\n",
278
+ " return avg_loss, accuracy"
279
+ ],
280
+ "execution_count": null,
281
+ "outputs": []
282
+ },
283
+ {
284
+ "cell_type": "code",
285
+ "metadata": {},
286
+ "source": [
287
+ "# Task 4: Define device, model, loss, optimizer:\n",
288
+ "# Device setup\n",
289
+ "device = torch.device(\"cuda\" if torch.cuda.is_available() else \"cpu\")\n",
290
+ "print(X_train.shape)\n",
291
+ "#x_view = X_train.view(1600, -1)\n",
292
+ "# Model parameters\n",
293
+ "input_dim = 3*36*36 # Number of features WxHxC\n",
294
+ "hidden_dim = 14 # Design choice\n",
295
+ "\n",
296
+ "# Instantiate model\n",
297
+ "model = NN4Layer(input_dim, hidden_dim).to(device)\n",
298
+ "\n",
299
+ "# Print the model architecture\n",
300
+ "print(\"Model Architecture:\\n\")\n",
301
+ "print(model)\n",
302
+ "\n",
303
+ "# Calculate the total number of trainable parameters\n",
304
+ "total_params = sum(p.numel() for p in model.parameters() if p.requires_grad)\n",
305
+ "print(f\"\\nTotal trainable parameters: {total_params}\")\n",
306
+ "num_epochs = 20\n",
307
+ "learning_rate = 0.001\n",
308
+ "\n",
309
+ "# Define criterion (loss function) - using CrossEntropyLoss as model now outputs logits\n",
310
+ "criterion = nn.MSELoss()\n",
311
+ "# Define optimizer\n",
312
+ "optimizer = AdamW(model.parameters(), learning_rate)"
313
+ ],
314
+ "execution_count": null,
315
+ "outputs": []
316
+ },
317
+ {
318
+ "cell_type": "code",
319
+ "metadata": {},
320
+ "source": [
321
+ "# Task 5: Start training for 20 epochs:\n",
322
+ "# Run Training\n",
323
+ "train_losses = []\n",
324
+ "val_losses = []\n",
325
+ "val_accuracies = []\n",
326
+ "\n",
327
+ "print('Starting Training...')\n",
328
+ "for epoch in range(num_epochs):\n",
329
+ " # Train one epoch\n",
330
+ " train_loss = train_one_epoch(model, optimizer, criterion, train_loader, device)\n",
331
+ "\n",
332
+ " # Validate\n",
333
+ " val_loss, val_accuracy = validate(model, criterion, test_loader, device)\n",
334
+ "\n",
335
+ " train_losses.append(train_loss)\n",
336
+ " val_losses.append(val_loss)\n",
337
+ " val_accuracies.append(val_accuracy)\n",
338
+ "\n",
339
+ " print(f'Epoch [{epoch+1}/{num_epochs}], Train Loss: {train_loss:.4f}, Val Loss: {val_loss:.4f}, Val Accuracy: {val_accuracy:.4f}')\n",
340
+ "\n",
341
+ "print('Training Complete!')\n",
342
+ "\n",
343
+ "\n",
344
+ "#####the erorr here is there is a problem the train epoch use 32*3*36 instade of 3*36*36 and i couldnt find the right way to change the shape"
345
+ ],
346
+ "execution_count": null,
347
+ "outputs": []
348
+ },
349
+ {
350
+ "cell_type": "code",
351
+ "metadata": {},
352
+ "source": [
353
+ "# Task 1: Write your code here:\n",
354
+ "# Plotting results\n",
355
+ "plt.figure(figsize=(7, 5))\n",
356
+ "\n",
357
+ "plt.plot(train_losses, label='Train Loss')\n",
358
+ "plt.plot(val_losses, label='Validation Loss')\n",
359
+ "plt.title('Loss over Epochs')\n",
360
+ "plt.xlabel('Epoch')\n",
361
+ "plt.ylabel('Loss')\n",
362
+ "plt.legend()\n",
363
+ "\n",
364
+ "plt.tight_layout()\n",
365
+ "plt.show()"
366
+ ],
367
+ "execution_count": null,
368
+ "outputs": []
369
+ },
370
+ {
371
+ "cell_type": "code",
372
+ "metadata": {},
373
+ "source": [
374
+ "# Task 2 (Bonus): Write your code here:\n",
375
+ "# Set model to evaluation mode\n",
376
+ "model.eval()\n",
377
+ "# Get one batch from the test DataLoader\n",
378
+ "images, labels = next(iter(test_loader))\n",
379
+ "# Move images to device\n",
380
+ "images = images.to(device)\n",
381
+ "labels = labels.to(device)\n",
382
+ "\n",
383
+ "with torch.no_grad():\n",
384
+ " # Flatten images before passing to the model\n",
385
+ " outputs = model(images.view(images.size(0), -1))\n",
386
+ " predictions = torch.argmax(outputs, dim=1)\n",
387
+ "\n",
388
+ "# Move tensors back to CPU for plotting\n",
389
+ "images = images.cpu()\n",
390
+ "labels = labels.cpu()\n",
391
+ "predictions = predictions.cpu()\n",
392
+ "\n",
393
+ "# Plot first 6 predictions\n",
394
+ "plt.figure(figsize=(8, 4))\n",
395
+ "for i in range(6):\n",
396
+ " plt.subplot(2, 3, i + 1)\n",
397
+ " plt.imshow(images[i].squeeze(), cmap='gray')\n",
398
+ " plt.title(f\"True: {labels[i]} | Pred: {predictions[i]}\")\n",
399
+ " plt.axis('off')\n",
400
+ "\n",
401
+ "plt.tight_layout()\n",
402
+ "plt.show()"
403
+ ],
404
+ "execution_count": null,
405
+ "outputs": []
406
+ }
407
+ ],
408
+ "metadata": {
409
+ "kernelspec": {
410
+ "display_name": "Python 3",
411
+ "name": "python3"
412
+ },
413
+ "language_info": {
414
+ "name": "python"
415
+ }
416
+ },
417
+ "nbformat": 4,
418
+ "nbformat_minor": 0
419
+ }
submissions_extracted/1007/Q3.ipynb ADDED
@@ -0,0 +1,335 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "metadata": {},
6
+ "source": [
7
+ "import kagglehub\n",
8
+ "\n",
9
+ "\n",
10
+ "\n",
11
+ "# Download latest version\n",
12
+ "\n",
13
+ "path = kagglehub.dataset_download(\"ANON_OWNER/q3-exam-data\")\n",
14
+ "\n",
15
+ "\n",
16
+ "\n",
17
+ "print(\"Path to dataset files:\", path)"
18
+ ],
19
+ "execution_count": null,
20
+ "outputs": []
21
+ },
22
+ {
23
+ "cell_type": "code",
24
+ "metadata": {},
25
+ "source": [
26
+ "import numpy as np\n",
27
+ "import pandas as pd\n",
28
+ "import matplotlib.pyplot as plt\n",
29
+ "import os\n",
30
+ "import kagglehub\n",
31
+ "\n",
32
+ "from sklearn.model_selection import train_test_split, KFold\n",
33
+ "from sklearn.preprocessing import StandardScaler, LabelEncoder\n",
34
+ "from sklearn.ensemble import RandomForestRegressor\n",
35
+ "from sklearn.metrics import mean_absolute_error, mean_squared_error"
36
+ ],
37
+ "execution_count": null,
38
+ "outputs": []
39
+ },
40
+ {
41
+ "cell_type": "code",
42
+ "metadata": {},
43
+ "source": [
44
+ "# Task 1: Write your code here:\n",
45
+ "ppath = os.path.join(path, 'Q3_data.csv')\n",
46
+ "df = pd.read_csv(ppath)"
47
+ ],
48
+ "execution_count": null,
49
+ "outputs": []
50
+ },
51
+ {
52
+ "cell_type": "code",
53
+ "metadata": {},
54
+ "source": [
55
+ "# Task 2: Write your code here:\n",
56
+ "df.head()"
57
+ ],
58
+ "execution_count": null,
59
+ "outputs": []
60
+ },
61
+ {
62
+ "cell_type": "code",
63
+ "metadata": {},
64
+ "source": [
65
+ "# Task 3: Write your code here:\n",
66
+ "df.info()"
67
+ ],
68
+ "execution_count": null,
69
+ "outputs": []
70
+ },
71
+ {
72
+ "cell_type": "code",
73
+ "metadata": {},
74
+ "source": [
75
+ "# Task 4: Write your code here:\n",
76
+ "df.describe()"
77
+ ],
78
+ "execution_count": null,
79
+ "outputs": []
80
+ },
81
+ {
82
+ "cell_type": "code",
83
+ "metadata": {},
84
+ "source": [
85
+ "# Task 1: Write your code here:\n",
86
+ "def check_missing_values(df):\n",
87
+ " missing_values = df.isnull().sum()\n",
88
+ " print(\"Missing Values per Column:\")\n",
89
+ " print(missing_values[missing_values > 0])\n",
90
+ " if missing_values.any():\n",
91
+ " print(\"\\nHandle Missing Values as needed.\")\n",
92
+ " else:\n",
93
+ " print(\"\\nNo Missing Values Found.\")\n",
94
+ "\n",
95
+ "check_missing_values(df)\n",
96
+ "df['Target'].isna().sum()\n",
97
+ "numerical_cols = df.columns.drop(\"Target\")\n",
98
+ "print(numerical_cols)\n",
99
+ "for num in numerical_cols:\n",
100
+ " print(num)\n",
101
+ " df[num].fillna(df[num].mode()[0])\n",
102
+ "\n",
103
+ "\n",
104
+ "check_missing_values(df)"
105
+ ],
106
+ "execution_count": null,
107
+ "outputs": []
108
+ },
109
+ {
110
+ "cell_type": "code",
111
+ "metadata": {},
112
+ "source": [
113
+ "# Task 2: Write your code here:\n",
114
+ "def check_duplicates(df):\n",
115
+ "\n",
116
+ "\n",
117
+ " duplicates = df.duplicated().sum()\n",
118
+ "\n",
119
+ " print(f\"Number of Duplicate Samples: {duplicates}\")\n",
120
+ " if duplicates > 0:\n",
121
+ " print(\"Dropping Duplicates...\")\n",
122
+ " df.drop_duplicates(inplace=True)\n",
123
+ " print(\"Duplicates Dropped.\")\n",
124
+ " else:\n",
125
+ " print(\"No Duplicate Samples Found.\")\n",
126
+ "\n",
127
+ "check_duplicates(df)"
128
+ ],
129
+ "execution_count": null,
130
+ "outputs": []
131
+ },
132
+ {
133
+ "cell_type": "code",
134
+ "metadata": {},
135
+ "source": [
136
+ "# Task 3: Write your code here:\n",
137
+ "categorical_cols = df.select_dtypes(include=[\"object\"]).columns\n",
138
+ "\n",
139
+ "print(\"Categorical Columns:\", list(categorical_cols))\n",
140
+ "#no string or categorical clmn so no encode needed\n",
141
+ "df.head()"
142
+ ],
143
+ "execution_count": null,
144
+ "outputs": []
145
+ },
146
+ {
147
+ "cell_type": "code",
148
+ "metadata": {},
149
+ "source": [
150
+ "# Task 4: Write your code here:\n",
151
+ "from sklearn.preprocessing import StandardScaler\n",
152
+ "\n",
153
+ "# Pick only the numerical columns, NOT the target\n",
154
+ "numerical_cols = df.select_dtypes(include=[\"number\"]).columns.drop(\"Target\")\n",
155
+ "\n",
156
+ "scaler = StandardScaler()\n",
157
+ "\n",
158
+ "# scale the `numerical_cols`\n",
159
+ "df[numerical_cols] = scaler.fit_transform(df[numerical_cols])\n",
160
+ "\n",
161
+ "df.head()"
162
+ ],
163
+ "execution_count": null,
164
+ "outputs": []
165
+ },
166
+ {
167
+ "cell_type": "code",
168
+ "metadata": {},
169
+ "source": [
170
+ "# Task 5: Write your code here:\n",
171
+ "def check_target_imbalance(df, target_column):\n",
172
+ " print(\"Target Distribution:\")\n",
173
+ "\n",
174
+ " df[target_column].hist() # Yeah you can just do this :)\n",
175
+ " plt.show()\n",
176
+ "\n",
177
+ "check_target_imbalance(df, \"Target\")\n"
178
+ ],
179
+ "execution_count": null,
180
+ "outputs": []
181
+ },
182
+ {
183
+ "cell_type": "code",
184
+ "metadata": {},
185
+ "source": [
186
+ "# Task 1: Write your code here:\n",
187
+ "X = df.drop(\"Target\", axis=1).astype(float)\n",
188
+ "y = df[\"Target\"].astype(float)"
189
+ ],
190
+ "execution_count": null,
191
+ "outputs": []
192
+ },
193
+ {
194
+ "cell_type": "code",
195
+ "metadata": {},
196
+ "source": [
197
+ "%pip install kagglehub catboost xgboost tqdm imbalanced-learn -q"
198
+ ],
199
+ "execution_count": null,
200
+ "outputs": []
201
+ },
202
+ {
203
+ "cell_type": "code",
204
+ "metadata": {},
205
+ "source": [
206
+ "sr_results = {'loss': [], 'acc': [], 'f1': []}\n"
207
+ ],
208
+ "execution_count": null,
209
+ "outputs": []
210
+ },
211
+ {
212
+ "cell_type": "code",
213
+ "metadata": {},
214
+ "source": [
215
+ "# Task 2,3,4,5: Write your code here:\n",
216
+ "from sklearn.model_selection import StratifiedKFold\n",
217
+ "from catboost import CatBoostClassifier\n",
218
+ "from sklearn.metrics import accuracy_score, f1_score\n",
219
+ "n_splits = 5 # K=5 Folds\n",
220
+ "model = CatBoostClassifier()\n",
221
+ "# 5-Fold , shuffled\n",
222
+ "skf = StratifiedKFold(n_splits=n_splits, shuffle=True, random_state=42)\n",
223
+ "\n",
224
+ "for fold_idx, (train_index, test_index) in enumerate(skf.split(X, y)):\n",
225
+ " print(f\"\\nFold {fold_idx + 1}/{n_splits}\")\n",
226
+ "\n",
227
+ " # Get the train & test split for this fold\n",
228
+ " X_train, X_test = X.iloc[train_index], X.iloc[test_index]\n",
229
+ " y_train, y_test = y.iloc[train_index], y.iloc[test_index]\n",
230
+ "\n",
231
+ " # Train & Validate Models\n",
232
+ " # Fit the model on train data\n",
233
+ " model.fit(X_train, y_train)\n",
234
+ "\n",
235
+ " # Use the model to predict the test data\n",
236
+ " y_pred = model.predict(X_test)\n",
237
+ " accuracy = accuracy_score(y_test, y_pred)\n",
238
+ " f1 = f1_score(y_test, y_pred)\n",
239
+ " losses = y_test-y_pred\n",
240
+ " # Store results\n",
241
+ " sr_results['loss'].append(losses)\n",
242
+ " sr_results['acc'].append(accuracy)\n",
243
+ " sr_results['f1'].append(f1)\n"
244
+ ],
245
+ "execution_count": null,
246
+ "outputs": []
247
+ },
248
+ {
249
+ "cell_type": "code",
250
+ "metadata": {},
251
+ "source": [
252
+ "# Task 1: Write your code here:\n",
253
+ "importance_model= list(zip(X.columns, model.feature_importances_))\n",
254
+ "sorted_importance = sorted(importance_model, key=lambda x: x[1], reverse=True)\n",
255
+ "\n",
256
+ "# Extract features and their importances\n",
257
+ "features, importances = zip(*sorted_importance)\n",
258
+ "\n",
259
+ "# Plot feature importances\n",
260
+ "plt.figure(figsize=(18, 14))\n",
261
+ "plt.barh(features, importances, color='orange')\n",
262
+ "plt.xlabel('Importance Score')\n",
263
+ "plt.ylabel('Features')\n",
264
+ "plt.title('catboost importance Feature Importance')\n",
265
+ "plt.gca().invert_yaxis() # Invert y-axis to show the most important features at the top\n",
266
+ "plt.show()"
267
+ ],
268
+ "execution_count": null,
269
+ "outputs": []
270
+ },
271
+ {
272
+ "cell_type": "code",
273
+ "metadata": {},
274
+ "source": [
275
+ "# Task 2: Write your code here:\n",
276
+ "print(features[0])"
277
+ ],
278
+ "execution_count": null,
279
+ "outputs": []
280
+ },
281
+ {
282
+ "cell_type": "code",
283
+ "metadata": {},
284
+ "source": [],
285
+ "execution_count": null,
286
+ "outputs": []
287
+ },
288
+ {
289
+ "cell_type": "code",
290
+ "metadata": {},
291
+ "source": [
292
+ "# Task Bonus: Write your code here:\n",
293
+ "X_golden = df['P_2']\n",
294
+ "n_splits = 5 # K=5 Folds\n",
295
+ "model = CatBoostClassifier()\n",
296
+ "# 5-Fold , shuffled\n",
297
+ "skf = StratifiedKFold(n_splits=n_splits, shuffle=True, random_state=42)\n",
298
+ "\n",
299
+ "for fold_idx, (train_index, test_index) in enumerate(skf.split(X_golden, y)):\n",
300
+ " print(f\"\\nFold {fold_idx + 1}/{n_splits}\")\n",
301
+ "\n",
302
+ " # Get the train & test split for this fold\n",
303
+ " X_train, X_test = X.iloc[train_index], X.iloc[test_index]\n",
304
+ " y_train, y_test = y.iloc[train_index], y.iloc[test_index]\n",
305
+ "\n",
306
+ " # Train & Validate Models\n",
307
+ " # Fit the model on train data\n",
308
+ " model.fit(X_train, y_train)\n",
309
+ "\n",
310
+ " # Use the model to predict the test data\n",
311
+ " y_pred = model.predict(X_test)\n",
312
+ " accuracy = accuracy_score(y_test, y_pred)\n",
313
+ " f1 = f1_score(y_test, y_pred)\n",
314
+ " losses = y_test-y_pred\n",
315
+ " # Store results\n",
316
+ " sr_results['loss'].append(losses)\n",
317
+ " sr_results['acc'].append(accuracy)\n",
318
+ " sr_results['f1'].append(f1)"
319
+ ],
320
+ "execution_count": null,
321
+ "outputs": []
322
+ }
323
+ ],
324
+ "metadata": {
325
+ "kernelspec": {
326
+ "display_name": "Python 3",
327
+ "name": "python3"
328
+ },
329
+ "language_info": {
330
+ "name": "python"
331
+ }
332
+ },
333
+ "nbformat": 4,
334
+ "nbformat_minor": 0
335
+ }
submissions_extracted/1008/Q1.ipynb ADDED
@@ -0,0 +1,325 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "metadata": {},
6
+ "source": [
7
+ "import kagglehub\n",
8
+ "import os\n",
9
+ "import pandas as pd\n",
10
+ "import matplotlib.pyplot as plt\n",
11
+ "from sklearn.model_selection import train_test_split\n",
12
+ "from sklearn.preprocessing import StandardScaler, LabelEncoder"
13
+ ],
14
+ "execution_count": null,
15
+ "outputs": []
16
+ },
17
+ {
18
+ "cell_type": "code",
19
+ "metadata": {},
20
+ "source": [
21
+ "import kagglehub\n",
22
+ "\n",
23
+ "# Download latest version\n",
24
+ "path = kagglehub.dataset_download(\"ANON_OWNER/q1-exam-data\")\n",
25
+ "\n",
26
+ "print(\"Path to dataset files:\", path)"
27
+ ],
28
+ "execution_count": null,
29
+ "outputs": []
30
+ },
31
+ {
32
+ "cell_type": "code",
33
+ "metadata": {},
34
+ "source": [
35
+ "# Task 1: Write your code here:\n",
36
+ "main_path = os.path.join(path, 'Q1_data.csv')\n",
37
+ "main_df = pd.read_csv(main_path)\n",
38
+ "\n"
39
+ ],
40
+ "execution_count": null,
41
+ "outputs": []
42
+ },
43
+ {
44
+ "cell_type": "code",
45
+ "metadata": {},
46
+ "source": [
47
+ "# Task 2: Write your code here: Inspect the first few rows using head()\n",
48
+ "main_df.head()"
49
+ ],
50
+ "execution_count": null,
51
+ "outputs": []
52
+ },
53
+ {
54
+ "cell_type": "code",
55
+ "metadata": {},
56
+ "source": [
57
+ "# Task 3: Write your code here: Display dataset information using info()\n",
58
+ "main_df.info()"
59
+ ],
60
+ "execution_count": null,
61
+ "outputs": []
62
+ },
63
+ {
64
+ "cell_type": "code",
65
+ "metadata": {},
66
+ "source": [
67
+ "# Task 4: Write your code here: Show statistical description using describe()\n",
68
+ "main_df.describe()"
69
+ ],
70
+ "execution_count": null,
71
+ "outputs": []
72
+ },
73
+ {
74
+ "cell_type": "code",
75
+ "metadata": {},
76
+ "source": [
77
+ "# Task 5: Write your code here: Plot the target distribution (delivery_time)\n",
78
+ "plt.figure(figsize=(10, 5))\n",
79
+ "plt.hist(main_df['Delivery_Time'].dropna(), bins=50)\n",
80
+ "plt.title('delivery_time')\n",
81
+ "plt.show()"
82
+ ],
83
+ "execution_count": null,
84
+ "outputs": []
85
+ },
86
+ {
87
+ "cell_type": "code",
88
+ "metadata": {},
89
+ "source": [
90
+ "# Task 1: Write your code here: Drop the 'Order_ID' column from the data\n",
91
+ "df_clean = main_df.drop(columns=['Order_ID'])\n",
92
+ "df_clean"
93
+ ],
94
+ "execution_count": null,
95
+ "outputs": []
96
+ },
97
+ {
98
+ "cell_type": "code",
99
+ "metadata": {},
100
+ "source": [
101
+ "# Task 2: Write your code here: Handle missing values appropriately (Hint: I guess you want to have a closer look at the columns with missing values :) )\n",
102
+ "df_clean = df_clean.dropna()\n",
103
+ "print(\"Missing values remaining:\", df_clean.isnull().sum().sum())\n"
104
+ ],
105
+ "execution_count": null,
106
+ "outputs": []
107
+ },
108
+ {
109
+ "cell_type": "code",
110
+ "metadata": {},
111
+ "source": [
112
+ "# Task 3: Write your code here:Check and remove duplicates if any exist\n",
113
+ "print(\"duplicate\", df_clean.duplicated().sum())\n",
114
+ "df_clean = df_clean.drop_duplicates()\n",
115
+ "print(\"duplicate - after\", df_clean.duplicated().sum())\n",
116
+ "\n",
117
+ "\n",
118
+ "df_clean"
119
+ ],
120
+ "execution_count": null,
121
+ "outputs": []
122
+ },
123
+ {
124
+ "cell_type": "code",
125
+ "metadata": {},
126
+ "source": [
127
+ "df_clean\n"
128
+ ],
129
+ "execution_count": null,
130
+ "outputs": []
131
+ },
132
+ {
133
+ "cell_type": "code",
134
+ "metadata": {},
135
+ "source": [],
136
+ "execution_count": null,
137
+ "outputs": []
138
+ },
139
+ {
140
+ "cell_type": "code",
141
+ "metadata": {},
142
+ "source": [
143
+ "# Task 4: Write your code here: Encode categorical variables if needed (Bonus if used One Hot Encoding)\n",
144
+ "categorical_cols = ['Vehicle_Type', 'Time_of_Day', 'Traffic_Level', 'Weather']\n",
145
+ "for col in categorical_cols:\n",
146
+ " le = LabelEncoder()\n",
147
+ " df_clean[col] = le.fit_transform(df_clean[col].astype(str))\n",
148
+ "\n",
149
+ "df_clean.head()"
150
+ ],
151
+ "execution_count": null,
152
+ "outputs": []
153
+ },
154
+ {
155
+ "cell_type": "code",
156
+ "metadata": {},
157
+ "source": [
158
+ "# Task 5: Write your code here: Apply feature scaling for all features (Use StandardScaler)\n",
159
+ "scaler = StandardScaler()\n",
160
+ "X_train_scaled = scaler.fit_transform(df_clean)\n",
161
+ "df_clean"
162
+ ],
163
+ "execution_count": null,
164
+ "outputs": []
165
+ },
166
+ {
167
+ "cell_type": "code",
168
+ "metadata": {},
169
+ "source": [
170
+ "# Task 6: Write your code here: Check for target imbalance and state if it is imbalanced or not (keep this cell empty if not needed)"
171
+ ],
172
+ "execution_count": null,
173
+ "outputs": []
174
+ },
175
+ {
176
+ "cell_type": "code",
177
+ "metadata": {},
178
+ "source": [
179
+ "# Task 1: Write your code here:\n",
180
+ "# Define features (X) and target (y)\n",
181
+ "feature_cols = ['Distance_km',\t'Weather'\t,'Traffic_Level'\t,'Time_of_Day'\t,'Vehicle_Type'\t,'Preparation_Time_min'\t,'Courier_Experience_yrs']\n",
182
+ "X = df_clean[feature_cols]\n",
183
+ "y = df_clean['Delivery_Time']\n",
184
+ "\n",
185
+ "# Train-test split (80% train, 20% test)\n",
186
+ "X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)\n",
187
+ "print(f\"Train: {X_train.shape}, Test: {X_test.shape}\")"
188
+ ],
189
+ "execution_count": null,
190
+ "outputs": []
191
+ },
192
+ {
193
+ "cell_type": "code",
194
+ "metadata": {},
195
+ "source": [
196
+ "# Scale features - fit on train, transform both\n",
197
+ "scaler = StandardScaler()\n",
198
+ "X_train_scaled = scaler.fit_transform(X_train)\n",
199
+ "X_test_scaled = scaler.transform(X_test)\n",
200
+ "\n",
201
+ "print(f\"\\nScaled ranges - Min: {X_train_scaled.min():.2f}, Max: {X_train_scaled.max():.2f}\")\n",
202
+ "pd.DataFrame(X_train_scaled, columns=X_train.columns).head(3)\n"
203
+ ],
204
+ "execution_count": null,
205
+ "outputs": []
206
+ },
207
+ {
208
+ "cell_type": "code",
209
+ "metadata": {},
210
+ "source": [
211
+ "from sklearn.model_selection import train_test_split, KFold\n",
212
+ "from sklearn.preprocessing import StandardScaler, LabelEncoder\n",
213
+ "from sklearn.ensemble import RandomForestRegressor\n",
214
+ "from sklearn.metrics import mean_absolute_error, mean_squared_error\n",
215
+ "import numpy as np"
216
+ ],
217
+ "execution_count": null,
218
+ "outputs": []
219
+ },
220
+ {
221
+ "cell_type": "code",
222
+ "metadata": {},
223
+ "source": [
224
+ "# Train Random Forest Regressor\n",
225
+ "model = RandomForestRegressor(n_estimators=100, max_depth=20, random_state=42, n_jobs=-1)\n",
226
+ "model.fit(X_train_scaled, y_train)\n",
227
+ "print(\"Model trained!\")\n",
228
+ "\n",
229
+ "# Use the correct split: KFold OR StratifiedKFold\n",
230
+ "kfold = KFold(n_splits=5, shuffle=True, random_state=42)\n",
231
+ "\n",
232
+ "mae_scores = []\n",
233
+ "rmse_scores = []\n",
234
+ "\n",
235
+ "for train_idx, val_idx in kfold.split(X_train_scaled):\n",
236
+ " X_fold_train, X_fold_val = X_train_scaled[train_idx], X_train_scaled[val_idx]\n",
237
+ " y_fold_train, y_fold_val = y_train.iloc[train_idx], y_train.iloc[val_idx]\n",
238
+ "\n",
239
+ " # Train and predict\n",
240
+ " model.fit(X_fold_train, y_fold_train)\n",
241
+ " y_fold_pred = model.predict(X_fold_val)\n",
242
+ "\n",
243
+ " # Calculate metrics\n",
244
+ " mae_scores.append(mean_absolute_error(y_fold_val, y_fold_pred))\n",
245
+ " rmse_scores.append(np.sqrt(mean_squared_error(y_fold_val, y_fold_pred)))\n",
246
+ "\n",
247
+ "mae_scores = np.array(mae_scores)\n",
248
+ "rmse_scores = np.array(rmse_scores)\n",
249
+ "\n",
250
+ "print(f\"5-Fold CV Results:\")\n",
251
+ "print(f\"MAE: ${mae_scores.mean():,.2f}\")\n",
252
+ "print(f\"RMSE: ${rmse_scores.mean():,.2f}\")\n",
253
+ "# Evaluate using MAE (Mean Absolute Error) ONLY\n",
254
+ "# Predict and evaluate\n",
255
+ "y_pred = model.predict(X_test_scaled)\n",
256
+ "mae = mean_absolute_error(y_test, y_pred)\n",
257
+ "print(f\"MAE: ${mae:,.2f}\")\n",
258
+ "# Print the averaged score across all folds"
259
+ ],
260
+ "execution_count": null,
261
+ "outputs": []
262
+ },
263
+ {
264
+ "cell_type": "code",
265
+ "metadata": {},
266
+ "source": [
267
+ "# Task 1: Write your code here:\n",
268
+ "# Feature importance\n",
269
+ "feature_importance = pd.DataFrame({\n",
270
+ " 'feature': feature_cols,\n",
271
+ " 'importance': model.feature_importances_\n",
272
+ "}).sort_values('importance', ascending=False)\n",
273
+ "\n",
274
+ "plt.figure(figsize=(10, 6))\n",
275
+ "plt.barh(feature_importance['feature'], feature_importance['importance'])\n",
276
+ "plt.xlabel('Importance')\n",
277
+ "plt.title('Feature Importance')\n",
278
+ "plt.gca().invert_yaxis()\n",
279
+ "plt.show()"
280
+ ],
281
+ "execution_count": null,
282
+ "outputs": []
283
+ },
284
+ {
285
+ "cell_type": "code",
286
+ "metadata": {},
287
+ "source": [
288
+ "# Task 2: Write your code here:2. Plot predicted delivery time histogram\n",
289
+ "\n",
290
+ "# Plot Predictions vs Ground Truth\n",
291
+ "plt.figure(figsize=(6, 4))\n",
292
+ "plt.scatter(y_test, y_pred, alpha=0.6)\n",
293
+ "plt.plot(\n",
294
+ " [y_test.min(), y_test.max()],\n",
295
+ " [y_test.min(), y_test.max()],\n",
296
+ " \"r--\",\n",
297
+ " linewidth=2\n",
298
+ ")\n",
299
+ "plt.grid(True)"
300
+ ],
301
+ "execution_count": null,
302
+ "outputs": []
303
+ },
304
+ {
305
+ "cell_type": "code",
306
+ "metadata": {},
307
+ "source": [
308
+ "# Task Bonus: Write your code here:"
309
+ ],
310
+ "execution_count": null,
311
+ "outputs": []
312
+ }
313
+ ],
314
+ "metadata": {
315
+ "kernelspec": {
316
+ "display_name": "Python 3",
317
+ "name": "python3"
318
+ },
319
+ "language_info": {
320
+ "name": "python"
321
+ }
322
+ },
323
+ "nbformat": 4,
324
+ "nbformat_minor": 0
325
+ }
submissions_extracted/1008/Q3.ipynb ADDED
@@ -0,0 +1,190 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "metadata": {},
6
+ "source": [
7
+ "import kagglehub\n",
8
+ "import pandas as pd\n",
9
+ "import torch\n",
10
+ "import os\n",
11
+ "import torch.nn as nn\n",
12
+ "from torch.optim import AdamW\n",
13
+ "import matplotlib.pyplot as plt\n",
14
+ "import torch.nn.functional as F\n",
15
+ "from torch.utils.data import DataLoader, TensorDataset\n",
16
+ "from sklearn.model_selection import train_test_split\n",
17
+ "from sklearn.preprocessing import StandardScaler, LabelEncoder\n",
18
+ "\n",
19
+ "\n",
20
+ "\n",
21
+ "# Download latest version\n",
22
+ "\n",
23
+ "path = kagglehub.dataset_download(\"ANON_OWNER/q3-exam-data\")\n",
24
+ "\n",
25
+ "\n",
26
+ "\n",
27
+ "print(\"Path to dataset files:\", path)"
28
+ ],
29
+ "execution_count": null,
30
+ "outputs": []
31
+ },
32
+ {
33
+ "cell_type": "code",
34
+ "metadata": {},
35
+ "source": [
36
+ "# Task 1: Write your code here:\n",
37
+ "data_path = os.path.join(path, 'Q3_data.csv')\n",
38
+ "df_data = pd.read_csv(data_path)\n"
39
+ ],
40
+ "execution_count": null,
41
+ "outputs": []
42
+ },
43
+ {
44
+ "cell_type": "code",
45
+ "metadata": {},
46
+ "source": [
47
+ "# Task 2: Write your code here:\n",
48
+ "df_data.head()"
49
+ ],
50
+ "execution_count": null,
51
+ "outputs": []
52
+ },
53
+ {
54
+ "cell_type": "code",
55
+ "metadata": {},
56
+ "source": [
57
+ "# Task 3: Write your code here:\n",
58
+ "df_data.describe()"
59
+ ],
60
+ "execution_count": null,
61
+ "outputs": []
62
+ },
63
+ {
64
+ "cell_type": "code",
65
+ "metadata": {},
66
+ "source": [
67
+ "# Task 4: Write your code here:\n",
68
+ "df_data.info()"
69
+ ],
70
+ "execution_count": null,
71
+ "outputs": []
72
+ },
73
+ {
74
+ "cell_type": "code",
75
+ "metadata": {},
76
+ "source": [
77
+ "# Task 1: Write your code here:\n",
78
+ "df_clean = df_data.dropna()\n",
79
+ "df_clean"
80
+ ],
81
+ "execution_count": null,
82
+ "outputs": []
83
+ },
84
+ {
85
+ "cell_type": "code",
86
+ "metadata": {},
87
+ "source": [
88
+ "# Task 3: Write your code here:Check and remove duplicates if any exist\n",
89
+ "print(\"duplicate\", df_data.duplicated().sum())\n",
90
+ "df_clean = df_clean.drop_duplicates()\n",
91
+ "print(\"duplicate\", df_clean.duplicated().sum())\n",
92
+ "\n",
93
+ "\n",
94
+ "df_clean"
95
+ ],
96
+ "execution_count": null,
97
+ "outputs": []
98
+ },
99
+ {
100
+ "cell_type": "code",
101
+ "metadata": {},
102
+ "source": [
103
+ "# Task 3: Write your code here:Encode categorical variables if needed\n",
104
+ "df_clean.info()"
105
+ ],
106
+ "execution_count": null,
107
+ "outputs": []
108
+ },
109
+ {
110
+ "cell_type": "code",
111
+ "metadata": {},
112
+ "source": [
113
+ "# Task 4: Write your code here: Apply feature scaling to numerical features (Use StandardScaler)\n",
114
+ "# Scale features - fit on train, transform both\n",
115
+ "scaler = StandardScaler()\n",
116
+ "X_train_scaled = scaler.fit_transform(df_clean)\n",
117
+ "df_clean.dropna()\n",
118
+ "df_clean\n",
119
+ "\n"
120
+ ],
121
+ "execution_count": null,
122
+ "outputs": []
123
+ },
124
+ {
125
+ "cell_type": "code",
126
+ "metadata": {},
127
+ "source": [
128
+ "# Task 5: Write your code here:"
129
+ ],
130
+ "execution_count": null,
131
+ "outputs": []
132
+ },
133
+ {
134
+ "cell_type": "code",
135
+ "metadata": {},
136
+ "source": [
137
+ "# Task 1: Write your code here:"
138
+ ],
139
+ "execution_count": null,
140
+ "outputs": []
141
+ },
142
+ {
143
+ "cell_type": "code",
144
+ "metadata": {},
145
+ "source": [
146
+ "# Task 2,3,4,5: Write your code here:"
147
+ ],
148
+ "execution_count": null,
149
+ "outputs": []
150
+ },
151
+ {
152
+ "cell_type": "code",
153
+ "metadata": {},
154
+ "source": [
155
+ "# Task 1: Write your code here:"
156
+ ],
157
+ "execution_count": null,
158
+ "outputs": []
159
+ },
160
+ {
161
+ "cell_type": "code",
162
+ "metadata": {},
163
+ "source": [
164
+ "# Task 2: Write your code here:"
165
+ ],
166
+ "execution_count": null,
167
+ "outputs": []
168
+ },
169
+ {
170
+ "cell_type": "code",
171
+ "metadata": {},
172
+ "source": [
173
+ "# Task Bonus: Write your code here:"
174
+ ],
175
+ "execution_count": null,
176
+ "outputs": []
177
+ }
178
+ ],
179
+ "metadata": {
180
+ "kernelspec": {
181
+ "display_name": "Python 3",
182
+ "name": "python3"
183
+ },
184
+ "language_info": {
185
+ "name": "python"
186
+ }
187
+ },
188
+ "nbformat": 4,
189
+ "nbformat_minor": 0
190
+ }
submissions_extracted/1009/Q1.ipynb ADDED
@@ -0,0 +1,317 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "metadata": {},
6
+ "source": [
7
+ "import kagglehub\n",
8
+ "import pandas as pd\n",
9
+ "import numpy as np\n",
10
+ "import matplotlib.pyplot as plt\n",
11
+ "import seaborn as sns\n",
12
+ "import os\n",
13
+ "from tqdm import tqdm\n",
14
+ "\n",
15
+ "from sklearn.model_selection import train_test_split, KFold\n",
16
+ "from sklearn.preprocessing import StandardScaler, LabelEncoder\n",
17
+ "from sklearn.ensemble import RandomForestRegressor\n",
18
+ "from sklearn.metrics import mean_absolute_error, mean_squared_error\n",
19
+ "from sklearn.linear_model import LogisticRegression\n",
20
+ "\n",
21
+ "\n",
22
+ "\n",
23
+ "from lightgbm import LGBMClassifier\n",
24
+ "from xgboost import XGBClassifier\n",
25
+ "from sklearn.ensemble import RandomForestClassifier\n",
26
+ "from sklearn.ensemble import VotingClassifier\n",
27
+ "from sklearn.metrics import f1_score\n",
28
+ "\n",
29
+ "\n",
30
+ "# Download latest version\n",
31
+ "path = kagglehub.dataset_download(\"ANON_OWNER/q1-exam-data\")\n",
32
+ "\n",
33
+ "print(\"Path to dataset files:\", path)"
34
+ ],
35
+ "execution_count": null,
36
+ "outputs": []
37
+ },
38
+ {
39
+ "cell_type": "code",
40
+ "metadata": {},
41
+ "source": [
42
+ "# Task 1: Write your code here:\n",
43
+ "csv_path = os.path.join(path, \"Q1_data.csv\")\n",
44
+ "\n",
45
+ "df = pd.read_csv(csv_path)\n"
46
+ ],
47
+ "execution_count": null,
48
+ "outputs": []
49
+ },
50
+ {
51
+ "cell_type": "code",
52
+ "metadata": {},
53
+ "source": [
54
+ "# Task 2: Write your code here:\n",
55
+ "df.head()"
56
+ ],
57
+ "execution_count": null,
58
+ "outputs": []
59
+ },
60
+ {
61
+ "cell_type": "code",
62
+ "metadata": {},
63
+ "source": [
64
+ "# Task 3: Write your code here:\n",
65
+ "df.info()"
66
+ ],
67
+ "execution_count": null,
68
+ "outputs": []
69
+ },
70
+ {
71
+ "cell_type": "code",
72
+ "metadata": {},
73
+ "source": [
74
+ "# Task 4: Write your code here:\n",
75
+ "df.describe()"
76
+ ],
77
+ "execution_count": null,
78
+ "outputs": []
79
+ },
80
+ {
81
+ "cell_type": "code",
82
+ "metadata": {},
83
+ "source": [
84
+ "# Task 5: Write your code here:\n",
85
+ "def check_target_distribution(df, target_column):\n",
86
+ " df[target_column].hist(bins=30, edgecolor='black')\n",
87
+ "\n",
88
+ " plt.title(f\"Target Distribution ({target_column})\")\n",
89
+ " plt.xlabel(target_column)\n",
90
+ " plt.ylabel(\"Frequency\")\n",
91
+ " plt.grid(False)\n",
92
+ "\n",
93
+ " plt.show()\n",
94
+ "\n",
95
+ "check_target_distribution(df, \"delivery_time\")"
96
+ ],
97
+ "execution_count": null,
98
+ "outputs": []
99
+ },
100
+ {
101
+ "cell_type": "code",
102
+ "metadata": {},
103
+ "source": [
104
+ "# Task 1: Write your code here:\n",
105
+ "df = df.drop(columns=\"Order_ID\", axis=1)"
106
+ ],
107
+ "execution_count": null,
108
+ "outputs": []
109
+ },
110
+ {
111
+ "cell_type": "code",
112
+ "metadata": {},
113
+ "source": [
114
+ "# Task 2: Write your code here:\n",
115
+ "def check_missing_values(df):\n",
116
+ " missing_values = df.isnull().sum()\n",
117
+ " print(\"Missing Values per Column:\")\n",
118
+ " print(missing_values[missing_values > 0])\n",
119
+ " if missing_values.any():\n",
120
+ " print(\"\\nHandle Missing Values as needed.\")\n",
121
+ " else:\n",
122
+ " print(\"\\nNo Missing Values Found.\")\n",
123
+ "\n",
124
+ "check_missing_values(df)\n",
125
+ "\n",
126
+ "cols = ['Distance_km', 'Weather', 'Traffic_Level', 'Time_of_Day', 'Vehicle_Type','Preparation_Time_min', 'Courier_Experience_yrs', 'Delivery_Time']\n",
127
+ "df_clean = df[cols].copy()\n",
128
+ "df_clean = df_clean.dropna(subset=['Weather', 'Traffic_Level', 'Time_of_Day', 'Courier_Experience_yrs', 'Delivery_Time'])\n",
129
+ "print(f\"Shape after cleaning: {df_clean.shape}\")\n",
130
+ "\n",
131
+ "for col in ['Weather', 'Traffic_Level', 'Time_of_Day', 'Courier_Experience_yrs', 'Delivery_Time']:\n",
132
+ " df_clean[col] = df_clean[col].fillna('unknown')\n"
133
+ ],
134
+ "execution_count": null,
135
+ "outputs": []
136
+ },
137
+ {
138
+ "cell_type": "code",
139
+ "metadata": {},
140
+ "source": [
141
+ "# Task 3: Write your code here:\n",
142
+ "def check_duplicates(df_clean):\n",
143
+ " duplicates = df.duplicated().sum()\n",
144
+ " print(f\"Number of Duplicate Samples: {duplicates}\")\n",
145
+ " if duplicates > 0:\n",
146
+ " print(\"Dropping Duplicates...\")\n",
147
+ " df.drop_duplicates(inplace=True)\n",
148
+ " print(\"Duplicates Dropped.\")\n",
149
+ " else:\n",
150
+ " print(\"No Duplicate Samples Found.\")\n",
151
+ "\n",
152
+ "check_duplicates(df)"
153
+ ],
154
+ "execution_count": null,
155
+ "outputs": []
156
+ },
157
+ {
158
+ "cell_type": "code",
159
+ "metadata": {},
160
+ "source": [
161
+ "# Task 4: Write your code here:\n",
162
+ "categorical_cols = df.select_dtypes(include=[\"object\"]).columns\n",
163
+ "print(\"Categorical Columns:\", list(categorical_cols))\n",
164
+ "\n",
165
+ "ccategorical_cols = ['Weather', 'Traffic_Level', 'Time_of_Day', 'Vehicle_Type']\n",
166
+ "for col in ccategorical_cols:\n",
167
+ " le = LabelEncoder()\n",
168
+ " df_clean[col] = le.fit_transform(df_clean[col].astype(str))\n",
169
+ "\n",
170
+ "df_clean.head()"
171
+ ],
172
+ "execution_count": null,
173
+ "outputs": []
174
+ },
175
+ {
176
+ "cell_type": "code",
177
+ "metadata": {},
178
+ "source": [
179
+ "# Task 5: Write your code here:\n",
180
+ "standard_scaler = StandardScaler()\n",
181
+ "data_standard_scaled = standard_scaler.fit_transform(df_clean)"
182
+ ],
183
+ "execution_count": null,
184
+ "outputs": []
185
+ },
186
+ {
187
+ "cell_type": "code",
188
+ "metadata": {},
189
+ "source": [
190
+ "# Task 6: Write your code here:\n",
191
+ "def check_target_imbalance(df, target_column):\n",
192
+ " print(\"Target Distribution:\")\n",
193
+ " print(df[target_column].value_counts(normalize=True))\n",
194
+ " sns.countplot(x=df[target_column])\n",
195
+ " plt.title(\"Target Distribution\")\n",
196
+ " plt.show()\n",
197
+ "check_target_imbalance(df_clean, \"Delivery_Time\")\n",
198
+ "#Data is balanced"
199
+ ],
200
+ "execution_count": null,
201
+ "outputs": []
202
+ },
203
+ {
204
+ "cell_type": "code",
205
+ "metadata": {},
206
+ "source": [
207
+ "# Task 1: Write your code here:\n",
208
+ "X = df_clean.drop(\"Delivery_Time\", axis=1).astype(float)\n",
209
+ "y = df_clean['Delivery_Time'].astype(float)"
210
+ ],
211
+ "execution_count": null,
212
+ "outputs": []
213
+ },
214
+ {
215
+ "cell_type": "code",
216
+ "metadata": {},
217
+ "source": [
218
+ "# Task 2,3,4,5: Write your code here:\n",
219
+ "from sklearn.model_selection import KFold\n",
220
+ "from sklearn.metrics import mean_squared_error as sklearn_mse, mean_absolute_error, r2_score"
221
+ ],
222
+ "execution_count": null,
223
+ "outputs": []
224
+ },
225
+ {
226
+ "cell_type": "code",
227
+ "metadata": {},
228
+ "source": [
229
+ "majority_class = y.value_counts().idxmax()\n",
230
+ "baseline_pred = [majority_class] * len(y)\n",
231
+ "\n",
232
+ "# Evaluate the baseline\n",
233
+ "baseline_f1 = f1_score(y, baseline_pred, average='weighted')\n",
234
+ "print(f\"Baseline F1-Score (majority class): {baseline_f1:.4f}\")"
235
+ ],
236
+ "execution_count": null,
237
+ "outputs": []
238
+ },
239
+ {
240
+ "cell_type": "code",
241
+ "metadata": {},
242
+ "source": [
243
+ "models = {\n",
244
+ " \"Logistic Regression\": LogisticRegression(max_iter=10000),\n",
245
+ " \"Random Forest Classifier\": RandomForestClassifier(n_estimators=100),\n",
246
+ "}\n",
247
+ "\n",
248
+ "models[\"Ensemble\"] = VotingClassifier(estimators=[\n",
249
+ " ('rf', models[\"Logistic Regression\"]), ('gnb', models[\"Random Forest Classifier\"])], voting=\"soft\")\n",
250
+ "\n",
251
+ "for model_name, model in models.items():\n",
252
+ " scores_accuracy = []\n",
253
+ " scores_precision = []\n",
254
+ " scores_recall = []\n",
255
+ " scores_f1 = []\n",
256
+ "\n",
257
+ " # Stratified 5-Fold Cross-Validation\n",
258
+ " skf = KFold(n_splits=5)\n",
259
+ " for train_index, test_index in skf.split(X, y):\n",
260
+ " # Split data into training and testing sets\n",
261
+ " X_Train, X_Test = X.loc[train_index, :], X.loc[test_index, :]\n",
262
+ " y_Train, y_Test = y.iloc[train_index], y.iloc[test_index]\n",
263
+ " # Train the model\n",
264
+ " model.fit(X_Train, y_Train)\n",
265
+ " # Predict on the test set\n",
266
+ " y_pred = model.predict(X_Test)\n",
267
+ "\n",
268
+ " # Calculate metrics\n",
269
+ " scores_f1.append(f1_score(y_Test, y_pred, average='weighted'))\n",
270
+ "\n",
271
+ " # Print the results\n",
272
+ " print(f\"{model_name} F1-Score: {np.mean(scores_f1):.4f}\")\n",
273
+ " print(\"\\n\")"
274
+ ],
275
+ "execution_count": null,
276
+ "outputs": []
277
+ },
278
+ {
279
+ "cell_type": "code",
280
+ "metadata": {},
281
+ "source": [
282
+ "# Task 1: Write your code here:"
283
+ ],
284
+ "execution_count": null,
285
+ "outputs": []
286
+ },
287
+ {
288
+ "cell_type": "code",
289
+ "metadata": {},
290
+ "source": [
291
+ "# Task 2: Write your code here:"
292
+ ],
293
+ "execution_count": null,
294
+ "outputs": []
295
+ },
296
+ {
297
+ "cell_type": "code",
298
+ "metadata": {},
299
+ "source": [
300
+ "# Task Bonus: Write your code here:"
301
+ ],
302
+ "execution_count": null,
303
+ "outputs": []
304
+ }
305
+ ],
306
+ "metadata": {
307
+ "kernelspec": {
308
+ "display_name": "Python 3",
309
+ "name": "python3"
310
+ },
311
+ "language_info": {
312
+ "name": "python"
313
+ }
314
+ },
315
+ "nbformat": 4,
316
+ "nbformat_minor": 0
317
+ }
submissions_extracted/101/Q1.ipynb ADDED
@@ -0,0 +1,326 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "metadata": {},
6
+ "source": [
7
+ "import kagglehub\n",
8
+ "\n",
9
+ "# Download latest version\n",
10
+ "path = kagglehub.dataset_download(\"ANON_OWNER/q1-exam-data\")\n",
11
+ "\n",
12
+ "print(\"Path to dataset files:\", path)"
13
+ ],
14
+ "execution_count": null,
15
+ "outputs": []
16
+ },
17
+ {
18
+ "cell_type": "code",
19
+ "metadata": {},
20
+ "source": [
21
+ "import pandas as pd\n",
22
+ "import numpy as np\n",
23
+ "import matplotlib.pyplot as plt\n",
24
+ "import seaborn as sns\n",
25
+ "import kagglehub\n",
26
+ "import os\n",
27
+ "from tqdm import tqdm\n",
28
+ "\n",
29
+ "%matplotlib inline"
30
+ ],
31
+ "execution_count": null,
32
+ "outputs": []
33
+ },
34
+ {
35
+ "cell_type": "code",
36
+ "metadata": {},
37
+ "source": [
38
+ "# Task 1: Write your code here:\n",
39
+ "csv_path = os.path.join(path, \"Q1_data.csv\")\n",
40
+ "\n",
41
+ "df = pd.read_csv(csv_path)"
42
+ ],
43
+ "execution_count": null,
44
+ "outputs": []
45
+ },
46
+ {
47
+ "cell_type": "code",
48
+ "metadata": {},
49
+ "source": [
50
+ "# Task 2: Write your code here:\n",
51
+ "df.head()"
52
+ ],
53
+ "execution_count": null,
54
+ "outputs": []
55
+ },
56
+ {
57
+ "cell_type": "code",
58
+ "metadata": {},
59
+ "source": [
60
+ "# Task 3: Write your code here:\n",
61
+ "df.info()"
62
+ ],
63
+ "execution_count": null,
64
+ "outputs": []
65
+ },
66
+ {
67
+ "cell_type": "code",
68
+ "metadata": {},
69
+ "source": [
70
+ "# Task 4: Write your code here:\n",
71
+ "df.describe()"
72
+ ],
73
+ "execution_count": null,
74
+ "outputs": []
75
+ },
76
+ {
77
+ "cell_type": "code",
78
+ "metadata": {},
79
+ "source": [
80
+ "# Task 5: Write your code here:\n",
81
+ "def check_target_distribution(df, target_column):\n",
82
+ " df[target_column].hist(bins=30, edgecolor='black')\n",
83
+ "\n",
84
+ " plt.title(f\"Target Distribution ({target_column})\")\n",
85
+ " plt.xlabel(target_column)\n",
86
+ " plt.ylabel(\"Frequency\")\n",
87
+ " plt.grid(False)\n",
88
+ "\n",
89
+ " plt.show()\n",
90
+ "\n",
91
+ "check_target_distribution(df, \"Delivery_Time\")"
92
+ ],
93
+ "execution_count": null,
94
+ "outputs": []
95
+ },
96
+ {
97
+ "cell_type": "code",
98
+ "metadata": {},
99
+ "source": [
100
+ "# Task 1: Write your code here:\n",
101
+ "df = df.drop(columns=\"Order_ID\", axis=1)"
102
+ ],
103
+ "execution_count": null,
104
+ "outputs": []
105
+ },
106
+ {
107
+ "cell_type": "code",
108
+ "metadata": {},
109
+ "source": [
110
+ "df.isnull().sum()"
111
+ ],
112
+ "execution_count": null,
113
+ "outputs": []
114
+ },
115
+ {
116
+ "cell_type": "code",
117
+ "metadata": {},
118
+ "source": [
119
+ "# Task 2: Write your code here:\n",
120
+ "missing_percentage = (df.isnull().sum() / len(df)) * 100\n",
121
+ "missing_data = pd.DataFrame({\n",
122
+ " 'Column': missing_percentage.index,\n",
123
+ " 'Missing_Percentage': missing_percentage.values\n",
124
+ "})\n",
125
+ "missing_data = missing_data[missing_data['Missing_Percentage'] > 0].sort_values('Missing_Percentage', ascending=False)\n",
126
+ "\n",
127
+ "print(\"Missing Data Analysis:\")\n",
128
+ "missing_data.head(10)"
129
+ ],
130
+ "execution_count": null,
131
+ "outputs": []
132
+ },
133
+ {
134
+ "cell_type": "code",
135
+ "metadata": {},
136
+ "source": [
137
+ "#task2 cont. handeling the missing values\n",
138
+ "#missing categ\n",
139
+ "df['Weather'] = df['Weather'].fillna('none')\n",
140
+ "df['Traffic_Level'] = df['Traffic_Level'].fillna('none')\n",
141
+ "df['Time_of_Day'] = df['Time_of_Day'].fillna('none')\n",
142
+ "#fill numerical missing\n",
143
+ "df['Courier_Experience_yrs'] = df['Courier_Experience_yrs'].fillna('none')\n",
144
+ "df['Delivery_Time'] = df['Delivery_Time'].fillna('none')"
145
+ ],
146
+ "execution_count": null,
147
+ "outputs": []
148
+ },
149
+ {
150
+ "cell_type": "code",
151
+ "metadata": {},
152
+ "source": [
153
+ "# Task 3: Write your code here:\n",
154
+ "def check_duplicates(df):\n",
155
+ " duplicates = df.duplicated().sum()\n",
156
+ " print(f\"Number of Duplicate Samples: {duplicates}\")\n",
157
+ " if duplicates > 0:\n",
158
+ " print(\"Dropping Duplicates...\")\n",
159
+ " df.drop_duplicates(inplace=True)\n",
160
+ " print(\"Duplicates Dropped.\")\n",
161
+ " else:\n",
162
+ " print(\"No Duplicate Samples Found.\")\n",
163
+ "\n",
164
+ "check_duplicates(df)"
165
+ ],
166
+ "execution_count": null,
167
+ "outputs": []
168
+ },
169
+ {
170
+ "cell_type": "code",
171
+ "metadata": {},
172
+ "source": [
173
+ "# Task 4: Write your code here:\n",
174
+ "from sklearn.preprocessing import StandardScaler, LabelEncoder\n",
175
+ "categorical_cols = df.select_dtypes(include=[\"object\"]).columns\n",
176
+ "for col in categorical_cols:\n",
177
+ " le = LabelEncoder()\n",
178
+ " df[col] = le.fit_transform(df[col].astype(str))\n",
179
+ "\n",
180
+ "print(\"Categorical Columns:\", list(categorical_cols))\n",
181
+ "df.head()"
182
+ ],
183
+ "execution_count": null,
184
+ "outputs": []
185
+ },
186
+ {
187
+ "cell_type": "code",
188
+ "metadata": {},
189
+ "source": [
190
+ "# Task 5: Write your code here:\n",
191
+ "features = df.columns.drop(\"Delivery_Time\")\n",
192
+ "\n",
193
+ "scaler = StandardScaler()\n",
194
+ "df[features] = scaler.fit_transform(df[features])\n",
195
+ "df.head()"
196
+ ],
197
+ "execution_count": null,
198
+ "outputs": []
199
+ },
200
+ {
201
+ "cell_type": "code",
202
+ "metadata": {},
203
+ "source": [
204
+ "# Task 6: Write your code here:\n",
205
+ "#we dont need it cause its not classification but regression but i will do it to make sure\n",
206
+ "def check_target_imbalance(df, target_column):\n",
207
+ " print(\"Target Distribution:\")\n",
208
+ " print(df[\"Delivery_Time\"].value_counts(normalize=True))\n",
209
+ " sns.countplot(x=df[\"Delivery_Time\"])\n",
210
+ " plt.title(\"Target Distribution\")\n",
211
+ " plt.show()\n",
212
+ "\n",
213
+ "check_target_imbalance(df, \"status\")"
214
+ ],
215
+ "execution_count": null,
216
+ "outputs": []
217
+ },
218
+ {
219
+ "cell_type": "code",
220
+ "metadata": {},
221
+ "source": [
222
+ "# Task 1: Write your code here:\n",
223
+ "X = df.drop(\"Delivery_Time\",axis=1)\n",
224
+ "y = df['Delivery_Time']"
225
+ ],
226
+ "execution_count": null,
227
+ "outputs": []
228
+ },
229
+ {
230
+ "cell_type": "code",
231
+ "metadata": {},
232
+ "source": [
233
+ "# Task 2,3,4,5: Write your code here:\n",
234
+ "from sklearn.model_selection import KFold\n",
235
+ "from sklearn.metrics import mean_squared_error as sklearn_mse, mean_absolute_error, r2_score\n",
236
+ "from sklearn.ensemble import RandomForestRegressor\n",
237
+ "\n",
238
+ "n_splits = 5 # K=5 Folds\n",
239
+ "\n",
240
+ "# 5-Fold Cross-Validation, shuffled\n",
241
+ "kf = KFold(n_splits=n_splits, shuffle=True, random_state=42)\n",
242
+ "\n",
243
+ "# Storage for linear regression results for each fold\n",
244
+ "lr_losses = []\n",
245
+ "lr_mse = []\n",
246
+ "lr_rmse = []\n",
247
+ "lr_r2 = []\n",
248
+ "\n",
249
+ "for fold_idx, (train_index, test_index) in enumerate(kf.split(X)):\n",
250
+ " print(f\"\\nFold {fold_idx + 1}/{n_splits}\")\n",
251
+ "\n",
252
+ " X_train, X_test = X.iloc[train_index], X.iloc[test_index]\n",
253
+ " y_train, y_test = y.iloc[train_index], y.iloc[test_index]\n",
254
+ "\n",
255
+ " RF = RandomForestRegressor(n_estimators=200)\n",
256
+ "\n",
257
+ " # Train\n",
258
+ " RF.fit(X_train, y_train)\n",
259
+ "\n",
260
+ " # Validate\n",
261
+ " y_pred = RF.predict(X_test)\n",
262
+ "\n",
263
+ " # Calculate evaluation metrics\n",
264
+ " mse = sklearn_mse(y_test, y_pred)\n",
265
+ " rmse = np.sqrt(mse)\n",
266
+ " r2 = r2_score(y_test, y_pred)\n",
267
+ "\n",
268
+ " # Store results\n",
269
+ " lr_mse.append(mse)\n",
270
+ " lr_rmse.append(rmse)\n",
271
+ " lr_r2.append(r2)"
272
+ ],
273
+ "execution_count": null,
274
+ "outputs": []
275
+ },
276
+ {
277
+ "cell_type": "code",
278
+ "metadata": {},
279
+ "source": [
280
+ "# Task 1: Write your code here:\n",
281
+ "importance = pd.DataFrame({\n",
282
+ " 'feature': features,\n",
283
+ " 'importance': RF.feature_importances_\n",
284
+ "}).sort_values('importance', ascending=False)\n",
285
+ "\n",
286
+ "plt.figure(figsize=(10, 6))\n",
287
+ "plt.barh(importance['feature'], importance['importance'], color='purple')\n",
288
+ "plt.xlabel('Importance')\n",
289
+ "plt.title('Feature Importance')\n",
290
+ "plt.gca().invert_yaxis()\n",
291
+ "plt.show()"
292
+ ],
293
+ "execution_count": null,
294
+ "outputs": []
295
+ },
296
+ {
297
+ "cell_type": "code",
298
+ "metadata": {},
299
+ "source": [
300
+ "# Task 2: Write your code here:"
301
+ ],
302
+ "execution_count": null,
303
+ "outputs": []
304
+ },
305
+ {
306
+ "cell_type": "code",
307
+ "metadata": {},
308
+ "source": [
309
+ "# Task Bonus: Write your code here:"
310
+ ],
311
+ "execution_count": null,
312
+ "outputs": []
313
+ }
314
+ ],
315
+ "metadata": {
316
+ "kernelspec": {
317
+ "display_name": "Python 3",
318
+ "name": "python3"
319
+ },
320
+ "language_info": {
321
+ "name": "python"
322
+ }
323
+ },
324
+ "nbformat": 4,
325
+ "nbformat_minor": 0
326
+ }
submissions_extracted/101/Q2.ipynb ADDED
@@ -0,0 +1,386 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "metadata": {},
6
+ "source": [
7
+ "import kagglehub\n",
8
+ "\n",
9
+ "# Download latest version\n",
10
+ "path = kagglehub.dataset_download(\"ANON_OWNER/q2-exam-data\")\n",
11
+ "\n",
12
+ "print(\"Path to dataset files:\", path)"
13
+ ],
14
+ "execution_count": null,
15
+ "outputs": []
16
+ },
17
+ {
18
+ "cell_type": "code",
19
+ "metadata": {},
20
+ "source": [
21
+ "import os\n",
22
+ "import pandas as pd\n",
23
+ "import numpy as np\n",
24
+ "from PIL import Image\n",
25
+ "from sklearn.model_selection import train_test_split\n",
26
+ "\n",
27
+ "# Load Labels\n",
28
+ "labels_df = pd.read_csv(os.path.join(path, \"labels.csv\"))\n",
29
+ "img_dir = os.path.join(path, \"images\")\n",
30
+ "\n",
31
+ "images = []\n",
32
+ "ages = []\n",
33
+ "\n",
34
+ "# Load Images and Resize\n",
35
+ "print(\"Loading images...\")\n",
36
+ "for index, row in labels_df.iterrows():\n",
37
+ " img_name = row.iloc[0]\n",
38
+ " age = row.iloc[1]\n",
39
+ " img_path = os.path.join(img_dir, img_name)\n",
40
+ "\n",
41
+ " if os.path.exists(img_path):\n",
42
+ " img = Image.open(img_path).convert('RGB')\n",
43
+ " img_array = np.array(img) / 255.0 # Normalize pixel values to [0, 1]\n",
44
+ " images.append(img_array)\n",
45
+ " ages.append(age)\n",
46
+ "\n",
47
+ "X = np.array(images)\n",
48
+ "y = np.array(ages)\n",
49
+ "\n",
50
+ "# Transpose image dimensions to match PyTorch format (N, C, H, W)\n",
51
+ "X = np.transpose(X, (0, 3, 1, 2))\n",
52
+ "\n",
53
+ "# Split Data\n",
54
+ "X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)\n",
55
+ "\n",
56
+ "print(f\"X_train shape: {X_train.shape}\")\n",
57
+ "print(f\"X_test shape: {X_test.shape}\")\n",
58
+ "print(f\"y_train shape: {y_train.shape}\")\n",
59
+ "print(f\"y_test shape: {y_test.shape}\")"
60
+ ],
61
+ "execution_count": null,
62
+ "outputs": []
63
+ },
64
+ {
65
+ "cell_type": "code",
66
+ "metadata": {},
67
+ "source": [
68
+ "import torch\n",
69
+ "import torch.nn as nn\n",
70
+ "from torch.utils.data import DataLoader\n",
71
+ "from torch.optim import Adam\n",
72
+ "from torchvision.transforms.functional import to_tensor\n",
73
+ "import torch.nn.functional as F\n",
74
+ "import matplotlib.pyplot as plt"
75
+ ],
76
+ "execution_count": null,
77
+ "outputs": []
78
+ },
79
+ {
80
+ "cell_type": "code",
81
+ "metadata": {},
82
+ "source": [
83
+ "# 1. Convert Numpy arrays to PyTorch Tensors\n",
84
+ "X_train = torch.tensor(X_train, dtype=torch.float32)\n",
85
+ "X_test = torch.tensor(X_test, dtype=torch.float32)\n",
86
+ "y_train = torch.tensor(y_train, dtype=torch.float32)\n",
87
+ "y_test = torch.tensor(y_test, dtype=torch.float32)"
88
+ ],
89
+ "execution_count": null,
90
+ "outputs": []
91
+ },
92
+ {
93
+ "cell_type": "code",
94
+ "metadata": {},
95
+ "source": [
96
+ "# 2. Create TensorDataset objects\n",
97
+ "from torch.utils.data import TensorDataset\n",
98
+ "train_dataset = TensorDataset(X_train, y_train)\n",
99
+ "test_dataset = TensorDataset(X_test, y_test)\n"
100
+ ],
101
+ "execution_count": null,
102
+ "outputs": []
103
+ },
104
+ {
105
+ "cell_type": "code",
106
+ "metadata": {},
107
+ "source": [
108
+ "# 3. Create DataLoaders\n",
109
+ "train_loader = DataLoader(\n",
110
+ " train_dataset,\n",
111
+ " batch_size=32,\n",
112
+ " shuffle=True,\n",
113
+ " num_workers=2\n",
114
+ ")\n",
115
+ "# DataLoader for test/validation data\n",
116
+ "test_loader = DataLoader(\n",
117
+ " test_dataset,\n",
118
+ " batch_size=32,\n",
119
+ " shuffle=False,\n",
120
+ " num_workers=2\n",
121
+ ")\n",
122
+ "# Get the first batch from the training DataLoader\n",
123
+ "X_batch, y_batch = next(iter(train_loader))\n",
124
+ "print(f\"Training batch input shape: {X_batch.shape}\")\n",
125
+ "print(f\"Training batch labels shape: {y_batch.shape}\")\n",
126
+ "\n"
127
+ ],
128
+ "execution_count": null,
129
+ "outputs": []
130
+ },
131
+ {
132
+ "cell_type": "code",
133
+ "metadata": {},
134
+ "source": [
135
+ "# 4. Print shape of one batch\n",
136
+ "first_sample, _ = train_dataset[0]\n",
137
+ "print(f\"Shape of one sample: {first_sample.shape}\")\n"
138
+ ],
139
+ "execution_count": null,
140
+ "outputs": []
141
+ },
142
+ {
143
+ "cell_type": "code",
144
+ "metadata": {},
145
+ "source": [
146
+ "# 5. Display sample images\n",
147
+ "# Get one batch of images and labels\n",
148
+ "images, labels = next(iter(train_loader))\n",
149
+ "\n",
150
+ "# Display the first 6 images in the batch\n",
151
+ "plt.figure(figsize=(8, 4))\n",
152
+ "\n",
153
+ "for i in range(6):\n",
154
+ " plt.subplot(2, 3, i + 1)\n",
155
+ " plt.imshow(images[i].squeeze(), cmap='gray')\n",
156
+ " plt.title(f\"Label: {labels[i].item()}\")\n",
157
+ " plt.axis('off')\n",
158
+ "\n",
159
+ "plt.tight_layout()\n",
160
+ "plt.show()\n"
161
+ ],
162
+ "execution_count": null,
163
+ "outputs": []
164
+ },
165
+ {
166
+ "cell_type": "code",
167
+ "metadata": {},
168
+ "source": [
169
+ "# Task 1: Write your model class here:\n",
170
+ "class NN3Layer(nn.Module):\n",
171
+ "\n",
172
+ " def __init__(self, input_dim, hidden_dim, output_dim):\n",
173
+ " super(NN3Layer, self).__init__()\n",
174
+ "\n",
175
+ " # First linear layer: input features -> hidden layer\n",
176
+ " self.layer1 = nn.Linear(input_dim, hidden_dim)\n",
177
+ "\n",
178
+ " # Second linear layer: hidden layer -> hidden layer\n",
179
+ " self.layer2 = nn.Linear(hidden_dim, hidden_dim)\n",
180
+ "\n",
181
+ " # Output layer: hidden layer -> number of classes (logits)\n",
182
+ " self.layer3 = nn.Linear(hidden_dim, output_dim)\n",
183
+ "\n",
184
+ " # ReLU activation for non-linearity\n",
185
+ " self.relu = nn.ReLU()\n",
186
+ "\n",
187
+ " # Defines how input data flows through the network\n",
188
+ " def forward(self, x):\n",
189
+ " # First hidden layer\n",
190
+ " z1 = self.layer1(x)\n",
191
+ " a1 = self.relu(z1)\n",
192
+ "\n",
193
+ " # Second hidden layer\n",
194
+ " z2 = self.layer2(a1)\n",
195
+ " a2 = self.relu(z2)\n",
196
+ "\n",
197
+ " # Output layer (raw scores / logits)\n",
198
+ " output = self.layer3(a2) # there is something missing here, remember? :)\n",
199
+ "\n",
200
+ " return output\n"
201
+ ],
202
+ "execution_count": null,
203
+ "outputs": []
204
+ },
205
+ {
206
+ "cell_type": "code",
207
+ "metadata": {},
208
+ "source": [
209
+ "# Task 2: Write your training loop here:\n",
210
+ "def train_one_epoch(model, optimizer, criterion, train_loader, device):\n",
211
+ " # Set the model to training mode\n",
212
+ " model.train()\n",
213
+ "\n",
214
+ " running_loss = 0.0\n",
215
+ "\n",
216
+ " for X_batch, y_batch in train_loader:\n",
217
+ " # Move batch to the selected device\n",
218
+ " X_batch = X_batch.view(X_batch.size(0), -1).to(device)\n",
219
+ " y_batch = y_batch.to(device)\n",
220
+ "\n",
221
+ " # Forward pass\n",
222
+ " outputs = model(X_batch) # shape: (batch_size, 10)\n",
223
+ " loss = criterion(outputs, y_batch)\n",
224
+ "\n",
225
+ " # Backward pass & optimization\n",
226
+ " optimizer.zero_grad() # Clear previous gradients\n",
227
+ " loss.backward() # Compute gradients\n",
228
+ " optimizer.step() # Update model parameters\n",
229
+ "\n",
230
+ " running_loss += loss.item()\n",
231
+ "\n",
232
+ " # Average loss over all batches\n",
233
+ " avg_loss = running_loss / len(train_loader)\n",
234
+ "\n",
235
+ " return avg_loss"
236
+ ],
237
+ "execution_count": null,
238
+ "outputs": []
239
+ },
240
+ {
241
+ "cell_type": "code",
242
+ "metadata": {},
243
+ "source": [
244
+ "# Task 3: Write your validation loop here:\n",
245
+ "def validate(model, criterion, test_loader, device):\n",
246
+ " # Set the model to evaluation mode\n",
247
+ " model.eval()\n",
248
+ "\n",
249
+ " running_loss = 0.0\n",
250
+ " correct = 0\n",
251
+ " total = 0\n",
252
+ "\n",
253
+ " with torch.no_grad():\n",
254
+ " for X_batch, y_batch in test_loader:\n",
255
+ " # Move data to device\n",
256
+ " X_batch = X_batch.view(X_batch.size(0), -1).to(device)\n",
257
+ " y_batch = y_batch.to(device)\n",
258
+ "\n",
259
+ " # Forward pass\n",
260
+ " outputs = model(X_batch) # shape: (batch_size, 10)\n",
261
+ " loss = criterion(outputs, y_batch)\n",
262
+ " running_loss += loss.item()\n",
263
+ "\n",
264
+ " # Apply Softmax to get probabilities\n",
265
+ " probabilities = F.softmax(outputs, dim=1)\n",
266
+ "\n",
267
+ " # Multiclass predictions\n",
268
+ " predicted = torch.argmax(probabilities, dim=1)\n",
269
+ "\n",
270
+ " # Accuracy calculation\n",
271
+ " correct += (predicted == y_batch).sum().item()\n",
272
+ " total += y_batch.size(0)\n",
273
+ "\n",
274
+ " avg_loss = running_loss / len(test_loader)\n",
275
+ " accuracy = correct / total\n",
276
+ "\n",
277
+ " return avg_loss, accuracy\n"
278
+ ],
279
+ "execution_count": null,
280
+ "outputs": []
281
+ },
282
+ {
283
+ "cell_type": "code",
284
+ "metadata": {},
285
+ "source": [
286
+ "# Task 4: Define device, model, loss, optimizer:\n",
287
+ "# Device setup\n",
288
+ "device = torch.device(\"cuda\" if torch.cuda.is_available() else \"cpu\")\n",
289
+ "\n",
290
+ "# Model parameters\n",
291
+ "input_dim = 36 * 36\n",
292
+ "hidden_dim = 15\n",
293
+ "output_dim = 1\n",
294
+ "\n",
295
+ "# Instantiate model\n",
296
+ "model = NN3Layer(input_dim, hidden_dim, output_dim).to(device)\n",
297
+ "\n",
298
+ "# Print the model architecture\n",
299
+ "print(\"Model Architecture:\\n\")\n",
300
+ "print(model)\n",
301
+ "\n",
302
+ "# Calculate the total number of trainable parameters\n",
303
+ "total_params = sum(p.numel() for p in model.parameters() if p.requires_grad)\n",
304
+ "print(f\"\\nTotal trainable parameters: {total_params}\")"
305
+ ],
306
+ "execution_count": null,
307
+ "outputs": []
308
+ },
309
+ {
310
+ "cell_type": "code",
311
+ "metadata": {},
312
+ "source": [
313
+ "# Task 5: Start training for 20 epochs:\n",
314
+ "num_epochs = 20\n",
315
+ "learning_rate = 0.001\n",
316
+ "\n",
317
+ "# Define criterion (loss function) - using CrossEntropyLoss as model now outputs logits\n",
318
+ "criterion = nn.CrossEntropyLoss()\n",
319
+ "# Define optimizer\n",
320
+ "optimizer = Adam(model.parameters(), learning_rate)\n",
321
+ "# Run Training\n",
322
+ "train_losses = []\n",
323
+ "val_losses = []\n",
324
+ "val_accuracies = []\n",
325
+ "\n",
326
+ "print('Starting Training...')\n",
327
+ "for epoch in range(num_epochs):\n",
328
+ " # Train one epoch\n",
329
+ " train_loss = train_one_epoch(model, optimizer, criterion, train_loader, device)\n",
330
+ "\n",
331
+ " # Validate\n",
332
+ " val_loss, val_accuracy = validate(model, criterion, test_loader, device)\n",
333
+ "\n",
334
+ " train_losses.append(train_loss)\n",
335
+ " val_losses.append(val_loss)\n",
336
+ " val_accuracies.append(val_accuracy)\n",
337
+ "\n",
338
+ " print(f'Epoch [{epoch+1}/{num_epochs}], Train Loss: {train_loss:.4f}, Val Loss: {val_loss:.4f}, Val Accuracy: {val_accuracy:.4f}')\n",
339
+ "\n",
340
+ "print('Training Complete!')"
341
+ ],
342
+ "execution_count": null,
343
+ "outputs": []
344
+ },
345
+ {
346
+ "cell_type": "code",
347
+ "metadata": {},
348
+ "source": [
349
+ "# Task 1: Write your code here:\n",
350
+ "plt.figure(figsize=(7, 5))\n",
351
+ "\n",
352
+ "plt.plot(train_losses, label='Train Loss')\n",
353
+ "plt.plot(val_losses, label='Validation Loss')\n",
354
+ "plt.title('Loss over Epochs')\n",
355
+ "plt.xlabel('Epoch')\n",
356
+ "plt.ylabel('Loss')\n",
357
+ "plt.legend()\n",
358
+ "\n",
359
+ "plt.tight_layout()\n",
360
+ "plt.show()"
361
+ ],
362
+ "execution_count": null,
363
+ "outputs": []
364
+ },
365
+ {
366
+ "cell_type": "code",
367
+ "metadata": {},
368
+ "source": [
369
+ "# Task 2 (Bonus): Write your code here:"
370
+ ],
371
+ "execution_count": null,
372
+ "outputs": []
373
+ }
374
+ ],
375
+ "metadata": {
376
+ "kernelspec": {
377
+ "display_name": "Python 3",
378
+ "name": "python3"
379
+ },
380
+ "language_info": {
381
+ "name": "python"
382
+ }
383
+ },
384
+ "nbformat": 4,
385
+ "nbformat_minor": 0
386
+ }
submissions_extracted/101/Q3.ipynb ADDED
@@ -0,0 +1,318 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "metadata": {},
6
+ "source": [
7
+ "import pandas as pd\n",
8
+ "import numpy as np\n",
9
+ "import matplotlib.pyplot as plt\n",
10
+ "import seaborn as sns\n",
11
+ "import kagglehub\n",
12
+ "import os\n",
13
+ "from tqdm import tqdm\n",
14
+ "\n",
15
+ "%matplotlib inline"
16
+ ],
17
+ "execution_count": null,
18
+ "outputs": []
19
+ },
20
+ {
21
+ "cell_type": "code",
22
+ "metadata": {},
23
+ "source": [
24
+ "import kagglehub\n",
25
+ "\n",
26
+ "\n",
27
+ "\n",
28
+ "# Download latest version\n",
29
+ "\n",
30
+ "path = kagglehub.dataset_download(\"ANON_OWNER/q3-exam-data\")\n",
31
+ "\n",
32
+ "\n",
33
+ "\n",
34
+ "print(\"Path to dataset files:\", path)"
35
+ ],
36
+ "execution_count": null,
37
+ "outputs": []
38
+ },
39
+ {
40
+ "cell_type": "code",
41
+ "metadata": {},
42
+ "source": [
43
+ "# Task 1: Write your code here:\n",
44
+ "csv_path = os.path.join(path, \"Q3_data.csv\")\n",
45
+ "\n",
46
+ "df = pd.read_csv(csv_path)"
47
+ ],
48
+ "execution_count": null,
49
+ "outputs": []
50
+ },
51
+ {
52
+ "cell_type": "code",
53
+ "metadata": {},
54
+ "source": [
55
+ "# Task 2: Write your code here:\n",
56
+ "df.head()"
57
+ ],
58
+ "execution_count": null,
59
+ "outputs": []
60
+ },
61
+ {
62
+ "cell_type": "code",
63
+ "metadata": {},
64
+ "source": [
65
+ "# Task 3: Write your code here:\n",
66
+ "df.info()"
67
+ ],
68
+ "execution_count": null,
69
+ "outputs": []
70
+ },
71
+ {
72
+ "cell_type": "code",
73
+ "metadata": {},
74
+ "source": [
75
+ "# Task 4: Write your code here:\n",
76
+ "df.describe()"
77
+ ],
78
+ "execution_count": null,
79
+ "outputs": []
80
+ },
81
+ {
82
+ "cell_type": "code",
83
+ "metadata": {},
84
+ "source": [
85
+ "df.columns"
86
+ ],
87
+ "execution_count": null,
88
+ "outputs": []
89
+ },
90
+ {
91
+ "cell_type": "code",
92
+ "metadata": {},
93
+ "source": [
94
+ "# Task 1: Write your code here:\n",
95
+ "def check_missing_values(df):\n",
96
+ " missing_values = df.isnull().sum()\n",
97
+ " print(\"Missing Values per Column:\")\n",
98
+ " print(missing_values[missing_values > 0])\n",
99
+ " if missing_values.any():\n",
100
+ " print(\"\\nHandle Missing Values as needed.\")\n",
101
+ " else:\n",
102
+ " print(\"\\nNo Missing Values Found.\")\n",
103
+ "\n",
104
+ "check_missing_values(df)"
105
+ ],
106
+ "execution_count": null,
107
+ "outputs": []
108
+ },
109
+ {
110
+ "cell_type": "code",
111
+ "metadata": {},
112
+ "source": [
113
+ "# Task 2: Write your code here:\n",
114
+ "def check_duplicates(df):\n",
115
+ " duplicates = df.duplicated().sum()\n",
116
+ " print(f\"Number of Duplicate Samples: {duplicates}\")\n",
117
+ " if duplicates > 0:\n",
118
+ " print(\"Dropping Duplicates...\")\n",
119
+ " df.drop_duplicates(inplace=True)\n",
120
+ " print(\"Duplicates Dropped.\")\n",
121
+ " else:\n",
122
+ " print(\"No Duplicate Samples Found.\")\n",
123
+ "\n",
124
+ "check_duplicates(df)"
125
+ ],
126
+ "execution_count": null,
127
+ "outputs": []
128
+ },
129
+ {
130
+ "cell_type": "code",
131
+ "metadata": {},
132
+ "source": [
133
+ "# Task 3: Write your code here:\n",
134
+ "categorical_cols = df.select_dtypes(include=[\"object\"]).columns\n",
135
+ "\n",
136
+ "print(\"Categorical Columns:\", list(categorical_cols))"
137
+ ],
138
+ "execution_count": null,
139
+ "outputs": []
140
+ },
141
+ {
142
+ "cell_type": "code",
143
+ "metadata": {},
144
+ "source": [
145
+ "# Task 4: Write your code here:\n",
146
+ "from sklearn.preprocessing import StandardScaler\n",
147
+ "\n",
148
+ "numerical_cols = df.select_dtypes(include=[\"int64\", \"float64\"]).columns.drop(\"Target\")\n",
149
+ "\n",
150
+ "scaler = StandardScaler()\n",
151
+ "df[numerical_cols] = scaler.fit_transform(df[numerical_cols])\n",
152
+ "df.head()\n"
153
+ ],
154
+ "execution_count": null,
155
+ "outputs": []
156
+ },
157
+ {
158
+ "cell_type": "code",
159
+ "metadata": {},
160
+ "source": [
161
+ "# Task 5: Write your code here:\n",
162
+ "def check_target_imbalance(df, Target):\n",
163
+ " print(\"Target Distribution:\")\n",
164
+ " print(df[\"Target\"].value_counts(normalize=True))\n",
165
+ " sns.countplot(x=df[\"Target\"])\n",
166
+ " plt.title(\"Target Distribution\")\n",
167
+ " plt.show()\n",
168
+ "\n",
169
+ "check_target_imbalance(df, \"status\")"
170
+ ],
171
+ "execution_count": null,
172
+ "outputs": []
173
+ },
174
+ {
175
+ "cell_type": "code",
176
+ "metadata": {},
177
+ "source": [
178
+ "# Task 1: Write your code here:\n",
179
+ "X = df.drop(\"Target\",axis=1)\n",
180
+ "y = df['Target']"
181
+ ],
182
+ "execution_count": null,
183
+ "outputs": []
184
+ },
185
+ {
186
+ "cell_type": "code",
187
+ "metadata": {},
188
+ "source": [
189
+ "!pip install catboost"
190
+ ],
191
+ "execution_count": null,
192
+ "outputs": []
193
+ },
194
+ {
195
+ "cell_type": "code",
196
+ "metadata": {},
197
+ "source": [
198
+ "# Task 2,3,4,5: Write your code here:\n",
199
+ "from catboost import CatBoostClassifier\n",
200
+ "from sklearn.model_selection import StratifiedKFold\n",
201
+ "from sklearn.metrics import accuracy_score, precision_score, recall_score, f1_score\n",
202
+ "sklearn_model = {\n",
203
+ " \"CatBoost\": CatBoostClassifier(\n",
204
+ " verbose=0,\n",
205
+ " n_estimators=320,\n",
206
+ " max_depth=4\n",
207
+ " )\n",
208
+ "}\n",
209
+ "all_results = {}\n",
210
+ "\n",
211
+ "for name in sklearn_model:\n",
212
+ " all_results[name] = {'accuracy': [], 'precision': [], 'recall': [], 'f1': []}\n",
213
+ "n_splits = 5 # K\n",
214
+ "\n",
215
+ "# Stratified 5-Fold Cross-Validation, shuffled\n",
216
+ "skf = StratifiedKFold(n_splits=n_splits, shuffle=True, random_state=42)\n",
217
+ "for fold_idx, (train_index, test_index) in enumerate(skf.split(X, y)):\n",
218
+ " print(f\"\\nFold {fold_idx + 1}/{n_splits}\")\n",
219
+ "\n",
220
+ " # 1. Split data\n",
221
+ " X_train, X_test = X.iloc[train_index], X.iloc[test_index]\n",
222
+ " y_train, y_test = y.iloc[train_index], y.iloc[test_index]\n",
223
+ "\n",
224
+ " # 2. Train & Validate sklearn models\n",
225
+ " for model_name, model in sklearn_model.items():\n",
226
+ " print(f\"Training {model_name}...\")\n",
227
+ " model.fit(X_train, y_train) # train\n",
228
+ " y_pred = model.predict(X_test) # validate\n",
229
+ "\n",
230
+ " # 3. Save metrics for that model in this fold\n",
231
+ " accuracy = accuracy_score(y_test, y_pred)\n",
232
+ " precision = precision_score(y_test, y_pred, zero_division=0)\n",
233
+ " recall = recall_score(y_test, y_pred, zero_division=0)\n",
234
+ " f1 = f1_score(y_test, y_pred, zero_division=0)\n",
235
+ "\n",
236
+ " all_results[model_name]['accuracy'].append(accuracy)\n",
237
+ " all_results[model_name]['precision'].append(precision)\n",
238
+ " all_results[model_name]['recall'].append(recall)\n",
239
+ " all_results[model_name]['f1'].append(f1)"
240
+ ],
241
+ "execution_count": null,
242
+ "outputs": []
243
+ },
244
+ {
245
+ "cell_type": "code",
246
+ "metadata": {},
247
+ "source": [
248
+ "for model_name in all_results:\n",
249
+ " print(f\"\\n{model_name}:\")\n",
250
+ " print(f\" Accuracy: {np.mean(all_results[model_name]['accuracy']):.4f}\")\n",
251
+ " print(f\" Precision: {np.mean(all_results[model_name]['precision']):.4f}\")\n",
252
+ " print(f\" Recall: {np.mean(all_results[model_name]['recall']):.4f}\")\n",
253
+ " print(f\" F1-Score: {np.mean(all_results[model_name]['f1']):.4f}\")"
254
+ ],
255
+ "execution_count": null,
256
+ "outputs": []
257
+ },
258
+ {
259
+ "cell_type": "code",
260
+ "metadata": {},
261
+ "source": [
262
+ "# Task 1: Write your code here:\n",
263
+ "importances = {}\n",
264
+ "\n",
265
+ "importances['CatBoost'] = sklearn_model['CatBoost'].feature_importances_\n",
266
+ "\n",
267
+ "# Create a 1x3 plot\n",
268
+ "fig, axes = plt.subplots(1, 2, figsize=(15, 12))\n",
269
+ "axes = axes.flatten()\n",
270
+ "features = X.columns\n",
271
+ "\n",
272
+ "for i, (model_name, imp) in enumerate(importances.items()):\n",
273
+ " # Sort features by importance for a cleaner plot\n",
274
+ " sorted_idx = np.argsort(imp)\n",
275
+ "\n",
276
+ " ax = axes[i]\n",
277
+ " ax.barh(features[sorted_idx], imp[sorted_idx])\n",
278
+ " ax.set_title(f\"{model_name} Feature Importance\")\n",
279
+ " ax.set_xlabel(\"Importance Score\")\n",
280
+ "\n",
281
+ "plt.tight_layout()\n",
282
+ "plt.show()"
283
+ ],
284
+ "execution_count": null,
285
+ "outputs": []
286
+ },
287
+ {
288
+ "cell_type": "code",
289
+ "metadata": {},
290
+ "source": [
291
+ "# Task 2: Write your code here:\n",
292
+ "print(\"the most important feature is: P_2 \")"
293
+ ],
294
+ "execution_count": null,
295
+ "outputs": []
296
+ },
297
+ {
298
+ "cell_type": "code",
299
+ "metadata": {},
300
+ "source": [
301
+ "# Task Bonus: Write your code here:"
302
+ ],
303
+ "execution_count": null,
304
+ "outputs": []
305
+ }
306
+ ],
307
+ "metadata": {
308
+ "kernelspec": {
309
+ "display_name": "Python 3",
310
+ "name": "python3"
311
+ },
312
+ "language_info": {
313
+ "name": "python"
314
+ }
315
+ },
316
+ "nbformat": 4,
317
+ "nbformat_minor": 0
318
+ }
submissions_extracted/1010/Q1.ipynb ADDED
@@ -0,0 +1,289 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "metadata": {},
6
+ "source": [
7
+ "import kagglehub\n",
8
+ "\n",
9
+ "\n",
10
+ "# Download latest version\n",
11
+ "path = kagglehub.dataset_download(\"ANON_OWNER/q1-exam-data\")\n",
12
+ "\n",
13
+ "print(\"Path to dataset files:\", path)"
14
+ ],
15
+ "execution_count": null,
16
+ "outputs": []
17
+ },
18
+ {
19
+ "cell_type": "code",
20
+ "metadata": {},
21
+ "source": [
22
+ "import numpy as np\n",
23
+ "import pandas as pd\n",
24
+ "import matplotlib.pyplot as plt\n",
25
+ "import os\n",
26
+ "import kagglehub\n",
27
+ "import seaborn as sns\n",
28
+ "import matplotlib.pyplot as plt\n",
29
+ "\n",
30
+ "\n",
31
+ "from sklearn.model_selection import train_test_split, StratifiedKFold, cross_val_score\n",
32
+ "from sklearn.preprocessing import StandardScaler, LabelEncoder\n",
33
+ "from sklearn.ensemble import RandomForestClassifier\n",
34
+ "from sklearn.metrics import classification_report, confusion_matrix, accuracy_score\n",
35
+ "\n",
36
+ "import warnings\n",
37
+ "warnings.filterwarnings('ignore')\n"
38
+ ],
39
+ "execution_count": null,
40
+ "outputs": []
41
+ },
42
+ {
43
+ "cell_type": "code",
44
+ "metadata": {},
45
+ "source": [
46
+ "# Task 1: Write your code here:\n",
47
+ "csv_path = os.path.join(path, \"Q1_data.csv\")\n",
48
+ "df = pd.read_csv(csv_path)\n"
49
+ ],
50
+ "execution_count": null,
51
+ "outputs": []
52
+ },
53
+ {
54
+ "cell_type": "code",
55
+ "metadata": {},
56
+ "source": [
57
+ "# Task 2: Write your code here:\n",
58
+ "print(\"\\n--- Task 3: Dataset Information ---\")\n",
59
+ "df.info()"
60
+ ],
61
+ "execution_count": null,
62
+ "outputs": []
63
+ },
64
+ {
65
+ "cell_type": "code",
66
+ "metadata": {},
67
+ "source": [
68
+ "# Task 3: Write your code here:\n",
69
+ "print(\"\\n--- Task 4: Statistical Description ---\")\n",
70
+ "print(df.describe())\n"
71
+ ],
72
+ "execution_count": null,
73
+ "outputs": []
74
+ },
75
+ {
76
+ "cell_type": "code",
77
+ "metadata": {},
78
+ "source": [
79
+ "# Task 4: Write your code here:\n",
80
+ "print(\"\\n--- Task 4: Statistical Description ---\")\n",
81
+ "print(df.describe())"
82
+ ],
83
+ "execution_count": null,
84
+ "outputs": []
85
+ },
86
+ {
87
+ "cell_type": "code",
88
+ "metadata": {},
89
+ "source": [
90
+ "# Task 5: Write your code here:\n",
91
+ "import seaborn as sns\n",
92
+ "import matplotlib.pyplot as plt\n",
93
+ "\n",
94
+ "\n",
95
+ "df.columns = df.columns.str.strip().str.lower()\n",
96
+ "\n",
97
+ "if target_col not in df.columns:\n",
98
+ " print(\"Columns found in dataset:\", df.columns.tolist())\n",
99
+ "\n",
100
+ " potential_cols = [c for c in df.columns if 'time' in c]\n",
101
+ " if potential_cols:\n",
102
+ " target_col = potential_cols[0]\n",
103
+ "\n",
104
+ "\n",
105
+ "plt.figure(figsize=(10, 6))\n",
106
+ "sns.histplot(df[target_col], kde=True, color='blue')\n",
107
+ "plt.title(f'Distribution of {target_col} (2026)')\n",
108
+ "plt.xlabel('Time (minutes)')\n",
109
+ "plt.ylabel('Frequency')\n",
110
+ "plt.show()\n",
111
+ "\n"
112
+ ],
113
+ "execution_count": null,
114
+ "outputs": []
115
+ },
116
+ {
117
+ "cell_type": "code",
118
+ "metadata": {},
119
+ "source": [
120
+ "# Task 1: Write your code here:\n",
121
+ "import pandas as pd\n",
122
+ "from sklearn.preprocessing import StandardScaler\n",
123
+ "\n",
124
+ "df.columns = df.columns.str.strip().str.lower()\n",
125
+ "target_col = 'delivery_time'\n",
126
+ "\n",
127
+ "df.drop(columns=['Order_ID'], inplace=True, errors='ignore')\n",
128
+ "\n",
129
+ "\n"
130
+ ],
131
+ "execution_count": null,
132
+ "outputs": []
133
+ },
134
+ {
135
+ "cell_type": "code",
136
+ "metadata": {},
137
+ "source": [
138
+ "# Task 2: Write your code here:\n",
139
+ "print(\"Missing values per column before cleaning:\\n\", df.isnull().sum())\n"
140
+ ],
141
+ "execution_count": null,
142
+ "outputs": []
143
+ },
144
+ {
145
+ "cell_type": "code",
146
+ "metadata": {},
147
+ "source": [
148
+ "# Task 3: Write your code here:\n",
149
+ "for col in df.columns:\n",
150
+ " if df[col].dtype == 'object':\n",
151
+ " df[col] = df[col].fillna(df[col].mode()[0])\n",
152
+ " else:\n",
153
+ " df[col] = df[col].fillna(df[col].median())\n"
154
+ ],
155
+ "execution_count": null,
156
+ "outputs": []
157
+ },
158
+ {
159
+ "cell_type": "code",
160
+ "metadata": {},
161
+ "source": [
162
+ "# Task 4: Write your code here:\n",
163
+ "for col in df.columns:\n",
164
+ " if df[col].dtype == 'object':\n",
165
+ " df[col] = df[col].fillna(df[col].mode()[0])\n",
166
+ " else:\n",
167
+ " df[col] = df[col].fillna(df[col].median())\n"
168
+ ],
169
+ "execution_count": null,
170
+ "outputs": []
171
+ },
172
+ {
173
+ "cell_type": "code",
174
+ "metadata": {},
175
+ "source": [
176
+ "# Task 5: Write your code here:\n",
177
+ "scaler = StandardScaler()\n",
178
+ "features = df.drop(columns=['delivery_time'])\n",
179
+ "target = df['delivery_time']\n",
180
+ "\n",
181
+ "scaled_features = scaler.fit_transform(features)\n",
182
+ "df_scaled = pd.DataFrame(scaled_features, columns=features.columns)\n",
183
+ "df_scaled['delivery_time'] = target.values"
184
+ ],
185
+ "execution_count": null,
186
+ "outputs": []
187
+ },
188
+ {
189
+ "cell_type": "code",
190
+ "metadata": {},
191
+ "source": [
192
+ "# Task 6: Write your code here:\n",
193
+ "skewness = df['delivery_time'].skew()\n",
194
+ "if abs(skewness) > 1:\n",
195
+ " print(f\"\\nTarget 'delivery_time' is imbalanced (Skewness: {skewness:.2f})\")\n",
196
+ "else:\n",
197
+ " print(f\"\\nTarget 'delivery_time' is relatively balanced (Skewness: {skewness:.2f})\")\n",
198
+ "\n",
199
+ "print(\"\\nData Cleaning Complete.\")"
200
+ ],
201
+ "execution_count": null,
202
+ "outputs": []
203
+ },
204
+ {
205
+ "cell_type": "code",
206
+ "metadata": {},
207
+ "source": [
208
+ "# Task 1: Write your code here:\n",
209
+ "\n",
210
+ "target_col = 'delivery_time'\n",
211
+ "\n",
212
+ "if target_col not in df.columns:\n",
213
+ "\n",
214
+ " potential_cols = [c for c in df.columns if 'time' in c]\n",
215
+ " target_col = potential_cols[0]\n",
216
+ "X = df.drop(columns=[target_col])\n",
217
+ "y = df[target_col]\n",
218
+ "\n",
219
+ "\n",
220
+ "\n"
221
+ ],
222
+ "execution_count": null,
223
+ "outputs": []
224
+ },
225
+ {
226
+ "cell_type": "code",
227
+ "metadata": {},
228
+ "source": [
229
+ "# Task 2,3,4,5: Write your code here:\n",
230
+ "# Task 2: Use KFold split (Standard for 2026 Regression tasks)\n",
231
+ "kf = KFold(n_splits=5, shuffle=True, random_state=42)\n",
232
+ "\n",
233
+ "# Task 3: Train a RandomForest model\n",
234
+ "model = RandomForestRegressor(n_estimators=100, random_state=42)\n",
235
+ "\n",
236
+ "mae_scores = cross_val_score(model, X, y, cv=kf, scoring='neg_mean_absolute_error')\n",
237
+ "average_mae = -np.mean(mae_scores)\n",
238
+ "\n",
239
+ "print(f\"Scores for each fold: {-mae_scores}\")\n",
240
+ "print(f\"Average MAE across all folds: {average_mae:.2f} minutes\")"
241
+ ],
242
+ "execution_count": null,
243
+ "outputs": []
244
+ },
245
+ {
246
+ "cell_type": "code",
247
+ "metadata": {},
248
+ "source": [
249
+ "# Task 1: Write your code here:\n",
250
+ "\n",
251
+ "plt.figure(figsize=(10, 8))\n",
252
+ "\n",
253
+ "# Get importances and sort them\n",
254
+ "importances = model.feature_importances\n",
255
+ "indices = np.argsort(importances)[::-1]\n",
256
+ "feature_names = X.columns\n",
257
+ "\n",
258
+ "sns.barplot(x=importances[indices], y=feature_names[indices], palette='viridis')\n",
259
+ "\n",
260
+ "plt.title('Feature Importance for Delivery Time Prediction (2026)')\n",
261
+ "plt.xlabel('Importance Score')\n",
262
+ "plt.ylabel('Features')\n",
263
+ "plt.show()"
264
+ ],
265
+ "execution_count": null,
266
+ "outputs": []
267
+ },
268
+ {
269
+ "cell_type": "code",
270
+ "metadata": {},
271
+ "source": [
272
+ "# Task 2: Write your code here:"
273
+ ],
274
+ "execution_count": null,
275
+ "outputs": []
276
+ }
277
+ ],
278
+ "metadata": {
279
+ "kernelspec": {
280
+ "display_name": "Python 3",
281
+ "name": "python3"
282
+ },
283
+ "language_info": {
284
+ "name": "python"
285
+ }
286
+ },
287
+ "nbformat": 4,
288
+ "nbformat_minor": 0
289
+ }
submissions_extracted/1010/Q2.ipynb ADDED
@@ -0,0 +1,353 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "metadata": {},
6
+ "source": [
7
+ "import kagglehub\n",
8
+ "\n",
9
+ "# Download latest version\n",
10
+ "path = kagglehub.dataset_download(\"ANON_OWNER/q2-exam-data\")\n",
11
+ "\n",
12
+ "print(\"Path to dataset files:\", path)"
13
+ ],
14
+ "execution_count": null,
15
+ "outputs": []
16
+ },
17
+ {
18
+ "cell_type": "code",
19
+ "metadata": {},
20
+ "source": [
21
+ "import os\n",
22
+ "import pandas as pd\n",
23
+ "import numpy as np\n",
24
+ "from PIL import Image\n",
25
+ "from sklearn.model_selection import train_test_split\n",
26
+ "\n",
27
+ "# Load Labels\n",
28
+ "labels_df = pd.read_csv(os.path.join(path, \"labels.csv\"))\n",
29
+ "img_dir = os.path.join(path, \"images\")\n",
30
+ "\n",
31
+ "images = []\n",
32
+ "ages = []\n",
33
+ "\n",
34
+ "# Load Images and Resize\n",
35
+ "print(\"Loading images...\")\n",
36
+ "for index, row in labels_df.iterrows():\n",
37
+ " img_name = row.iloc[0]\n",
38
+ " age = row.iloc[1]\n",
39
+ " img_path = os.path.join(img_dir, img_name)\n",
40
+ "\n",
41
+ " if os.path.exists(img_path):\n",
42
+ " img = Image.open(img_path).convert('RGB')\n",
43
+ " img_array = np.array(img) / 255.0 # Normalize pixel values to [0, 1]\n",
44
+ " images.append(img_array)\n",
45
+ " ages.append(age)\n",
46
+ "\n",
47
+ "X = np.array(images)\n",
48
+ "y = np.array(ages)\n",
49
+ "\n",
50
+ "# Transpose image dimensions to match PyTorch format (N, C, H, W)\n",
51
+ "X = np.transpose(X, (0, 3, 1, 2))\n",
52
+ "\n",
53
+ "# Split Data\n",
54
+ "X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)\n",
55
+ "\n",
56
+ "print(f\"X_train shape: {X_train.shape}\")\n",
57
+ "print(f\"X_test shape: {X_test.shape}\")\n",
58
+ "print(f\"y_train shape: {y_train.shape}\")\n",
59
+ "print(f\"y_test shape: {y_test.shape}\")"
60
+ ],
61
+ "execution_count": null,
62
+ "outputs": []
63
+ },
64
+ {
65
+ "cell_type": "code",
66
+ "metadata": {},
67
+ "source": [
68
+ "# 1. Convert Numpy arrays to PyTorch Tensors\n",
69
+ "\n",
70
+ "\n",
71
+ "import torch\n",
72
+ "import numpy as np\n",
73
+ "\n",
74
+ "\n",
75
+ "X_train_t = torch.tensor(X_train, dtype=torch.float32)\n",
76
+ "X_test_t = torch.tensor(X_test, dtype=torch.float32)\n",
77
+ "\n",
78
+ "\n",
79
+ "y_train_t = torch.tensor(y_train, dtype=torch.float32).view(-1, 1)\n",
80
+ "y_test_t = torch.tensor(y_test, dtype=torch.float32).view(-1, 1)\n"
81
+ ],
82
+ "execution_count": null,
83
+ "outputs": []
84
+ },
85
+ {
86
+ "cell_type": "code",
87
+ "metadata": {},
88
+ "source": [
89
+ "# 2. Create TensorDataset objects\n",
90
+ "\n",
91
+ "from torch.utils.data import TensorDataset\n",
92
+ "\n",
93
+ "train_dataset = TensorDataset(X_train_t, y_train_t)\n",
94
+ "test_dataset = TensorDataset(X_test_t, y_test_t)\n",
95
+ "\n"
96
+ ],
97
+ "execution_count": null,
98
+ "outputs": []
99
+ },
100
+ {
101
+ "cell_type": "code",
102
+ "metadata": {},
103
+ "source": [
104
+ "# 3. Create DataLoaders\n",
105
+ "\n",
106
+ "from torch.utils.data import DataLoader\n",
107
+ "\n",
108
+ "train_loader = DataLoader(train_dataset, batch_size=32, shuffle=True)\n",
109
+ "test_loader = DataLoader(test_dataset, batch_size=32, shuffle=False)\n",
110
+ "\n"
111
+ ],
112
+ "execution_count": null,
113
+ "outputs": []
114
+ },
115
+ {
116
+ "cell_type": "code",
117
+ "metadata": {},
118
+ "source": [
119
+ "# 4. Print shape of one batch\n",
120
+ "\n",
121
+ "# Extract the first batch\n",
122
+ "train_features, train_labels = next(iter(train_loader))\n",
123
+ "\n",
124
+ "print(f\"Feature batch shape: {train_features.shape}\") # Expected: [32, Channels, H, W]\n",
125
+ "print(f\"Labels batch shape: {train_labels.shape}\") # Expected: [32, 1]\n"
126
+ ],
127
+ "execution_count": null,
128
+ "outputs": []
129
+ },
130
+ {
131
+ "cell_type": "code",
132
+ "metadata": {},
133
+ "source": [
134
+ "# 5. Display sample images\n",
135
+ "import matplotlib.pyplot as plt\n",
136
+ "\n",
137
+ "# Display first 4 images from the batch\n",
138
+ "plt.figure(figsize=(10, 4))\n",
139
+ "for i in range(4):\n",
140
+ " plt.subplot(1, 4, i + 1)\n",
141
+ " # Permute from (C, H, W) to (H, W, C) for plotting\n",
142
+ " img = train_features[i].permute(1, 2, 0).numpy()\n",
143
+ " plt.imshow(img.astype(np.uint8) if img.max() > 1 else img)\n",
144
+ " plt.title(f\"Age: {train_labels[i].item():.0f}\")\n",
145
+ " plt.axis('off')\n",
146
+ "plt.show()\n"
147
+ ],
148
+ "execution_count": null,
149
+ "outputs": []
150
+ },
151
+ {
152
+ "cell_type": "code",
153
+ "metadata": {},
154
+ "source": [
155
+ "# Task 1: Write your model class here:\n",
156
+ "import torch\n",
157
+ "import torch.nn as nn\n",
158
+ "import torch.nn.functional as F\n",
159
+ "\n",
160
+ "class AgePredictionModel(nn.Module):\n",
161
+ " def __init__(self, input_shape):\n",
162
+ " super(AgePredictionModel, self).__init__()\n",
163
+ " # input_shape should be: Channels * Height * Width\n",
164
+ " self.flatten = nn.Flatten()\n",
165
+ " self.fc1 = nn.Linear(input_shape, 512)\n",
166
+ " self.fc2 = nn.Linear(512, 256)\n",
167
+ " self.fc3 = nn.Linear(256, 64)\n",
168
+ " self.fc4 = nn.Linear(64, 1) # Output layer: 1 neuron for regression (age)\n",
169
+ "\n",
170
+ " def forward(self, x):\n",
171
+ " x = self.flatten(x)\n",
172
+ " x = F.relu(self.fc1(x))\n",
173
+ " x = F.relu(self.fc2(x))\n",
174
+ " x = F.relu(self.fc3(x))\n",
175
+ " x = self.fc4(x) # No activation for the last layer in regression\n",
176
+ " return x\n"
177
+ ],
178
+ "execution_count": null,
179
+ "outputs": []
180
+ },
181
+ {
182
+ "cell_type": "code",
183
+ "metadata": {},
184
+ "source": [
185
+ "# Task 2: Write your training loop here:\n",
186
+ "def train_step(model, loader, criterion, optimizer, device):\n",
187
+ " model.train()\n",
188
+ " total_loss = 0\n",
189
+ " for images, labels in loader:\n",
190
+ " images, labels = images.to(device), labels.to(device)\n",
191
+ "\n",
192
+ " optimizer.zero_grad()\n",
193
+ " outputs = model(images)\n",
194
+ " loss = criterion(outputs, labels)\n",
195
+ " loss.backward()\n",
196
+ " optimizer.step()\n",
197
+ "\n",
198
+ " total_loss += loss.item()\n",
199
+ " return total_loss / len(loader)\n",
200
+ "\n",
201
+ "def validate_step(model, loader, criterion, device):\n",
202
+ " model.eval()\n",
203
+ " total_loss = 0\n",
204
+ " with torch.no_grad():\n",
205
+ " for images, labels in loader:\n",
206
+ " images, labels = images.to(device), labels.to(device)\n",
207
+ " outputs = model(images)\n",
208
+ " loss = criterion(outputs, labels)\n",
209
+ " total_loss += loss.item()\n",
210
+ " return total_loss / len(loader)\n"
211
+ ],
212
+ "execution_count": null,
213
+ "outputs": []
214
+ },
215
+ {
216
+ "cell_type": "code",
217
+ "metadata": {},
218
+ "source": [
219
+ "# Task 3: Write your validation loop here:\n",
220
+ "def validate_step(model, loader, criterion, device):\n",
221
+ " model.eval()\n",
222
+ " total_loss = 0\n",
223
+ " with torch.no_grad():\n",
224
+ " for images, labels in loader:\n",
225
+ " images, labels = images.to(device), labels.to(device)\n",
226
+ " outputs = model(images)\n",
227
+ " loss = criterion(outputs, labels)\n",
228
+ " total_loss += loss.item()\n",
229
+ " return total_loss / len(loader)"
230
+ ],
231
+ "execution_count": null,
232
+ "outputs": []
233
+ },
234
+ {
235
+ "cell_type": "code",
236
+ "metadata": {},
237
+ "source": [
238
+ "# Task 4: Define device, model, loss, optimizer:\n",
239
+ "\n",
240
+ "device = torch.device(\"cuda\" if torch.cuda.is_available() else \"cpu\")\n",
241
+ "\n",
242
+ "\n",
243
+ "sample_batch, _ = next(iter(train_loader))\n",
244
+ "input_size = sample_batch.shape[1] * sample_batch.shape[2] * sample_batch.shape[3]\n",
245
+ "\n",
246
+ "\n",
247
+ "model = AgePredictionModel(input_size).to(device)\n",
248
+ "\n",
249
+ "\n",
250
+ "criterion = nn.MSELoss()\n",
251
+ "optimizer = torch.optim.Adam(model.parameters(), lr=0.001)\n"
252
+ ],
253
+ "execution_count": null,
254
+ "outputs": []
255
+ },
256
+ {
257
+ "cell_type": "code",
258
+ "metadata": {},
259
+ "source": [
260
+ "# Task 5: Start training for 20 epochs:\n",
261
+ "epochs = 20\n",
262
+ "history = {\"train_loss\": [], \"val_loss\": []}\n",
263
+ "\n",
264
+ "print(f\"Starting training on {device}...\")\n",
265
+ "\n",
266
+ "for epoch in range(epochs):\n",
267
+ " train_loss = train_step(model, train_loader, criterion, optimizer, device)\n",
268
+ " val_loss = validate_step(model, test_loader, criterion, device)\n",
269
+ "\n",
270
+ " history[\"train_loss\"].append(train_loss)\n",
271
+ " history[\"val_loss\"].append(val_loss)\n",
272
+ "\n",
273
+ " print(f\"Epoch [{epoch+1}/{epochs}] - Train Loss: {train_loss:.4f} | Val Loss: {val_loss:.4f}\")\n",
274
+ "\n",
275
+ "print(\"Training Complete.\")\n"
276
+ ],
277
+ "execution_count": null,
278
+ "outputs": []
279
+ },
280
+ {
281
+ "cell_type": "code",
282
+ "metadata": {},
283
+ "source": [
284
+ "# Task 1: Write your code here:\n",
285
+ "import matplotlib.pyplot as plt\n",
286
+ "\n",
287
+ "\n",
288
+ "plt.figure(figsize=(10, 6))\n",
289
+ "plt.plot(range(1, epochs + 1), history[\"train_loss\"], label='Training Loss', marker='o')\n",
290
+ "plt.plot(range(1, epochs + 1), history[\"val_loss\"], label='Validation Loss', marker='o')\n",
291
+ "\n",
292
+ "plt.title('Age Prediction Model: Loss Over Epochs (2026)')\n",
293
+ "plt.xlabel('Epoch')\n",
294
+ "plt.ylabel('Mean Squared Error (Loss)')\n",
295
+ "plt.legend()\n",
296
+ "plt.grid(True, linestyle='--', alpha=0.6)\n",
297
+ "plt.show()\n"
298
+ ],
299
+ "execution_count": null,
300
+ "outputs": []
301
+ },
302
+ {
303
+ "cell_type": "code",
304
+ "metadata": {},
305
+ "source": [
306
+ "# Task 2 (Bonus): Write your code here:\n",
307
+ "\n",
308
+ "model.eval()\n",
309
+ "images, labels = next(iter(test_loader))\n",
310
+ "images, labels = images.to(device), labels.to(device)\n",
311
+ "\n",
312
+ "with torch.no_grad():\n",
313
+ " preds = model(images)\n",
314
+ "\n",
315
+ "plt.figure(figsize=(15, 10))\n",
316
+ "for i in range(8):\n",
317
+ " plt.subplot(2, 4, i + 1)\n",
318
+ "\n",
319
+ "\n",
320
+ " img = images[i].cpu().permute(1, 2, 0).numpy()\n",
321
+ "\n",
322
+ "\n",
323
+ "\n",
324
+ " plt.imshow(img.clip(0, 1)) # Clip to ensure valid RGB range\n",
325
+ "\n",
326
+ " actual_age = labels[i].item()\n",
327
+ " predicted_age = preds[i].item()\n",
328
+ "\n",
329
+ "\n",
330
+ " color = 'green' if abs(actual_age - predicted_age) <= 5 else 'red'\n",
331
+ "\n",
332
+ " plt.title(f\"Actual: {actual_age:.0f}\\nPred: {predicted_age:.1f}\", color=color)\n",
333
+ " plt.axis('off')\n",
334
+ "\n",
335
+ "plt.tight_layout()\n",
336
+ "plt.show()\n"
337
+ ],
338
+ "execution_count": null,
339
+ "outputs": []
340
+ }
341
+ ],
342
+ "metadata": {
343
+ "kernelspec": {
344
+ "display_name": "Python 3",
345
+ "name": "python3"
346
+ },
347
+ "language_info": {
348
+ "name": "python"
349
+ }
350
+ },
351
+ "nbformat": 4,
352
+ "nbformat_minor": 0
353
+ }
submissions_extracted/1010/Q3.ipynb ADDED
@@ -0,0 +1,274 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "metadata": {},
6
+ "source": [
7
+ "import kagglehub\n",
8
+ "\n",
9
+ "\n",
10
+ "\n",
11
+ "# Download latest version\n",
12
+ "\n",
13
+ "path = kagglehub.dataset_download(\"ANON_OWNER/q3-exam-data\")\n",
14
+ "\n",
15
+ "\n",
16
+ "\n",
17
+ "print(\"Path to dataset files:\", path)"
18
+ ],
19
+ "execution_count": null,
20
+ "outputs": []
21
+ },
22
+ {
23
+ "cell_type": "code",
24
+ "metadata": {},
25
+ "source": [
26
+ "import numpy as np\n",
27
+ "import pandas as pd\n",
28
+ "import matplotlib.pyplot as plt\n",
29
+ "import os\n",
30
+ "import kagglehub\n",
31
+ "\n",
32
+ "from sklearn.model_selection import train_test_split, StratifiedKFold, cross_val_score\n",
33
+ "from sklearn.preprocessing import StandardScaler, LabelEncoder\n",
34
+ "from sklearn.ensemble import RandomForestClassifier\n",
35
+ "from sklearn.metrics import classification_report, confusion_matrix, accuracy_score\n",
36
+ "\n",
37
+ "import warnings\n",
38
+ "warnings.filterwarnings('ignore')\n"
39
+ ],
40
+ "execution_count": null,
41
+ "outputs": []
42
+ },
43
+ {
44
+ "cell_type": "code",
45
+ "metadata": {},
46
+ "source": [
47
+ "# Task 1: Write your code here:\n",
48
+ "csv_path = os.path.join(path, \"Q3_data.csv\")\n",
49
+ "df_credit = pd.read_csv(csv_path)"
50
+ ],
51
+ "execution_count": null,
52
+ "outputs": []
53
+ },
54
+ {
55
+ "cell_type": "code",
56
+ "metadata": {},
57
+ "source": [
58
+ "# Task 2: Write your code here:\n",
59
+ "print(\"--- Task 2: First 5 Rows of Credit Data ---\")\n",
60
+ "print(df_credit.head())\n"
61
+ ],
62
+ "execution_count": null,
63
+ "outputs": []
64
+ },
65
+ {
66
+ "cell_type": "code",
67
+ "metadata": {},
68
+ "source": [
69
+ "# Task 3: Write your code here:\n",
70
+ "print(\"\\n--- Task 3: Dataset Information ---\")\n",
71
+ "df_credit.info()\n"
72
+ ],
73
+ "execution_count": null,
74
+ "outputs": []
75
+ },
76
+ {
77
+ "cell_type": "code",
78
+ "metadata": {},
79
+ "source": [
80
+ "# Task 4: Write your code here:rint(\"\\n--- Task 4: Statistical Description ---\")\n",
81
+ "print(df_credit.describe())"
82
+ ],
83
+ "execution_count": null,
84
+ "outputs": []
85
+ },
86
+ {
87
+ "cell_type": "code",
88
+ "metadata": {},
89
+ "source": [
90
+ "# Task 1: Write your code here:\n",
91
+ "for col in df_credit.columns:\n",
92
+ " if df_credit[col].dtype == 'object':\n",
93
+ " df_credit[col] = df_credit[col].fillna(df_credit[col].mode()[0])\n",
94
+ " else:\n",
95
+ " df_credit[col] = df_credit[col].fillna(df_credit[col].median())"
96
+ ],
97
+ "execution_count": null,
98
+ "outputs": []
99
+ },
100
+ {
101
+ "cell_type": "code",
102
+ "metadata": {},
103
+ "source": [
104
+ "# Task 2: Write your code here:\n",
105
+ "duplicate_count = df_credit.duplicated().sum()\n",
106
+ "print(f\"Duplicates found: {duplicate_count}\")\n",
107
+ "if duplicate_count > 0:\n",
108
+ " df_credit.drop_duplicates(inplace=True)"
109
+ ],
110
+ "execution_count": null,
111
+ "outputs": []
112
+ },
113
+ {
114
+ "cell_type": "code",
115
+ "metadata": {},
116
+ "source": [
117
+ "# Task 3: Write your code here:\n",
118
+ "df_credit = pd.get_dummies(df_credit, drop_first=True)\n"
119
+ ],
120
+ "execution_count": null,
121
+ "outputs": []
122
+ },
123
+ {
124
+ "cell_type": "code",
125
+ "metadata": {},
126
+ "source": [
127
+ "# Task 4: Write your code here:\n",
128
+ "caler = StandardScaler()\n",
129
+ "X_scaled = scaler.fit_transform(X)\n",
130
+ "\n",
131
+ "\n",
132
+ "df_scaled = pd.DataFrame(X_scaled, columns=X.columns)\n",
133
+ "df_scaled[target_col] = y.values\n",
134
+ "\n",
135
+ "\n",
136
+ "imbalance_ratio = y.value_counts(normalize=True)\n",
137
+ "print(\"\\nTarget Distribution:\\n\", imbalance_ratio)"
138
+ ],
139
+ "execution_count": null,
140
+ "outputs": []
141
+ },
142
+ {
143
+ "cell_type": "code",
144
+ "metadata": {},
145
+ "source": [
146
+ "# Task 5: Write your code here:\n",
147
+ "imbalance_ratio = y.value_counts(normalize=True)\n",
148
+ "print(\"\\nTarget Distribution:\")\n",
149
+ "print(imbalance_ratio)\n",
150
+ "\n",
151
+ "# Identify if imbalanced (usually if one class is < 20%)\n",
152
+ "if imbalance_ratio.min() < 0.20:\n",
153
+ " print(\"State: The target is IMBALANCED.\")\n",
154
+ "else:\n",
155
+ " print(\"State: The target is relatively BALANCED.\")\n",
156
+ "sns.countplot(x=y)\n",
157
+ "plt.title('Target Distribution (0: No Default, 1: Default)')\n",
158
+ "plt.show()"
159
+ ],
160
+ "execution_count": null,
161
+ "outputs": []
162
+ },
163
+ {
164
+ "cell_type": "code",
165
+ "metadata": {},
166
+ "source": [
167
+ "# Task 1: Write your code here:\n",
168
+ "X = df_scaled.drop(columns=[target_col])\n",
169
+ "y = df_scaled[target_col]\n"
170
+ ],
171
+ "execution_count": null,
172
+ "outputs": []
173
+ },
174
+ {
175
+ "cell_type": "code",
176
+ "metadata": {},
177
+ "source": [
178
+ "# Task 2,3,4,5: Write your code here:\n",
179
+ "skf = StratifiedKFold(n_splits=5, shuffle=True, random_state=42)\n",
180
+ "\n",
181
+ "model = CatBoostClassifier(iterations=500, depth=6, learning_rate=0.05, verbose=0)\n",
182
+ "\n",
183
+ "f1_scores = []\n",
184
+ "print(\"Starting Stratified Cross-Validation...\")\n",
185
+ "for fold, (train_idx, test_idx) in enumerate(skf.split(X, y)):\n",
186
+ " X_train, X_test = X.iloc[train_idx], X.iloc[test_idx]\n",
187
+ " y_train, y_test = y.iloc[train_idx], y.iloc[test_idx]\n",
188
+ "\n",
189
+ " # Fit model\n",
190
+ " model.fit(X_train, y_train)\n",
191
+ "\n",
192
+ " # Predict\n",
193
+ " y_pred = model.predict(X_test)\n",
194
+ "\n",
195
+ " score = f1_score(y_test, y_pred)\n",
196
+ " f1_scores.append(score)\n",
197
+ " print(f\"Fold {fold+1} F1 Score: {score:.4f}\")\n",
198
+ "\n",
199
+ "\n",
200
+ "print(f\"\\nAverage F1 Score across all folds: {np.mean(f1_scores):.4f}\")\n",
201
+ "\n"
202
+ ],
203
+ "execution_count": null,
204
+ "outputs": []
205
+ },
206
+ {
207
+ "cell_type": "code",
208
+ "metadata": {},
209
+ "source": [
210
+ "# Task 1: Write your code here:\n",
211
+ "import matplotlib.pyplot as plt\n",
212
+ "import seaborn as sns\n",
213
+ "import pandas as pd\n",
214
+ "model.fit(X, y)\n",
215
+ "\n",
216
+ "\n",
217
+ "# Get feature importance from CatBoost\n",
218
+ "feature_importance = model.get_feature_importance()\n",
219
+ "feature_names = X.columns\n",
220
+ "# Create a DataFrame for visualization\n",
221
+ "fi_df = pd.DataFrame({'Feature': feature_names, 'Importance': feature_importance})\n",
222
+ "fi_df = fi_df.sort_values(by='Importance', ascending=False).head(15) # Top 15 features\n",
223
+ "\n",
224
+ "# Plotting\n",
225
+ "plt.figure(figsize=(12, 8))\n",
226
+ "sns.barplot(x='Importance', y='Feature', data=fi_df, palette='magma')\n",
227
+ "plt.title('Top Feature Importances - Identifying the Golden Feature (2026)')\n",
228
+ "plt.xlabel('Importance Score')\n",
229
+ "plt.ylabel('Anonymized Features')\n",
230
+ "plt.show()\n",
231
+ "\n"
232
+ ],
233
+ "execution_count": null,
234
+ "outputs": []
235
+ },
236
+ {
237
+ "cell_type": "code",
238
+ "metadata": {},
239
+ "source": [
240
+ "# Task 2: Write your code here:\n",
241
+ "golden_feature = fi_df.iloc[0]['Feature']\n",
242
+ "importance_score = fi_df.iloc[0]['Importance']\n",
243
+ "\n",
244
+ "print(\"=\"*50)\n",
245
+ "print(f\"MISSION ACCOMPLISHED!\")\n",
246
+ "print(f\"The Golden Feature is: {golden_feature}\")\n",
247
+ "print(f\"Importance Score: {importance_score:.2f}\")\n",
248
+ "print(\"=\"*50)"
249
+ ],
250
+ "execution_count": null,
251
+ "outputs": []
252
+ },
253
+ {
254
+ "cell_type": "code",
255
+ "metadata": {},
256
+ "source": [
257
+ "# Task Bonus: Write your code here:"
258
+ ],
259
+ "execution_count": null,
260
+ "outputs": []
261
+ }
262
+ ],
263
+ "metadata": {
264
+ "kernelspec": {
265
+ "display_name": "Python 3",
266
+ "name": "python3"
267
+ },
268
+ "language_info": {
269
+ "name": "python"
270
+ }
271
+ },
272
+ "nbformat": 4,
273
+ "nbformat_minor": 0
274
+ }
submissions_extracted/1011/Q1.ipynb ADDED
@@ -0,0 +1,325 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "metadata": {},
6
+ "source": [
7
+ "import kagglehub\n",
8
+ "\n",
9
+ "# Download latest version\n",
10
+ "path = kagglehub.dataset_download(\"ANON_OWNER/q1-exam-data\")\n",
11
+ "\n",
12
+ "print(\"Path to dataset files:\", path)"
13
+ ],
14
+ "execution_count": null,
15
+ "outputs": []
16
+ },
17
+ {
18
+ "cell_type": "code",
19
+ "metadata": {},
20
+ "source": [
21
+ "import numpy as np\n",
22
+ "import pandas as pd\n",
23
+ "import matplotlib.pyplot as plt\n",
24
+ "import kagglehub\n",
25
+ "import os\n",
26
+ "import kagglehub\n",
27
+ "from sklearn.preprocessing import OneHotEncoder\n",
28
+ "\n",
29
+ "from sklearn.model_selection import train_test_split, KFold\n",
30
+ "from sklearn.preprocessing import StandardScaler, LabelEncoder\n",
31
+ "from sklearn.ensemble import RandomForestRegressor\n",
32
+ "from sklearn.metrics import mean_absolute_error, mean_squared_error\n",
33
+ "\n",
34
+ "from sklearn.preprocessing import StandardScaler, LabelEncoder\n",
35
+ "from sklearn.model_selection import KFold\n",
36
+ "from sklearn.linear_model import LinearRegression\n",
37
+ "from sklearn.metrics import mean_squared_error, mean_absolute_error\n"
38
+ ],
39
+ "execution_count": null,
40
+ "outputs": []
41
+ },
42
+ {
43
+ "cell_type": "code",
44
+ "metadata": {},
45
+ "source": [
46
+ "# Task 1:\n",
47
+ "food_path = os.path.join(path, 'Q1_data.csv')\n",
48
+ "df_food = pd.read_csv(food_path)\n"
49
+ ],
50
+ "execution_count": null,
51
+ "outputs": []
52
+ },
53
+ {
54
+ "cell_type": "code",
55
+ "metadata": {},
56
+ "source": [
57
+ "# Task 2:\n",
58
+ "print(f\"Dataset shape: {df_food.shape}\")\n",
59
+ "df_food.head()"
60
+ ],
61
+ "execution_count": null,
62
+ "outputs": []
63
+ },
64
+ {
65
+ "cell_type": "code",
66
+ "metadata": {},
67
+ "source": [
68
+ "# Task 3:\n",
69
+ "df_food.info()"
70
+ ],
71
+ "execution_count": null,
72
+ "outputs": []
73
+ },
74
+ {
75
+ "cell_type": "code",
76
+ "metadata": {},
77
+ "source": [
78
+ "# Task 4:\n",
79
+ "df_food.describe()"
80
+ ],
81
+ "execution_count": null,
82
+ "outputs": []
83
+ },
84
+ {
85
+ "cell_type": "code",
86
+ "metadata": {},
87
+ "source": [
88
+ "# Task 5:\n",
89
+ "plt.figure(figsize=(10, 5))\n",
90
+ "plt.hist(df_food['Delivery_Time'].dropna(), bins=50, edgecolor='black')\n",
91
+ "plt.title('delivery_time Distribution')\n",
92
+ "plt.xlabel('df_food')\n",
93
+ "plt.ylabel('Frequency')\n",
94
+ "plt.show()"
95
+ ],
96
+ "execution_count": null,
97
+ "outputs": []
98
+ },
99
+ {
100
+ "cell_type": "code",
101
+ "metadata": {},
102
+ "source": [
103
+ "# Task 1:\n",
104
+ "#cols = df_food.drop(columns=['Order_ID'])\n",
105
+ "\n",
106
+ "cols = ['Order_ID', 'Distance_km', 'Weather', 'Traffic_Level', 'Time_of_Day', 'Vehicle_Type', 'Preparation_Time_min', 'Courier_Experience_yrs', 'Delivery_Time']\n",
107
+ "df_clean = df_food[cols].copy()\n",
108
+ "\n",
109
+ "print(f\"Before: {df_clean.shape}\")\n",
110
+ "df_clean = df_clean.drop(columns=['Order_ID'])\n",
111
+ "print(f\"After dropping : {df_clean.shape}\")"
112
+ ],
113
+ "execution_count": null,
114
+ "outputs": []
115
+ },
116
+ {
117
+ "cell_type": "code",
118
+ "metadata": {},
119
+ "source": [
120
+ "# Task 2:\n",
121
+ "df_clean['Weather'] = df_clean['Weather'].fillna(df_clean['Weather'].mode()[0])\n",
122
+ "df_clean['Traffic_Level'] = df_clean['Traffic_Level'].fillna(df_clean['Traffic_Level'].mode()[0])\n",
123
+ "df_clean['Time_of_Day'] = df_clean['Time_of_Day'].fillna(df_clean['Time_of_Day'].mode()[0])\n",
124
+ "\n",
125
+ "\n",
126
+ "df_clean['Courier_Experience_yrs'] = df_clean['Courier_Experience_yrs'].fillna(df_clean['Courier_Experience_yrs'].mean())\n",
127
+ "df_clean['Delivery_Time'] = df_clean['Delivery_Time'].fillna(df_clean['Delivery_Time'].mean())\n",
128
+ "\n",
129
+ "print(\"Missing values remaining:\", df_clean.isnull().sum().sum())\n",
130
+ "\n"
131
+ ],
132
+ "execution_count": null,
133
+ "outputs": []
134
+ },
135
+ {
136
+ "cell_type": "code",
137
+ "metadata": {},
138
+ "source": [
139
+ "# Task 3:\n",
140
+ "def check_duplicates(df):\n",
141
+ " duplicates = df.duplicated().sum()\n",
142
+ " print(f\"Number of Duplicate Samples: {duplicates}\")\n",
143
+ " if duplicates > 0:\n",
144
+ " print(\"Dropping Duplicates...\")\n",
145
+ " df.drop_duplicates(inplace=True)\n",
146
+ " print(\"Duplicates Dropped.\")\n",
147
+ " else:\n",
148
+ " print(\"No Duplicate Samples Found.\")\n",
149
+ "\n",
150
+ "check_duplicates(train_df)"
151
+ ],
152
+ "execution_count": null,
153
+ "outputs": []
154
+ },
155
+ {
156
+ "cell_type": "code",
157
+ "metadata": {},
158
+ "source": [
159
+ "# Task 4:\n",
160
+ "categorical_cols = ['Weather', 'Traffic_Level', 'Time_of_Day', 'Vehicle_Type']\n",
161
+ "for col in categorical_cols:\n",
162
+ " le = LabelEncoder()\n",
163
+ " df_clean[col] = le.fit_transform(df_clean[col].astype(str))\n",
164
+ "\n",
165
+ "df_clean.head()"
166
+ ],
167
+ "execution_count": null,
168
+ "outputs": []
169
+ },
170
+ {
171
+ "cell_type": "code",
172
+ "metadata": {},
173
+ "source": [
174
+ "# Task 4: (OneHotEncoder)\n",
175
+ "print('data before encoding:\\n', categories)\n",
176
+ "\n",
177
+ "onehot_encoder = OneHotEncoder(sparse_output=False)\n",
178
+ "data_onehot_encoded = onehot_encoder.fit_transform(categories)\n",
179
+ "\n",
180
+ "print('\\nData after encoding:\\n', data_onehot_encoded)"
181
+ ],
182
+ "execution_count": null,
183
+ "outputs": []
184
+ },
185
+ {
186
+ "cell_type": "code",
187
+ "metadata": {},
188
+ "source": [
189
+ "# Task 5:\n",
190
+ "\n",
191
+ "scaler = StandardScaler()\n",
192
+ "X_train_scaled = scaler.fit_transform(X_train)\n",
193
+ "X_test_scaled = scaler.transform(X_test)\n",
194
+ "\n",
195
+ "print(f\"\\nScaled ranges - Min: {X_train_scaled.min():.2f}, Max: {X_train_scaled.max():.2f}\")\n",
196
+ "pd.DataFrame(X_train_scaled, columns=X_train.columns).head(3)\n",
197
+ "\n"
198
+ ],
199
+ "execution_count": null,
200
+ "outputs": []
201
+ },
202
+ {
203
+ "cell_type": "code",
204
+ "metadata": {},
205
+ "source": [
206
+ "# Task 6:\n",
207
+ "print(f\"\\nFeature ranges - Min: {X_train.min().min():.2f}, Max: {X_train.max().max():.2f}\")\n",
208
+ "X_train.head(3)"
209
+ ],
210
+ "execution_count": null,
211
+ "outputs": []
212
+ },
213
+ {
214
+ "cell_type": "code",
215
+ "metadata": {},
216
+ "source": [
217
+ "# Task 1:\n",
218
+ "feature_cols = ['Distance_km', 'Weather', 'Traffic_Level', 'Time_of_Day',\n",
219
+ " 'Vehicle_Type', 'Preparation_Time_min', 'Courier_Experience_yrs', 'Delivery_Time']\n",
220
+ "\n",
221
+ "X = df_clean[feature_cols]\n",
222
+ "y = df_clean['Delivery_Time']\n",
223
+ "\n",
224
+ "# Train-test split (80% train, 20% test)\n",
225
+ "X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)\n",
226
+ "print(f\"Train: {X_train.shape}, Test: {X_test.shape}\")\n"
227
+ ],
228
+ "execution_count": null,
229
+ "outputs": []
230
+ },
231
+ {
232
+ "cell_type": "code",
233
+ "metadata": {},
234
+ "source": [
235
+ "# Task 2,3,4,5:\n",
236
+ "model = RandomForestRegressor(n_estimators=100, max_depth=20, random_state=42, n_jobs=-1)\n",
237
+ "model.fit(X_train_scaled, y_train)\n",
238
+ "print(\"Model trained!\")\n",
239
+ "\n",
240
+ "y_pred = model.predict(X_test_scaled)\n",
241
+ "\n",
242
+ "mae = mean_absolute_error(y_test, y_pred)\n",
243
+ "\n",
244
+ "print(f\"MAE: ${mae:,.2f}\")\n",
245
+ "\n",
246
+ "kfold = KFold(n_splits=5, shuffle=True, random_state=42)\n",
247
+ "\n",
248
+ "mae_scores = []\n",
249
+ "\n",
250
+ "for train_idx, val_idx in kfold.split(X_train_scaled):\n",
251
+ " X_fold_train, X_fold_val = X_train_scaled[train_idx], X_train_scaled[val_idx]\n",
252
+ " y_fold_train, y_fold_val = y_train.iloc[train_idx], y_train.iloc[val_idx]\n",
253
+ "\n",
254
+ " # Train and predict\n",
255
+ " model.fit(X_fold_train, y_fold_train)\n",
256
+ " y_fold_pred = model.predict(X_fold_val)\n",
257
+ "\n",
258
+ " # Calculate metrics\n",
259
+ " mae_scores.append(mean_absolute_error(y_fold_val, y_fold_pred))\n",
260
+ "\n",
261
+ "mae_scores = np.array(mae_scores)\n",
262
+ "\n",
263
+ "print(f\"5-Fold CV Results:\")\n",
264
+ "print(f\"MAE: ${mae_scores.mean():,.2f}\")\n"
265
+ ],
266
+ "execution_count": null,
267
+ "outputs": []
268
+ },
269
+ {
270
+ "cell_type": "code",
271
+ "metadata": {},
272
+ "source": [
273
+ "# Task 1:\n",
274
+ "feature_importance = pd.DataFrame({\n",
275
+ " 'feature': feature_cols,\n",
276
+ " 'importance': model.feature_importances_\n",
277
+ "}).sort_values('importance', ascending=False)\n",
278
+ "\n",
279
+ "plt.figure(figsize=(10, 6))\n",
280
+ "plt.barh(feature_importance['feature'], feature_importance['importance'])\n",
281
+ "plt.xlabel('Importance')\n",
282
+ "plt.title('Feature Importance')\n",
283
+ "plt.gca().invert_yaxis()\n",
284
+ "plt.show()"
285
+ ],
286
+ "execution_count": null,
287
+ "outputs": []
288
+ },
289
+ {
290
+ "cell_type": "code",
291
+ "metadata": {},
292
+ "source": [
293
+ "# Task 2:\n",
294
+ "plt.figure(figsize=(10, 5))\n",
295
+ "plt.hist(df_food['Delivery_Time'].dropna(), bins=50, edgecolor='black')\n",
296
+ "plt.title('delivery_time Distribution')\n",
297
+ "plt.xlabel('df_food')\n",
298
+ "plt.ylabel('Frequency')\n",
299
+ "plt.show()"
300
+ ],
301
+ "execution_count": null,
302
+ "outputs": []
303
+ },
304
+ {
305
+ "cell_type": "code",
306
+ "metadata": {},
307
+ "source": [
308
+ "# Task Bonus: Write your code here:"
309
+ ],
310
+ "execution_count": null,
311
+ "outputs": []
312
+ }
313
+ ],
314
+ "metadata": {
315
+ "kernelspec": {
316
+ "display_name": "Python 3",
317
+ "name": "python3"
318
+ },
319
+ "language_info": {
320
+ "name": "python"
321
+ }
322
+ },
323
+ "nbformat": 4,
324
+ "nbformat_minor": 0
325
+ }
submissions_extracted/1011/Q2.ipynb ADDED
@@ -0,0 +1,488 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "metadata": {},
6
+ "source": [
7
+ "import kagglehub\n",
8
+ "\n",
9
+ "# Download latest version\n",
10
+ "path = kagglehub.dataset_download(\"ANON_OWNER/q2-exam-data\")\n",
11
+ "\n",
12
+ "print(\"Path to dataset files:\", path)"
13
+ ],
14
+ "execution_count": null,
15
+ "outputs": []
16
+ },
17
+ {
18
+ "cell_type": "code",
19
+ "metadata": {},
20
+ "source": [
21
+ "import os\n",
22
+ "import pandas as pd\n",
23
+ "import numpy as np\n",
24
+ "from PIL import Image\n",
25
+ "from sklearn.model_selection import train_test_split\n",
26
+ "from torch.utils.data import DataLoader, TensorDataset\n",
27
+ "\n",
28
+ "\n",
29
+ "# Load Labels\n",
30
+ "labels_df = pd.read_csv(os.path.join(path, \"labels.csv\"))\n",
31
+ "img_dir = os.path.join(path, \"images\")\n",
32
+ "\n",
33
+ "images = []\n",
34
+ "ages = []\n",
35
+ "\n",
36
+ "# Load Images and Resize\n",
37
+ "print(\"Loading images...\")\n",
38
+ "for index, row in labels_df.iterrows():\n",
39
+ " img_name = row.iloc[0]\n",
40
+ " age = row.iloc[1]\n",
41
+ " img_path = os.path.join(img_dir, img_name)\n",
42
+ "\n",
43
+ " if os.path.exists(img_path):\n",
44
+ " img = Image.open(img_path).convert('RGB')\n",
45
+ " img_array = np.array(img) / 255.0 # Normalize pixel values to [0, 1]\n",
46
+ " images.append(img_array)\n",
47
+ " ages.append(age)\n",
48
+ "\n",
49
+ "X = np.array(images)\n",
50
+ "y = np.array(ages)\n",
51
+ "\n",
52
+ "# Transpose image dimensions to match PyTorch format (N, C, H, W)\n",
53
+ "X = np.transpose(X, (0, 3, 1, 2))\n",
54
+ "\n",
55
+ "# Split Data\n",
56
+ "X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)\n",
57
+ "\n",
58
+ "print(f\"X_train shape: {X_train.shape}\")\n",
59
+ "print(f\"X_test shape: {X_test.shape}\")\n",
60
+ "print(f\"y_train shape: {y_train.shape}\")\n",
61
+ "print(f\"y_test shape: {y_test.shape}\")"
62
+ ],
63
+ "execution_count": null,
64
+ "outputs": []
65
+ },
66
+ {
67
+ "cell_type": "code",
68
+ "metadata": {},
69
+ "source": [
70
+ "import kagglehub\n",
71
+ "import pandas as pd\n",
72
+ "import torch\n",
73
+ "import torch.nn as nn\n",
74
+ "from torch.optim import AdamW\n",
75
+ "import matplotlib.pyplot as plt\n",
76
+ "import torch.nn.functional as F\n",
77
+ "from torch.utils.data import DataLoader, TensorDataset\n",
78
+ "from sklearn.model_selection import train_test_split\n",
79
+ "from sklearn.preprocessing import StandardScaler, LabelEncoder\n",
80
+ "from sklearn.datasets import load_breast_cancer\n",
81
+ "from sklearn.model_selection import train_test_split\n",
82
+ "from sklearn.preprocessing import StandardScaler\n",
83
+ "from torch.utils.data import TensorDataset\n",
84
+ "from torch.utils.data import DataLoader\n",
85
+ "import torch\n",
86
+ "import matplotlib.pyplot as plt"
87
+ ],
88
+ "execution_count": null,
89
+ "outputs": []
90
+ },
91
+ {
92
+ "cell_type": "code",
93
+ "metadata": {},
94
+ "source": [
95
+ "# 1. Convert Numpy arrays to PyTorch Tensors\n",
96
+ "\n",
97
+ "# load data\n",
98
+ "data = load_breast_cancer()\n",
99
+ "X = data.data\n",
100
+ "y = data.target\n",
101
+ "\n",
102
+ "# Split the dataset into training and testing sets\n",
103
+ "X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42, stratify=y)\n",
104
+ "\n",
105
+ "# Standardize the data\n",
106
+ "scaler = StandardScaler()\n",
107
+ "X_train = scaler.fit_transform(X_train)\n",
108
+ "X_test = scaler.transform(X_test)\n",
109
+ "\n",
110
+ "# transform to tensors\n",
111
+ "X_train = torch.tensor(X_train, dtype=torch.float32)\n",
112
+ "X_test = torch.tensor(X_test, dtype=torch.float32)\n",
113
+ "y_train = torch.tensor(y_train, dtype=torch.float32)\n",
114
+ "y_test = torch.tensor(y_test, dtype=torch.float32)\n",
115
+ "\n",
116
+ "# TensorDataset pairs input features (X) with their corresponding labels (y)\n",
117
+ "# Each item in the dataset is returned as (X[i], y[i])\n",
118
+ "train_dataset = TensorDataset(X_train, y_train)\n",
119
+ "test_dataset = TensorDataset(X_test, y_test)\n",
120
+ "\n",
121
+ "# Access a single sample from the dataset\n",
122
+ "# This helps verify the shape of one data sample\n",
123
+ "first_sample, _ = train_dataset[0]\n",
124
+ "print(f\"Shape of one sample: {first_sample.shape}\")\n",
125
+ "\n",
126
+ "from torchvision.datasets import MNIST\n",
127
+ "from torchvision.transforms.functional import to_tensor\n",
128
+ "\n",
129
+ "# Training dataset\n",
130
+ "train_dataset = MNIST(\n",
131
+ " root='./datasets', # Dataset storage path\n",
132
+ " train=True, # Use training data\n",
133
+ " transform=to_tensor, # Convert images to tensors\n",
134
+ " download=True # Download if not available\n",
135
+ ")\n",
136
+ "\n",
137
+ "# Testing dataset\n",
138
+ "test_dataset = MNIST(\n",
139
+ " root='./datasets', # Dataset storage path\n",
140
+ " train=False, # Use test data\n",
141
+ " transform=to_tensor, # Convert images to tensors\n",
142
+ " download=True # Download if not available\n",
143
+ ")\n",
144
+ "\n",
145
+ "# print one sample from the dataset\n",
146
+ "# Each sample consists of an image tensor and its label\n",
147
+ "sample_image, sample_label = train_dataset[0]\n",
148
+ "\n",
149
+ "print(f\"\\n Image shape: {sample_image.shape}\") # (1, 28, 28)\n",
150
+ "print(f\"Label: {sample_label}\")\n",
151
+ "\n",
152
+ "\n"
153
+ ],
154
+ "execution_count": null,
155
+ "outputs": []
156
+ },
157
+ {
158
+ "cell_type": "code",
159
+ "metadata": {},
160
+ "source": [
161
+ "# 2. Create TensorDataset objects\n",
162
+ "# Create TensorDatasets for training and testing\n",
163
+ "train_dataset = TensorDataset(X_train, y_train)\n",
164
+ "test_dataset = TensorDataset(X_test, y_test)\n",
165
+ "\n",
166
+ "# Create Dataloaders to train and test data in batches\n",
167
+ "train_loader = DataLoader(train_dataset, batch_size=32, shuffle=True)\n",
168
+ "test_loader = DataLoader(test_dataset, batch_size=32, shuffle=False)\n",
169
+ "\n",
170
+ "# Print dataset sizes\n",
171
+ "print(\"Train dataset:\", len(train_dataset))\n",
172
+ "print(\"Test dataset:\", len(test_dataset))\n",
173
+ "\n",
174
+ "\n",
175
+ "\n"
176
+ ],
177
+ "execution_count": null,
178
+ "outputs": []
179
+ },
180
+ {
181
+ "cell_type": "code",
182
+ "metadata": {},
183
+ "source": [
184
+ "# 3. Create DataLoaders\n",
185
+ "train_dataset = TensorDataset(X_train, y_train)\n",
186
+ "test_dataset = TensorDataset(X_test, y_test)\n",
187
+ "\n",
188
+ "\n",
189
+ "train_loader = DataLoader(train_dataset, batch_size=32, shuffle=True)\n",
190
+ "test_loader = DataLoader(test_dataset, batch_size=32, shuffle=False)\n",
191
+ "\n"
192
+ ],
193
+ "execution_count": null,
194
+ "outputs": []
195
+ },
196
+ {
197
+ "cell_type": "code",
198
+ "metadata": {},
199
+ "source": [
200
+ "# 4. Print shape of one batch\n",
201
+ "\n",
202
+ "X_batch, y_batch = next(iter(train_loader))\n",
203
+ "print(f\"Training batch input shape: {X_batch.shape}\")\n",
204
+ "print(f\"Training batch labels shape: {y_batch.shape}\")\n",
205
+ "\n"
206
+ ],
207
+ "execution_count": null,
208
+ "outputs": []
209
+ },
210
+ {
211
+ "cell_type": "code",
212
+ "metadata": {},
213
+ "source": [
214
+ "X_train[41][0]"
215
+ ],
216
+ "execution_count": null,
217
+ "outputs": []
218
+ },
219
+ {
220
+ "cell_type": "code",
221
+ "metadata": {},
222
+ "source": [
223
+ "# DataLoader for training data\n",
224
+ "train_loader = DataLoader(\n",
225
+ " train_dataset,\n",
226
+ " batch_size=32,\n",
227
+ " shuffle=True,\n",
228
+ " num_workers=2\n",
229
+ ")\n",
230
+ "# DataLoader for test/validation data\n",
231
+ "test_loader = DataLoader(\n",
232
+ " test_dataset,\n",
233
+ " batch_size=32,\n",
234
+ " shuffle=False,\n",
235
+ " num_workers=2\n",
236
+ ")\n",
237
+ "# Get the first batch from the training DataLoader\n",
238
+ "X_batch, y_batch = next(iter(train_loader))\n",
239
+ "print(f\"Training batch input shape: {X_batch.shape}\")\n",
240
+ "print(f\"Training batch labels shape: {y_batch.shape}\")"
241
+ ],
242
+ "execution_count": null,
243
+ "outputs": []
244
+ },
245
+ {
246
+ "cell_type": "code",
247
+ "metadata": {},
248
+ "source": [
249
+ "# 5. Display sample images\n",
250
+ "images, labels = next(iter(train_loader))\n",
251
+ "\n",
252
+ "# Display the first 6 images in the batch\n",
253
+ "plt.figure(figsize=(8, 4))\n",
254
+ "\n",
255
+ "\n",
256
+ "plt.tight_layout()\n",
257
+ "plt.show()"
258
+ ],
259
+ "execution_count": null,
260
+ "outputs": []
261
+ },
262
+ {
263
+ "cell_type": "code",
264
+ "metadata": {},
265
+ "source": [
266
+ "# Task 1:\n",
267
+ "class NN4Layer(nn.Module):\n",
268
+ "\n",
269
+ " def __init__(self, input_dim, hidden_dim, output_dim):\n",
270
+ " super(NN4Layer, self).__init__()\n",
271
+ "\n",
272
+ " # First linear layer: input features -> hidden layer\n",
273
+ " self.layer1 = nn.Linear(input_dim, hidden_dim)\n",
274
+ "\n",
275
+ " # Second linear layer: hidden layer -> hidden layer\n",
276
+ " self.layer2 = nn.Linear(hidden_dim, hidden_dim)\n",
277
+ "\n",
278
+ " # Third linear layer: hidden layer -> hidden layer\n",
279
+ " self.layer3 = nn.Linear(hidden_dim, hidden_dim)\n",
280
+ "\n",
281
+ " # Output layer: hidden layer -> number of classes (logits)\n",
282
+ " self.layer4 = nn.Linear(hidden_dim, output_dim)\n",
283
+ "\n",
284
+ " # ReLU activation for non-linearity\n",
285
+ " self.relu = nn.ReLU()\n",
286
+ "\n",
287
+ " # Defines how input data flows through the network\n",
288
+ " def forward(self, x):\n",
289
+ " # First hidden layer\n",
290
+ " a1 = self.relu(self.layer1(x))\n",
291
+ "\n",
292
+ " # Second hidden layer\n",
293
+ " a2 = self.relu(self.layer2(a1))\n",
294
+ "\n",
295
+ " # Third hidden layer\n",
296
+ " a3 = self.relu(self.layer3(a2))\n",
297
+ "\n",
298
+ " # Output layer (raw scores / logits)\n",
299
+ " output = self.layer4(a3)\n",
300
+ "\n",
301
+ " return output"
302
+ ],
303
+ "execution_count": null,
304
+ "outputs": []
305
+ },
306
+ {
307
+ "cell_type": "code",
308
+ "metadata": {},
309
+ "source": [
310
+ "# Task 2:\n",
311
+ "def train_one_epoch(model, optimizer, criterion, train_loader, device):\n",
312
+ " # Set the model to training mode\n",
313
+ " model.train()\n",
314
+ "\n",
315
+ " running_loss = 0.0\n",
316
+ "\n",
317
+ " for X_batch, y_batch in train_loader:\n",
318
+ " # Move batch to the selected device\n",
319
+ " X_batch = X_batch.to(device) # shape: (batch_size, num_features)\n",
320
+ " y_batch = y_batch.to(device) # shape: (batch_size,)\n",
321
+ "\n",
322
+ " # Forward pass (outputs are logits)\n",
323
+ " outputs = model(X_batch) # shape: (batch_size, num_classes)\n",
324
+ " loss = criterion(outputs, y_batch)\n",
325
+ "\n",
326
+ " # Backward pass & optimization\n",
327
+ " optimizer.zero_grad() # Clear previous gradients\n",
328
+ " loss.backward() # Compute gradients\n",
329
+ " optimizer.step() # Update model parameters\n",
330
+ "\n",
331
+ " running_loss += loss.item()\n",
332
+ "\n",
333
+ " # Average loss over all batches\n",
334
+ " avg_loss = running_loss / len(train_loader)\n",
335
+ "\n",
336
+ " return avg_loss\n"
337
+ ],
338
+ "execution_count": null,
339
+ "outputs": []
340
+ },
341
+ {
342
+ "cell_type": "code",
343
+ "metadata": {},
344
+ "source": [
345
+ "# Task 3:\n",
346
+ "def validate(model, criterion, test_loader, device):\n",
347
+ " # Set the model to evaluation mode\n",
348
+ " model.eval()\n",
349
+ "\n",
350
+ " running_loss = 0.0\n",
351
+ " correct = 0\n",
352
+ " total = 0\n",
353
+ "\n",
354
+ " with torch.no_grad():\n",
355
+ " for X_batch, y_batch in test_loader:\n",
356
+ " # Move data to device\n",
357
+ " X_batch = X_batch.to(device) # shape: (batch_size, num_features)\n",
358
+ " y_batch = y_batch.to(device) # shape: (batch_size,)\n",
359
+ "\n",
360
+ " # Forward pass\n",
361
+ " outputs = model(X_batch) # shape: (batch_size, num_classes)\n",
362
+ " loss = criterion(outputs, y_batch)\n",
363
+ " running_loss += loss.item()\n",
364
+ "\n",
365
+ " # Apply Softmax to get probabilities\n",
366
+ " probabilities = F.softmax(outputs, dim=1)\n",
367
+ "\n",
368
+ " # Pick the classes with highest probabilities\n",
369
+ " predicted = torch.argmax(probabilities, dim=1)\n",
370
+ "\n",
371
+ " # Accuracy calculation\n",
372
+ " correct += (predicted == y_batch).sum().item()\n",
373
+ " total += y_batch.size(0)\n",
374
+ "\n",
375
+ " avg_loss = running_loss / len(test_loader)\n",
376
+ " accuracy = correct / total\n",
377
+ "\n",
378
+ " return avg_loss, accuracy"
379
+ ],
380
+ "execution_count": null,
381
+ "outputs": []
382
+ },
383
+ {
384
+ "cell_type": "code",
385
+ "metadata": {},
386
+ "source": [
387
+ "# Task 4:\n",
388
+ "# Device setup\n",
389
+ "device = torch.device(\"cuda\" if torch.cuda.is_available() else \"cpu\")\n",
390
+ "\n",
391
+ "# Model parameters\n",
392
+ "input_dim = X_train.shape[1] # Number of tabular features\n",
393
+ "hidden_dim = 14 # Design choice\n",
394
+ "output_dim = 4 # Weather classes: Rainy, Sunny, Cloudy, Snowy\n",
395
+ "\n",
396
+ "# Instantiate model\n",
397
+ "model = NN4Layer(input_dim, hidden_dim, output_dim).to(device)\n",
398
+ "\n",
399
+ "# Print the model architecture\n",
400
+ "print(\"Model Architecture:\\n\")\n",
401
+ "print(model)\n",
402
+ "\n",
403
+ "# Calculate the total number of trainable parameters\n",
404
+ "total_params = sum(p.numel() for p in model.parameters() if p.requires_grad)\n",
405
+ "print(f\"\\nTotal trainable parameters: {total_params}\")\n",
406
+ "\n",
407
+ "\n",
408
+ "num_epochs = 20\n",
409
+ "learning_rate = 0.001\n",
410
+ "\n",
411
+ "# Define criterion (loss function) - using CrossEntropyLoss as model now outputs logits\n",
412
+ "criterion = nn.CrossEntropyLoss()\n",
413
+ "# Define optimizer\n",
414
+ "optimizer = AdamW(model.parameters(), learning_rate)\n"
415
+ ],
416
+ "execution_count": null,
417
+ "outputs": []
418
+ },
419
+ {
420
+ "cell_type": "code",
421
+ "metadata": {},
422
+ "source": [
423
+ "# Task 5:\n",
424
+ "train_losses = []\n",
425
+ "val_losses = []\n",
426
+ "val_accuracies = []\n",
427
+ "\n",
428
+ "print('Starting Training...')\n",
429
+ "for epoch in range(num_epochs):\n",
430
+ " # Train one epoch\n",
431
+ " train_loss = train_one_epoch(model, optimizer, criterion, train_loader, device)\n",
432
+ "\n",
433
+ " # Validate\n",
434
+ " val_loss, val_accuracy = validate(model, criterion, test_loader, device)\n",
435
+ "\n",
436
+ " train_losses.append(train_loss)\n",
437
+ " val_losses.append(val_loss)\n",
438
+ " val_accuracies.append(val_accuracy)\n",
439
+ "\n",
440
+ " print(f'Epoch [{epoch+1}/{num_epochs}], Train Loss: {train_loss:.4f}, Val Loss: {val_loss:.4f}, Val Accuracy: {val_accuracy:.4f}')\n",
441
+ "\n",
442
+ "print('Training Complete!')"
443
+ ],
444
+ "execution_count": null,
445
+ "outputs": []
446
+ },
447
+ {
448
+ "cell_type": "code",
449
+ "metadata": {},
450
+ "source": [
451
+ "# Task 1:\n",
452
+ "plt.figure(figsize=(7, 5))\n",
453
+ "\n",
454
+ "plt.plot(train_losses, label='Train Loss')\n",
455
+ "plt.plot(val_losses, label='Validation Loss')\n",
456
+ "plt.title('Loss over Epochs')\n",
457
+ "plt.xlabel('Epoch')\n",
458
+ "plt.ylabel('Loss')\n",
459
+ "plt.legend()\n",
460
+ "\n",
461
+ "plt.tight_layout()\n",
462
+ "plt.show()"
463
+ ],
464
+ "execution_count": null,
465
+ "outputs": []
466
+ },
467
+ {
468
+ "cell_type": "code",
469
+ "metadata": {},
470
+ "source": [
471
+ "# Task 2 (Bonus): Write your code here:"
472
+ ],
473
+ "execution_count": null,
474
+ "outputs": []
475
+ }
476
+ ],
477
+ "metadata": {
478
+ "kernelspec": {
479
+ "display_name": "Python 3",
480
+ "name": "python3"
481
+ },
482
+ "language_info": {
483
+ "name": "python"
484
+ }
485
+ },
486
+ "nbformat": 4,
487
+ "nbformat_minor": 0
488
+ }
submissions_extracted/1011/Q3.ipynb ADDED
@@ -0,0 +1,332 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "metadata": {},
6
+ "source": [
7
+ "import kagglehub\n",
8
+ "\n",
9
+ "# Download latest version\n",
10
+ "path = kagglehub.dataset_download(\"ANON_OWNER/q3-exam-data\")\n",
11
+ "\n",
12
+ "print(\"Path to dataset files:\", path)"
13
+ ],
14
+ "execution_count": null,
15
+ "outputs": []
16
+ },
17
+ {
18
+ "cell_type": "code",
19
+ "metadata": {},
20
+ "source": [
21
+ "%pip install kagglehub catboost xgboost tqdm imbalanced-learn -q\n"
22
+ ],
23
+ "execution_count": null,
24
+ "outputs": []
25
+ },
26
+ {
27
+ "cell_type": "code",
28
+ "metadata": {},
29
+ "source": [
30
+ "import numpy as np\n",
31
+ "import pandas as pd\n",
32
+ "import matplotlib.pyplot as plt\n",
33
+ "import os\n",
34
+ "import kagglehub\n",
35
+ "from catboost import CatBoostClassifier\n",
36
+ "from sklearn.metrics import accuracy_score, f1_score\n",
37
+ "from sklearn.model_selection import StratifiedKFold\n",
38
+ "\n",
39
+ "\n",
40
+ "from sklearn.model_selection import train_test_split, StratifiedKFold, cross_val_score\n",
41
+ "from sklearn.preprocessing import StandardScaler, LabelEncoder\n",
42
+ "from sklearn.ensemble import RandomForestClassifier\n",
43
+ "from sklearn.metrics import classification_report, confusion_matrix, accuracy_score\n"
44
+ ],
45
+ "execution_count": null,
46
+ "outputs": []
47
+ },
48
+ {
49
+ "cell_type": "code",
50
+ "metadata": {},
51
+ "source": [
52
+ "# Task 1:\n",
53
+ "golden_path = os.path.join(path, 'Q3_data.csv')\n",
54
+ "df_golden = pd.read_csv(golden_path)\n"
55
+ ],
56
+ "execution_count": null,
57
+ "outputs": []
58
+ },
59
+ {
60
+ "cell_type": "code",
61
+ "metadata": {},
62
+ "source": [
63
+ "# Task 2:\n",
64
+ "print(f\"Dataset shape: {df_golden.shape}\")\n",
65
+ "df_golden.head()"
66
+ ],
67
+ "execution_count": null,
68
+ "outputs": []
69
+ },
70
+ {
71
+ "cell_type": "code",
72
+ "metadata": {},
73
+ "source": [
74
+ "# Task 3:\n",
75
+ "df_golden.info()"
76
+ ],
77
+ "execution_count": null,
78
+ "outputs": []
79
+ },
80
+ {
81
+ "cell_type": "code",
82
+ "metadata": {},
83
+ "source": [
84
+ "df_golden.count()\n",
85
+ "\n",
86
+ "\n",
87
+ "#the data is huge so i assue any value >20001 has a missing. and solve the entire Q with this problem :( i ask 2 TAs"
88
+ ],
89
+ "execution_count": null,
90
+ "outputs": []
91
+ },
92
+ {
93
+ "cell_type": "code",
94
+ "metadata": {},
95
+ "source": [
96
+ "# Task 4:\n",
97
+ "df_golden.describe()"
98
+ ],
99
+ "execution_count": null,
100
+ "outputs": []
101
+ },
102
+ {
103
+ "cell_type": "code",
104
+ "metadata": {},
105
+ "source": [
106
+ "# Task 1:\n",
107
+ "df_clean = df_golden[df_golden.count()].copy()\n",
108
+ "\n",
109
+ "df_clean['P_2'] = df_clean['P_2'].fillna(df_clean['P_2'].mean())\n",
110
+ "df_clean['B_2'] = df_clean['B_2'].fillna(df_clean['B_2'].mean())\n",
111
+ "df_clean['D_142'] = df_clean['D_142'].fillna(df_clean['D_142'].mean())\n",
112
+ "df_clean['D_143'] = df_clean['D_143'].fillna(df_clean['D_143'].mean())\n",
113
+ "df_clean['D_144'] = df_clean['D_144'].fillna(df_clean['D_144'].mean())\n",
114
+ "df_clean['D_145'] = df_clean['D_145'].fillna(df_clean['D_145'].mean())\n",
115
+ "\n",
116
+ "print(\"Missing values remaining:\", df_clean.isnull().sum().sum())\n",
117
+ "\n"
118
+ ],
119
+ "execution_count": null,
120
+ "outputs": []
121
+ },
122
+ {
123
+ "cell_type": "code",
124
+ "metadata": {},
125
+ "source": [
126
+ "# Task 2:\n",
127
+ "def check_duplicates(df):\n",
128
+ " duplicates = df.duplicated().sum()\n",
129
+ " print(f\"Number of Duplicate Samples: {duplicates}\")\n",
130
+ " if duplicates > 0:\n",
131
+ " print(\"Dropping Duplicates...\")\n",
132
+ " df.drop_duplicates(inplace=True)\n",
133
+ " print(\"Duplicates Dropped.\")\n",
134
+ " else:\n",
135
+ " print(\"No Duplicate Samples Found.\")\n",
136
+ "\n",
137
+ "check_duplicates(train_df)"
138
+ ],
139
+ "execution_count": null,
140
+ "outputs": []
141
+ },
142
+ {
143
+ "cell_type": "code",
144
+ "metadata": {},
145
+ "source": [
146
+ "# Task 3:\n",
147
+ "categorical_cols = [df_golden.count()]\n",
148
+ "for col in categorical_cols:\n",
149
+ " le = LabelEncoder()\n",
150
+ " df_clean[col] = le.fit_transform(df_clean[col].astype(str))\n",
151
+ "\n",
152
+ "df_clean.head()"
153
+ ],
154
+ "execution_count": null,
155
+ "outputs": []
156
+ },
157
+ {
158
+ "cell_type": "code",
159
+ "metadata": {},
160
+ "source": [
161
+ "# Task 4:\n",
162
+ "scaler = StandardScaler()\n",
163
+ "X_train_scaled = scaler.fit_transform(X_train)\n",
164
+ "X_test_scaled = scaler.transform(X_test)\n",
165
+ "\n",
166
+ "print(f\"\\nScaled ranges - Min: {X_train_scaled.min():.2f}, Max: {X_train_scaled.max():.2f}\")\n",
167
+ "pd.DataFrame(X_train_scaled, columns=X_train.columns).head(3)\n"
168
+ ],
169
+ "execution_count": null,
170
+ "outputs": []
171
+ },
172
+ {
173
+ "cell_type": "code",
174
+ "metadata": {},
175
+ "source": [
176
+ "# Task 5:\n",
177
+ "print(f\"\\nFeature ranges - Min: {X_train.min().min():.2f}, Max: {X_train.max().max():.2f}\")\n",
178
+ "X_train.head(3)"
179
+ ],
180
+ "execution_count": null,
181
+ "outputs": []
182
+ },
183
+ {
184
+ "cell_type": "code",
185
+ "metadata": {},
186
+ "source": [
187
+ "# Task 1:\n",
188
+ "feature_cols = ['P_2', 'D_39', 'B_1', 'B_2','R_1']\n",
189
+ "\n",
190
+ "X = df_clean[feature_cols]\n",
191
+ "y = df_clean['R_1']\n",
192
+ "\n",
193
+ "# Train-test split (80% train, 20% test)\n",
194
+ "X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)\n",
195
+ "print(f\"Train: {X_train.shape}, Test: {X_test.shape}\")"
196
+ ],
197
+ "execution_count": null,
198
+ "outputs": []
199
+ },
200
+ {
201
+ "cell_type": "code",
202
+ "metadata": {},
203
+ "source": [
204
+ "# Task 2,3,4,5:\n",
205
+ "model = CatBoostClassifier(\n",
206
+ " verbose=0,\n",
207
+ " n_estimators=200,\n",
208
+ " max_depth=4\n",
209
+ " )\n",
210
+ "\n",
211
+ "model.fit(X_train_scaled, y_train)\n",
212
+ "print(\"Model trained!\")\n",
213
+ "\n",
214
+ "y_pred = model.predict(X_test_scaled)\n",
215
+ "\n",
216
+ "accuracy = accuracy_score(y_test, y_pred)\n",
217
+ "f1 = f1_score(y_test, y_pred, average='macro')\n",
218
+ "\n",
219
+ "sr_results['acc'].append(accuracy)\n",
220
+ "sr_results['f1'].append(f1)\n",
221
+ "\n",
222
+ "print(f\" Accuracy: {np.mean(sr_results['acc']):.4f}\")\n",
223
+ "print(f\" F1-Score: {np.mean(sr_results['f1']):.4f}\")\n",
224
+ "\n",
225
+ "#kfold = KFold(n_splits=5, shuffle=True, random_state=42)\n",
226
+ "\n",
227
+ "#for train_idx, val_idx in kfold.split(X_train_scaled):\n",
228
+ "# X_fold_train, X_fold_val = X_train_scaled[train_idx], X_train_scaled[val_idx]\n",
229
+ "# y_fold_train, y_fold_val = y_train.iloc[train_idx], y_train.iloc[val_idx]\n",
230
+ "\n",
231
+ " # Train and predict\n",
232
+ " # model.fit(X_fold_train, y_fold_train)\n",
233
+ " # y_fold_pred = model.predict(X_fold_val)\n",
234
+ "\n",
235
+ "#print(f\"5-Fold CV Results:\")\n",
236
+ "\n",
237
+ "n_splits = 3 # K=3 Folds\n",
238
+ "\n",
239
+ "skf = StratifiedKFold(n_splits=n_splits, shuffle=True, random_state=42)\n",
240
+ "\n",
241
+ "sr_results = {'loss': [], 'acc': [], 'f1': []}\n",
242
+ "\n",
243
+ "for fold_idx, (train_index, test_index) in enumerate(skf.split(X, y)):\n",
244
+ "\n",
245
+ " print(f\"\\nFold {fold_idx + 1}/{n_splits}\")\n",
246
+ "\n",
247
+ " # Get the train & test split for this fold\n",
248
+ " X_train, X_test = X.iloc[train_index], X.iloc[test_index]\n",
249
+ " y_train, y_test = y.iloc[train_index], y.iloc[test_index]\n",
250
+ "\n",
251
+ " # Train using gradient descent with learning rate = 0.5\n",
252
+ " theta, losses = gradient_descent(X_train, y_train, lr=0.5, num_classes=4)\n",
253
+ "\n",
254
+ " # Calculate z & class probabilities for X_test\n",
255
+ " z = np.dot(X_test, theta)\n",
256
+ " y_pred_proba = softmax(z)\n",
257
+ "\n",
258
+ " # Pick the predicted classes with the highest probability\n",
259
+ " y_pred = np.argmax(y_pred_proba, axis=1)\n",
260
+ "\n",
261
+ " # Calculate evaluation metrics\n",
262
+ " accuracy = accuracy_score(y_test, y_pred)\n",
263
+ " f1 = f1_score(y_test, y_pred, average='macro') # for multiclass f1 score, you should set the average hyperparameter (\"macro\", \"micro\", \"weighted\")\n",
264
+ "\n",
265
+ " # Store results\n",
266
+ " sr_results['loss'].append(losses)\n",
267
+ " sr_results['acc'].append(accuracy)\n",
268
+ " sr_results['f1'].append(f1)\n",
269
+ "\n",
270
+ " avg_loss = np.mean(sr_results['loss'], axis=0)\n",
271
+ "\n"
272
+ ],
273
+ "execution_count": null,
274
+ "outputs": []
275
+ },
276
+ {
277
+ "cell_type": "code",
278
+ "metadata": {},
279
+ "source": [
280
+ "# Task 1:\n",
281
+ "feature_importance = pd.DataFrame({\n",
282
+ " 'feature': feature_cols,\n",
283
+ " 'importance': model.feature_importances_\n",
284
+ "}).sort_values('importance', ascending=False)\n",
285
+ "\n",
286
+ "plt.figure(figsize=(10, 6))\n",
287
+ "plt.barh(feature_importance['feature'], feature_importance['importance'])\n",
288
+ "plt.xlabel('Importance')\n",
289
+ "plt.title('Feature Importance')\n",
290
+ "plt.gca().invert_yaxis()\n",
291
+ "plt.show()"
292
+ ],
293
+ "execution_count": null,
294
+ "outputs": []
295
+ },
296
+ {
297
+ "cell_type": "code",
298
+ "metadata": {},
299
+ "source": [
300
+ "# Task 2:\n",
301
+ "plt.figure(figsize=(10, 5))\n",
302
+ "plt.hist(df_golden['R_1'].dropna(), bins=30, edgecolor='black', color='orange')\n",
303
+ "plt.title('R_1 Distribution')\n",
304
+ "plt.xlabel('R_1')\n",
305
+ "plt.ylabel('Frequency')\n",
306
+ "plt.show()"
307
+ ],
308
+ "execution_count": null,
309
+ "outputs": []
310
+ },
311
+ {
312
+ "cell_type": "code",
313
+ "metadata": {},
314
+ "source": [
315
+ "# Task Bonus: Write your code here:"
316
+ ],
317
+ "execution_count": null,
318
+ "outputs": []
319
+ }
320
+ ],
321
+ "metadata": {
322
+ "kernelspec": {
323
+ "display_name": "Python 3",
324
+ "name": "python3"
325
+ },
326
+ "language_info": {
327
+ "name": "python"
328
+ }
329
+ },
330
+ "nbformat": 4,
331
+ "nbformat_minor": 0
332
+ }
submissions_extracted/1012/Q1.ipynb ADDED
@@ -0,0 +1,285 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "metadata": {},
6
+ "source": [
7
+ "import kagglehub\n",
8
+ "\n",
9
+ "# Download latest version\n",
10
+ "path = kagglehub.dataset_download(\"ANON_OWNER/q1-exam-data\")\n",
11
+ "\n",
12
+ "print(\"Path to dataset files:\", path)"
13
+ ],
14
+ "execution_count": null,
15
+ "outputs": []
16
+ },
17
+ {
18
+ "cell_type": "code",
19
+ "metadata": {},
20
+ "source": [
21
+ "# Task 1: Write your code here:\n",
22
+ "# Read the dataset Q1_data.csv using read_csv()\n",
23
+ "import os\n",
24
+ "import pandas as pd\n",
25
+ "\n",
26
+ "foodDeliv_path = os.path.join(path, 'Q1_data.csv')\n",
27
+ "df_foodDeliv = pd.read_csv(foodDeliv_path)\n",
28
+ "print(f\"Dataset shape: {df_foodDeliv.shape}\")"
29
+ ],
30
+ "execution_count": null,
31
+ "outputs": []
32
+ },
33
+ {
34
+ "cell_type": "code",
35
+ "metadata": {},
36
+ "source": [
37
+ "# Task 2: Write your code here:\n",
38
+ "# Inspect the first few rows using head()\n",
39
+ "df_foodDeliv.head()"
40
+ ],
41
+ "execution_count": null,
42
+ "outputs": []
43
+ },
44
+ {
45
+ "cell_type": "code",
46
+ "metadata": {},
47
+ "source": [
48
+ "# Task 3: Write your code here:\n",
49
+ "# Display dataset information using info()\n",
50
+ "df_foodDeliv.info()"
51
+ ],
52
+ "execution_count": null,
53
+ "outputs": []
54
+ },
55
+ {
56
+ "cell_type": "code",
57
+ "metadata": {},
58
+ "source": [
59
+ "# Task 4: Write your code here:\n",
60
+ "# Show statistical description using describe()\n",
61
+ "df_foodDeliv.describe()"
62
+ ],
63
+ "execution_count": null,
64
+ "outputs": []
65
+ },
66
+ {
67
+ "cell_type": "code",
68
+ "metadata": {},
69
+ "source": [
70
+ "# Task 5: Write your code here:\n",
71
+ "# Plot the target distribution (delivery_time)\n",
72
+ "import matplotlib.pyplot as plt\n",
73
+ "\n",
74
+ "plt.figure(figsize=(10, 5))\n",
75
+ "plt.hist(df_foodDeliv['Delivery_Time'].dropna(), bins=50, edgecolor='black') # dropna drop null values\n",
76
+ "plt.title('Delivery Time Distribution')\n",
77
+ "plt.xlabel('Delivery Time')\n",
78
+ "plt.ylabel('Frequency')\n",
79
+ "plt.show()"
80
+ ],
81
+ "execution_count": null,
82
+ "outputs": []
83
+ },
84
+ {
85
+ "cell_type": "code",
86
+ "metadata": {},
87
+ "source": [
88
+ "# Task 1: Write your code here:\n",
89
+ "# Drop the 'Order_ID' column from the data\n",
90
+ "df_clean = df_foodDeliv.drop(columns=['Order_ID']).copy()\n",
91
+ "df_clean.info()"
92
+ ],
93
+ "execution_count": null,
94
+ "outputs": []
95
+ },
96
+ {
97
+ "cell_type": "code",
98
+ "metadata": {},
99
+ "source": [
100
+ "# Task 2: Write your code here:\n",
101
+ "# Handle missing values appropriately (Hint: I guess you want to have a closer look at the columns with missing values :) )\n",
102
+ "missing_columns = [\"Weather\", \"Traffic_Level\", \"Delivery_Time\", \"Courier_Experience_yrs\", \"Time_of_Day\"]\n",
103
+ "categorize_Data = df_clean[missing_columns].select_dtypes(include=[\"object\"]).columns\n",
104
+ "numbers_Data = df_clean[missing_columns].select_dtypes(include=[\"float64\"]).columns\n",
105
+ "for column in categorize_Data:\n",
106
+ " df_clean[column] = df_clean[column].fillna('unknown')\n",
107
+ "\n",
108
+ "\n",
109
+ "for column in numbers_Data:\n",
110
+ " df_clean[column] = df_clean[column].fillna(df_clean[column].mean())\n",
111
+ "\n",
112
+ "print(\"Missing values remaining:\", df_clean.isnull().sum().sum())\n",
113
+ "\n"
114
+ ],
115
+ "execution_count": null,
116
+ "outputs": []
117
+ },
118
+ {
119
+ "cell_type": "code",
120
+ "metadata": {},
121
+ "source": [
122
+ "# Task 3: Write your code here:\n",
123
+ "# Check and remove duplicates if any exist\n",
124
+ "def check_duplicates(df):\n",
125
+ " duplicates = df.duplicated().sum()\n",
126
+ " print(f\"Number of Duplicate Samples: {duplicates}\")\n",
127
+ " if duplicates > 0:\n",
128
+ " print(\"Dropping Duplicates...\")\n",
129
+ " df.drop_duplicates(inplace=True)\n",
130
+ " print(\"Duplicates Dropped.\")\n",
131
+ " else:\n",
132
+ " print(\"No Duplicate Samples Found.\")\n",
133
+ "\n",
134
+ "print(\"Duplicated:\", df_clean.duplicated().sum())\n",
135
+ "check_duplicates(df_clean)\n",
136
+ "print(\"Duplicated:\", df_clean.duplicated().sum())"
137
+ ],
138
+ "execution_count": null,
139
+ "outputs": []
140
+ },
141
+ {
142
+ "cell_type": "code",
143
+ "metadata": {},
144
+ "source": [
145
+ "# Task 4: Write your code here:\n",
146
+ "# Encode categorical variables if needed (Bonus if used One Hot Encoding)\n",
147
+ "from sklearn.preprocessing import LabelEncoder\n",
148
+ "\n",
149
+ "label_encoder = LabelEncoder()\n",
150
+ "categorize_Data = df_clean.select_dtypes(include=[\"object\"]).columns\n",
151
+ "for column in categorize_Data:\n",
152
+ " df_clean[column] = label_encoder.fit_transform(df_clean[column])\n",
153
+ "\n",
154
+ "df_clean.head()"
155
+ ],
156
+ "execution_count": null,
157
+ "outputs": []
158
+ },
159
+ {
160
+ "cell_type": "code",
161
+ "metadata": {},
162
+ "source": [
163
+ "# Task 5: Write your code here:\n",
164
+ "# Apply feature scaling for all features (Use StandardScaler)\n",
165
+ "from sklearn.preprocessing import StandardScaler\n",
166
+ "\n",
167
+ "scaler = StandardScaler()\n",
168
+ "df_clean_scaled = scaler.fit_transform(df_clean) #####################3\n"
169
+ ],
170
+ "execution_count": null,
171
+ "outputs": []
172
+ },
173
+ {
174
+ "cell_type": "code",
175
+ "metadata": {},
176
+ "source": [
177
+ "# Task 6: Write your code here:\n",
178
+ "# Check for target imbalance and state if it is imbalanced or not (keep this cell empty if not needed)\n",
179
+ "\n",
180
+ "# we are talking about continue numbers, so not needed"
181
+ ],
182
+ "execution_count": null,
183
+ "outputs": []
184
+ },
185
+ {
186
+ "cell_type": "code",
187
+ "metadata": {},
188
+ "source": [
189
+ "# Task 1: Write your code here:\n",
190
+ "# Split the dataset into features (X) and target (y)\n",
191
+ "\n",
192
+ "X = df_clean.drop(columns=['Delivery_Time'])\n",
193
+ "y = df_clean['Delivery_Time']\n",
194
+ "\n",
195
+ "print(f\"Train: {X.shape}, Test: {y.shape}\")"
196
+ ],
197
+ "execution_count": null,
198
+ "outputs": []
199
+ },
200
+ {
201
+ "cell_type": "code",
202
+ "metadata": {},
203
+ "source": [
204
+ "# Task 2,3,4,5: Write your code here:\n",
205
+ "# Use the correct split: KFold OR StratifiedKFold\n",
206
+ "# Train a RandomForest model\n",
207
+ "# Evaluate using MAE (Mean Absolute Error) ONLY\n",
208
+ "# Print the averaged score across all folds\n",
209
+ "from sklearn.model_selection import KFold\n",
210
+ "from sklearn.ensemble import RandomForestRegressor\n",
211
+ "from sklearn.metrics import mean_absolute_error\n",
212
+ "\n",
213
+ "n_splits = 5\n",
214
+ "kf = KFold(n_splits=n_splits, shuffle=True, random_state=42)\n",
215
+ "\n",
216
+ "maeresult = 0\n",
217
+ "for fold_idx, (train_index, test_index) in enumerate(kf.split(X)):\n",
218
+ " print(f\"\\nFold {fold_idx + 1}/{n_splits}\")\n",
219
+ "\n",
220
+ " X_train, X_test = X.iloc[train_index], X.iloc[test_index]\n",
221
+ " y_train, y_test = y.iloc[train_index], y.iloc[test_index]\n",
222
+ " model = RandomForestRegressor(n_estimators=200)\n",
223
+ " model.fit(X_train, y_train)\n",
224
+ "\n",
225
+ " # Predict\n",
226
+ " y_pred = model.predict(X_test)\n",
227
+ "\n",
228
+ " # Calculate metrics\n",
229
+ " mae = mean_absolute_error(y_test, y_pred)\n",
230
+ " maeresult += mae\n",
231
+ "print(\"mae result:\", maeresult / n_splits)\n",
232
+ "\n"
233
+ ],
234
+ "execution_count": null,
235
+ "outputs": []
236
+ },
237
+ {
238
+ "cell_type": "code",
239
+ "metadata": {},
240
+ "source": [
241
+ "# Task 1: Write your code here:\n",
242
+ "# Plot feature importance from your trained model\n",
243
+ "# Create a 1x3 plot\n"
244
+ ],
245
+ "execution_count": null,
246
+ "outputs": []
247
+ },
248
+ {
249
+ "cell_type": "code",
250
+ "metadata": {},
251
+ "source": [
252
+ "# Task 2: Write your code here:\n",
253
+ "# Plot predicted delivery time histogram\n",
254
+ "plt.figure(figsize=(10, 5))\n",
255
+ "plt.hist(y_pred, bins=50, edgecolor='black') # dropna drop null values\n",
256
+ "plt.title('Delivery Time Distribution')\n",
257
+ "plt.xlabel('Delivery Time')\n",
258
+ "plt.ylabel('Frequency')\n",
259
+ "plt.show()"
260
+ ],
261
+ "execution_count": null,
262
+ "outputs": []
263
+ },
264
+ {
265
+ "cell_type": "code",
266
+ "metadata": {},
267
+ "source": [
268
+ "# Task Bonus: Write your code here:"
269
+ ],
270
+ "execution_count": null,
271
+ "outputs": []
272
+ }
273
+ ],
274
+ "metadata": {
275
+ "kernelspec": {
276
+ "display_name": "Python 3",
277
+ "name": "python3"
278
+ },
279
+ "language_info": {
280
+ "name": "python"
281
+ }
282
+ },
283
+ "nbformat": 4,
284
+ "nbformat_minor": 0
285
+ }
submissions_extracted/1012/Q2.ipynb ADDED
@@ -0,0 +1,394 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "metadata": {},
6
+ "source": [
7
+ "import kagglehub\n",
8
+ "\n",
9
+ "# Download latest version\n",
10
+ "path = kagglehub.dataset_download(\"ANON_OWNER/q2-exam-data\")\n",
11
+ "\n",
12
+ "print(\"Path to dataset files:\", path)"
13
+ ],
14
+ "execution_count": null,
15
+ "outputs": []
16
+ },
17
+ {
18
+ "cell_type": "code",
19
+ "metadata": {},
20
+ "source": [
21
+ "import os\n",
22
+ "import pandas as pd\n",
23
+ "import numpy as np\n",
24
+ "from PIL import Image\n",
25
+ "from sklearn.model_selection import train_test_split\n",
26
+ "\n",
27
+ "# Load Labels\n",
28
+ "labels_df = pd.read_csv(os.path.join(path, \"labels.csv\"))\n",
29
+ "img_dir = os.path.join(path, \"images\")\n",
30
+ "\n",
31
+ "images = []\n",
32
+ "ages = []\n",
33
+ "\n",
34
+ "# Load Images and Resize\n",
35
+ "print(\"Loading images...\")\n",
36
+ "for index, row in labels_df.iterrows():\n",
37
+ " img_name = row.iloc[0]\n",
38
+ " age = row.iloc[1]\n",
39
+ " img_path = os.path.join(img_dir, img_name)\n",
40
+ "\n",
41
+ " if os.path.exists(img_path):\n",
42
+ " img = Image.open(img_path).convert('RGB')\n",
43
+ " img_array = np.array(img) / 255.0 # Normalize pixel values to [0, 1]\n",
44
+ " images.append(img_array)\n",
45
+ " ages.append(age)\n",
46
+ "\n",
47
+ "X = np.array(images)\n",
48
+ "y = np.array(ages)\n",
49
+ "\n",
50
+ "# Transpose image dimensions to match PyTorch format (N, C, H, W)\n",
51
+ "X = np.transpose(X, (0, 3, 1, 2))\n",
52
+ "\n",
53
+ "# Split Data\n",
54
+ "X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)\n",
55
+ "\n",
56
+ "print(f\"X_train shape: {X_train.shape}\")\n",
57
+ "print(f\"X_test shape: {X_test.shape}\")\n",
58
+ "print(f\"y_train shape: {y_train.shape}\")\n",
59
+ "print(f\"y_test shape: {y_test.shape}\")"
60
+ ],
61
+ "execution_count": null,
62
+ "outputs": []
63
+ },
64
+ {
65
+ "cell_type": "code",
66
+ "metadata": {},
67
+ "source": [
68
+ "# 1. Convert Numpy arrays to PyTorch Tensors\n",
69
+ "# Convert to Tensors: Convert the numpy arrays (X_train, X_test, y_train, y_test) into PyTorch tensors.\n",
70
+ "import torch\n",
71
+ "\n",
72
+ "X_train = torch.tensor(X_train)\n",
73
+ "X_test = torch.tensor(X_test)\n",
74
+ "y_train = torch.tensor(y_train)\n",
75
+ "y_test = torch.tensor(y_test)"
76
+ ],
77
+ "execution_count": null,
78
+ "outputs": []
79
+ },
80
+ {
81
+ "cell_type": "code",
82
+ "metadata": {},
83
+ "source": [
84
+ "# 2. Create TensorDataset objects\n",
85
+ "# Create Datasets: Use TensorDataset to create train_dataset and test_dataset from the tensors.\n",
86
+ "from torch.utils.data import TensorDataset\n",
87
+ "\n",
88
+ "train_dataset = TensorDataset(X_train, y_train)\n",
89
+ "test_dataset = TensorDataset(X_test, y_test)\n"
90
+ ],
91
+ "execution_count": null,
92
+ "outputs": []
93
+ },
94
+ {
95
+ "cell_type": "code",
96
+ "metadata": {},
97
+ "source": [
98
+ "# 3. Create DataLoaders\n",
99
+ "# Create DataLoaders: Create train_loader and test_loader with a batch size of 32.\n",
100
+ "from torch.utils.data import DataLoader\n",
101
+ "\n",
102
+ "train_loader = DataLoader(\n",
103
+ " train_dataset,\n",
104
+ " batch_size=32,\n",
105
+ " num_workers=2\n",
106
+ ")\n",
107
+ "# DataLoader for test/validation data\n",
108
+ "test_loader = DataLoader(\n",
109
+ " test_dataset,\n",
110
+ " batch_size=32,\n",
111
+ " num_workers=2\n",
112
+ ")\n",
113
+ "\n"
114
+ ],
115
+ "execution_count": null,
116
+ "outputs": []
117
+ },
118
+ {
119
+ "cell_type": "code",
120
+ "metadata": {},
121
+ "source": [
122
+ "# 4. Print shape of one batch\n",
123
+ "# Inspect Data: Print the shape of one batch from the train loader\n",
124
+ "\n",
125
+ "# Get the first batch from the training DataLoader\n",
126
+ "X_batch, y_batch = next(iter(train_loader))\n",
127
+ "print(f\"Training batch input shape: {X_batch.shape}\")\n",
128
+ "print(f\"Training batch labels shape: {y_batch.shape}\")"
129
+ ],
130
+ "execution_count": null,
131
+ "outputs": []
132
+ },
133
+ {
134
+ "cell_type": "code",
135
+ "metadata": {},
136
+ "source": [
137
+ "# 5. Display sample images\n",
138
+ "# Display a few images: Use matplotlib to display a few images.\n",
139
+ "import matplotlib.pyplot as plt\n",
140
+ "\n",
141
+ "images, labels = next(iter(train_loader))\n",
142
+ "\n",
143
+ "# Display the first 6 images in the batch\n",
144
+ "# it supposed to show it\n",
145
+ "plt.figure(figsize=(8, 4))\n",
146
+ "\n",
147
+ "for i in range(6):\n",
148
+ " plt.subplot(2, 3, i + 1)\n",
149
+ " plt.imshow(images[i].squeeze())\n",
150
+ " plt.title(f\"Label: {labels[i].item()}\")\n",
151
+ " plt.axis('off')\n",
152
+ "\n",
153
+ "plt.tight_layout()\n",
154
+ "plt.show()\n"
155
+ ],
156
+ "execution_count": null,
157
+ "outputs": []
158
+ },
159
+ {
160
+ "cell_type": "code",
161
+ "metadata": {},
162
+ "source": [
163
+ "# Task 1: Write your model class here:\n",
164
+ "# Create a model class with 4 linear layers\n",
165
+ "import torch.nn as nn\n",
166
+ "\n",
167
+ "class NN3Layer(nn.Module):\n",
168
+ "\n",
169
+ " def __init__(self, input_dim, hidden_dim, output_dim):\n",
170
+ " super(NN3Layer, self).__init__()\n",
171
+ "\n",
172
+ " # First linear layer: input features -> hidden layer\n",
173
+ " self.layer1 = nn.Linear(input_dim, hidden_dim)\n",
174
+ "\n",
175
+ " # Second linear layer: hidden layer -> hidden layer\n",
176
+ " self.layer2 = nn.Linear(hidden_dim, hidden_dim)\n",
177
+ "\n",
178
+ " # Output layer: hidden layer -> hidden layer\n",
179
+ " self.layer3 = nn.Linear(hidden_dim, output_dim)\n",
180
+ "\n",
181
+ " # Output layer: hidden layer -> number of classes (logits)\n",
182
+ " self.layer4 = nn.Linear(hidden_dim, output_dim)\n",
183
+ " # ReLU activation for non-linearity\n",
184
+ " self.relu = nn.ReLU()\n",
185
+ "\n",
186
+ " # Defines how input data flows through the network\n",
187
+ " def forward(self, x):\n",
188
+ " # First hidden layer\n",
189
+ " z1 = self.layer1(x)\n",
190
+ " a1 = self.relu(z1)\n",
191
+ "\n",
192
+ " # Second hidden layer\n",
193
+ " z2 = self.layer2(a1)\n",
194
+ " a2 = self.relu(z2)\n",
195
+ "\n",
196
+ " # third hidden layer\n",
197
+ " z3 = self.layer3(a2)\n",
198
+ " a3 = self.relu(z3)\n",
199
+ "\n",
200
+ " # output layer\n",
201
+ " output = self.layer3(a2)\n",
202
+ " return output\n"
203
+ ],
204
+ "execution_count": null,
205
+ "outputs": []
206
+ },
207
+ {
208
+ "cell_type": "code",
209
+ "metadata": {},
210
+ "source": [
211
+ "# Task 2: Write your training loop here:\n",
212
+ "# Create a training loop function\n",
213
+ "def train_one_epoch(model, optimizer, criterion, train_loader, device):\n",
214
+ " # Set the model to training mode\n",
215
+ " model.train()\n",
216
+ "\n",
217
+ " running_loss = 0.0\n",
218
+ "\n",
219
+ " for X_batch, y_batch in train_loader:\n",
220
+ " # Move batch to the selected device\n",
221
+ " X_batch = X_batch.view(X_batch.size(0), -1).to(device) # (batch size, remaining features)\n",
222
+ " y_batch = y_batch.to(device)\n",
223
+ "\n",
224
+ " # Forward pass\n",
225
+ " outputs = model(X_batch) # shape: (batch_size, 10)\n",
226
+ " loss = criterion(outputs, y_batch)\n",
227
+ "\n",
228
+ " # Backward pass & optimization\n",
229
+ " optimizer.zero_grad() # Clear previous gradients\n",
230
+ " loss.backward() # Compute gradients\n",
231
+ " optimizer.step() # Update model parameters\n",
232
+ "\n",
233
+ " running_loss += loss.item()\n",
234
+ "\n",
235
+ " # Average loss over all batches\n",
236
+ " avg_loss = running_loss / len(train_loader)\n",
237
+ "\n",
238
+ " return avg_loss\n"
239
+ ],
240
+ "execution_count": null,
241
+ "outputs": []
242
+ },
243
+ {
244
+ "cell_type": "code",
245
+ "metadata": {},
246
+ "source": [
247
+ "# Task 3: Write your validation loop here:\n",
248
+ "def validate(model, criterion, test_loader, device):\n",
249
+ " # Set the model to evaluation mode\n",
250
+ " model.eval()\n",
251
+ "\n",
252
+ " running_loss = 0.0\n",
253
+ " correct = 0\n",
254
+ " total = 0\n",
255
+ "\n",
256
+ " with torch.no_grad():\n",
257
+ " for X_batch, y_batch in test_loader:\n",
258
+ " # Move data to device\n",
259
+ " X_batch = X_batch.view(X_batch.size(0), -1).to(device)\n",
260
+ " y_batch = y_batch.to(device)\n",
261
+ "\n",
262
+ " # Forward pass\n",
263
+ " outputs = model(X_batch) # shape: (batch_size, 10)\n",
264
+ " loss = criterion(outputs, y_batch)\n",
265
+ " running_loss += loss.item()\n",
266
+ "\n",
267
+ " # Apply Softmax to get probabilities\n",
268
+ " probabilities = F.softmax(outputs, dim=1)\n",
269
+ "\n",
270
+ " # multi class\n",
271
+ " predicted = torch.argmax(probabilities, dim=1) # تاخذ البردكشن\n",
272
+ "\n",
273
+ " # Accuracy calculation\n",
274
+ " correct += (predicted == y_batch).sum().item()\n",
275
+ " total += y_batch.size(0)\n",
276
+ "\n",
277
+ " avg_loss = running_loss / len(test_loader)\n",
278
+ " accuracy = correct / total\n",
279
+ "\n",
280
+ " return avg_loss, accuracy"
281
+ ],
282
+ "execution_count": null,
283
+ "outputs": []
284
+ },
285
+ {
286
+ "cell_type": "code",
287
+ "metadata": {},
288
+ "source": [
289
+ "# Task 4: Define device, model, loss, optimizer:\n",
290
+ "from torch.optim import Adam\n",
291
+ "# Device setup\n",
292
+ "device = torch.device(\"cuda\" if torch.cuda.is_available() else \"cpu\")\n",
293
+ "\n",
294
+ "# Model parameters\n",
295
+ "input_dim = 36 * 36 # MNIST images flattened\n",
296
+ "hidden_dim = 6 # Design choice\n",
297
+ "output_dim = 1\n",
298
+ "\n",
299
+ "# Instantiate model\n",
300
+ "model = NN3Layer(input_dim, hidden_dim, output_dim).to(device)\n",
301
+ "\n",
302
+ "# Print the model architecture\n",
303
+ "print(\"Model Architecture:\\n\")\n",
304
+ "print(model)\n",
305
+ "\n",
306
+ "# Calculate the total number of trainable parameters\n",
307
+ "total_params = sum(p.numel() for p in model.parameters() if p.requires_grad)\n",
308
+ "print(f\"\\nTotal trainable parameters: {total_params}\")\n",
309
+ "\n",
310
+ "\n",
311
+ "learning_rate = 0.001\n",
312
+ "\n",
313
+ "\n",
314
+ "criterion = nn.MSELoss()\n",
315
+ "# Define optimizer\n",
316
+ "optimizer = Adam(model.parameters(), learning_rate)"
317
+ ],
318
+ "execution_count": null,
319
+ "outputs": []
320
+ },
321
+ {
322
+ "cell_type": "code",
323
+ "metadata": {},
324
+ "source": [
325
+ "# Task 5: Start training for 20 epochs:\n",
326
+ "num_epochs = 20\n",
327
+ "# Run Training\n",
328
+ "train_losses = []\n",
329
+ "val_losses = []\n",
330
+ "val_accuracies = []\n",
331
+ "\n",
332
+ "print('Starting Training...')\n",
333
+ "################################ it supposed to be trained but I got an error in the train_one_epoch function\n",
334
+ "for epoch in range(num_epochs):\n",
335
+ " # Train one epoch\n",
336
+ " train_loss = train_one_epoch(model, optimizer, criterion, train_loader, device)\n",
337
+ "\n",
338
+ " # Validate\n",
339
+ " val_loss, val_accuracy = validate(model, criterion, test_loader, device)\n",
340
+ "\n",
341
+ " train_losses.append(train_loss)\n",
342
+ " val_losses.append(val_loss)\n",
343
+ " val_accuracies.append(val_accuracy)\n",
344
+ "\n",
345
+ " print(f'Epoch [{epoch+1}/{num_epochs}], Train Loss: {train_loss:.4f}, Val Loss: {val_loss:.4f}, Val Accuracy: {val_accuracy:.4f}')\n",
346
+ "\n",
347
+ "print('Training Complete!')"
348
+ ],
349
+ "execution_count": null,
350
+ "outputs": []
351
+ },
352
+ {
353
+ "cell_type": "code",
354
+ "metadata": {},
355
+ "source": [
356
+ "# Task 1: Write your code here:\n",
357
+ "# Plotting results\n",
358
+ "plt.figure(figsize=(7, 5))\n",
359
+ "\n",
360
+ "plt.plot(train_losses, label='Train Loss')\n",
361
+ "plt.plot(val_losses, label='Validation Loss')\n",
362
+ "plt.title('Loss over Epochs')\n",
363
+ "plt.xlabel('Epoch')\n",
364
+ "plt.ylabel('Loss')\n",
365
+ "plt.legend()\n",
366
+ "\n",
367
+ "plt.tight_layout()\n",
368
+ "plt.show()"
369
+ ],
370
+ "execution_count": null,
371
+ "outputs": []
372
+ },
373
+ {
374
+ "cell_type": "code",
375
+ "metadata": {},
376
+ "source": [
377
+ "# Task 2 (Bonus): Write your code here:"
378
+ ],
379
+ "execution_count": null,
380
+ "outputs": []
381
+ }
382
+ ],
383
+ "metadata": {
384
+ "kernelspec": {
385
+ "display_name": "Python 3",
386
+ "name": "python3"
387
+ },
388
+ "language_info": {
389
+ "name": "python"
390
+ }
391
+ },
392
+ "nbformat": 4,
393
+ "nbformat_minor": 0
394
+ }
submissions_extracted/1012/Q3.ipynb ADDED
@@ -0,0 +1,264 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "metadata": {},
6
+ "source": [
7
+ "\n",
8
+ "import pandas as pd\n",
9
+ "import numpy as np\n",
10
+ "import matplotlib.pyplot as plt\n",
11
+ "import seaborn as sns\n",
12
+ "import kagglehub\n",
13
+ "import os\n",
14
+ "from tqdm import tqdm\n",
15
+ "\n",
16
+ "\n",
17
+ "# Download latest version\n",
18
+ "\n",
19
+ "path = kagglehub.dataset_download(\"ANON_OWNER/q3-exam-data\")\n",
20
+ "\n",
21
+ "\n",
22
+ "\n",
23
+ "print(\"Path to dataset files:\", path)"
24
+ ],
25
+ "execution_count": null,
26
+ "outputs": []
27
+ },
28
+ {
29
+ "cell_type": "code",
30
+ "metadata": {},
31
+ "source": [
32
+ "# Task 1: Write your code here:\n",
33
+ "csv_path = os.path.join(path, \"Q3_data.csv\")\n",
34
+ "\n",
35
+ "df = pd.read_csv(csv_path)\n"
36
+ ],
37
+ "execution_count": null,
38
+ "outputs": []
39
+ },
40
+ {
41
+ "cell_type": "code",
42
+ "metadata": {},
43
+ "source": [
44
+ "# Task 2: Write your code here:\n",
45
+ "df.head()"
46
+ ],
47
+ "execution_count": null,
48
+ "outputs": []
49
+ },
50
+ {
51
+ "cell_type": "code",
52
+ "metadata": {},
53
+ "source": [
54
+ "# Task 3: Write your code here:\n",
55
+ "df.head()"
56
+ ],
57
+ "execution_count": null,
58
+ "outputs": []
59
+ },
60
+ {
61
+ "cell_type": "code",
62
+ "metadata": {},
63
+ "source": [
64
+ "# Task 4: Write your code here:\n",
65
+ "df.describe()"
66
+ ],
67
+ "execution_count": null,
68
+ "outputs": []
69
+ },
70
+ {
71
+ "cell_type": "code",
72
+ "metadata": {},
73
+ "source": [
74
+ "# Task 1: Write your code here:\n",
75
+ "def check_missing_values(df):\n",
76
+ " missing_values = df.isnull().sum()\n",
77
+ " print(\"Missing Values per Column:\")\n",
78
+ " print(missing_values[missing_values > 0])\n",
79
+ " if missing_values.any():\n",
80
+ " print(\"\\nHandle Missing Values as needed.\")\n",
81
+ " else:\n",
82
+ " print(\"\\nNo Missing Values Found.\")\n",
83
+ "\n",
84
+ "check_missing_values(df)\n"
85
+ ],
86
+ "execution_count": null,
87
+ "outputs": []
88
+ },
89
+ {
90
+ "cell_type": "code",
91
+ "metadata": {},
92
+ "source": [
93
+ "# Task 2: Write your code here:\n",
94
+ "def check_duplicates(df):\n",
95
+ " duplicates = df.duplicated().sum()\n",
96
+ " print(f\"Number of Duplicate Samples: {duplicates}\")\n",
97
+ " if duplicates > 0:\n",
98
+ " print(\"Dropping Duplicates...\")\n",
99
+ " df.drop_duplicates(inplace=True)\n",
100
+ " print(\"Duplicates Dropped.\")\n",
101
+ " else:\n",
102
+ " print(\"No Duplicate Samples Found.\")\n",
103
+ "\n",
104
+ "print(\"Duplicated:\", df.duplicated().sum())\n",
105
+ "check_duplicates(df)\n",
106
+ "print(\"Duplicated:\", df.duplicated().sum())"
107
+ ],
108
+ "execution_count": null,
109
+ "outputs": []
110
+ },
111
+ {
112
+ "cell_type": "code",
113
+ "metadata": {},
114
+ "source": [
115
+ "# Task 3: Write your code here:\n",
116
+ "from sklearn.preprocessing import LabelEncoder\n",
117
+ "categorical_cols = df.select_dtypes(include=[\"object\"]).columns\n",
118
+ "\n",
119
+ "\n",
120
+ "# it suppose to run but I got an erro and I think because of the way hanlding missing values\n",
121
+ "label_encoders = {}\n",
122
+ "for col in categorical_cols:\n",
123
+ " le = LabelEncoder()\n",
124
+ " df[col] = le.fit_transform(df[col])\n",
125
+ " label_encoders[col] = le\n",
126
+ "\n",
127
+ "df\n"
128
+ ],
129
+ "execution_count": null,
130
+ "outputs": []
131
+ },
132
+ {
133
+ "cell_type": "code",
134
+ "metadata": {},
135
+ "source": [
136
+ "# Task 4: Write your code here:\n",
137
+ "# Apply feature scaling to numerical features (Use StandardScaler)\n",
138
+ "from sklearn.preprocessing import StandardScaler\n",
139
+ "\n",
140
+ "numerical_cols = df.select_dtypes(include=[\"int64\", \"float64\"]).columns.drop(\"Target\")\n",
141
+ "\n",
142
+ "scaler = StandardScaler()\n",
143
+ "df[numerical_cols] = scaler.fit_transform(df[numerical_cols])\n",
144
+ "df.head()"
145
+ ],
146
+ "execution_count": null,
147
+ "outputs": []
148
+ },
149
+ {
150
+ "cell_type": "code",
151
+ "metadata": {},
152
+ "source": [
153
+ "# Task 5: Write your code here:\n",
154
+ "def check_target_imbalance(df, target_column):\n",
155
+ " print(\"Target Distribution:\")\n",
156
+ " print(df[target_column].value_counts(normalize=True)) # normilize means finding the means\n",
157
+ " sns.countplot(x=df[target_column])\n",
158
+ " plt.title(\"Target Distribution\")\n",
159
+ " plt.show()\n",
160
+ "\n",
161
+ "check_target_imbalance(df, \"Target\")"
162
+ ],
163
+ "execution_count": null,
164
+ "outputs": []
165
+ },
166
+ {
167
+ "cell_type": "code",
168
+ "metadata": {},
169
+ "source": [
170
+ "# Task 1: Write your code here:\n",
171
+ "X = df.drop(\"Target\", axis=1).astype(float)\n",
172
+ "y = df['Target'].astype(float)"
173
+ ],
174
+ "execution_count": null,
175
+ "outputs": []
176
+ },
177
+ {
178
+ "cell_type": "code",
179
+ "metadata": {},
180
+ "source": [
181
+ "# Task 2,3,4,5: Write your code here:\n",
182
+ "from sklearn.model_selection import StratifiedKFold\n",
183
+ "from sklearn.metrics import accuracy_score, precision_score, recall_score, f1_score\n",
184
+ "from catboost import CatBoostClassifier\n",
185
+ "n_splits = 5 # K=5 Folds\n",
186
+ "\n",
187
+ "# Stratified 5-Fold Cross-Validation, shuffled\n",
188
+ "skf = StratifiedKFold(n_splits=n_splits, shuffle=True, random_state=42)\n",
189
+ "\n",
190
+ "\n",
191
+ "# Storage for logistic regression results for each fold\n",
192
+ "lr_losses = []\n",
193
+ "lr_accuracy = []\n",
194
+ "lr_precision = []\n",
195
+ "lr_recall = []\n",
196
+ "lr_f1 = []\n",
197
+ "\n",
198
+ "model = CatBoostClassifier(\n",
199
+ " verbose=0,\n",
200
+ " n_estimators=200,\n",
201
+ " max_depth=4\n",
202
+ " )\n",
203
+ "for fold_idx, (train_index, test_index) in enumerate(skf.split(X, y)):\n",
204
+ " print(f\"\\nFold {fold_idx + 1}/{n_splits}\")\n",
205
+ "\n",
206
+ " X_train, X_test = X.iloc[train_index], X.iloc[test_index]\n",
207
+ " y_train, y_test = y.iloc[train_index], y.iloc[test_index]\n",
208
+ "\n",
209
+ " model.fit(X_train, y_train)\n",
210
+ " # Validate\n",
211
+ " y_pred_proba = model.predict(X_test)\n",
212
+ "\n",
213
+ " y_pred = (y_pred_proba >= 0.5).astype(int)\n",
214
+ "\n",
215
+ " # Calculate evaluation metrics\n",
216
+ " accuracy = accuracy_score(y_test, y_pred)\n",
217
+ " precision = precision_score(y_test, y_pred, zero_division=0)\n",
218
+ " recall = recall_score(y_test, y_pred, zero_division=0)\n",
219
+ " f1 = f1_score(y_test, y_pred, zero_division=0)\n",
220
+ "\n"
221
+ ],
222
+ "execution_count": null,
223
+ "outputs": []
224
+ },
225
+ {
226
+ "cell_type": "code",
227
+ "metadata": {},
228
+ "source": [
229
+ "# Task 1: Write your code here:"
230
+ ],
231
+ "execution_count": null,
232
+ "outputs": []
233
+ },
234
+ {
235
+ "cell_type": "code",
236
+ "metadata": {},
237
+ "source": [
238
+ "# Task 2: Write your code here:"
239
+ ],
240
+ "execution_count": null,
241
+ "outputs": []
242
+ },
243
+ {
244
+ "cell_type": "code",
245
+ "metadata": {},
246
+ "source": [
247
+ "# Task Bonus: Write your code here:"
248
+ ],
249
+ "execution_count": null,
250
+ "outputs": []
251
+ }
252
+ ],
253
+ "metadata": {
254
+ "kernelspec": {
255
+ "display_name": "Python 3",
256
+ "name": "python3"
257
+ },
258
+ "language_info": {
259
+ "name": "python"
260
+ }
261
+ },
262
+ "nbformat": 4,
263
+ "nbformat_minor": 0
264
+ }