divya55 commited on
Commit
6bb31c8
Β·
verified Β·
1 Parent(s): 8dd5280

Upload 5 files

Browse files
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ src/fruit_dataset.csv filter=lfs diff=lfs merge=lfs -text
src/ML_Image_classification.ipynb ADDED
@@ -0,0 +1,1712 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "nbformat": 4,
3
+ "nbformat_minor": 0,
4
+ "metadata": {
5
+ "colab": {
6
+ "provenance": []
7
+ },
8
+ "kernelspec": {
9
+ "name": "python3",
10
+ "display_name": "Python 3"
11
+ },
12
+ "language_info": {
13
+ "name": "python"
14
+ }
15
+ },
16
+ "cells": [
17
+ {
18
+ "cell_type": "code",
19
+ "source": [
20
+ "import os\n",
21
+ "import cv2\n",
22
+ "import numpy as np\n",
23
+ "import pandas as pd"
24
+ ],
25
+ "metadata": {
26
+ "id": "RRIHYeA8vZ2f"
27
+ },
28
+ "execution_count": null,
29
+ "outputs": []
30
+ },
31
+ {
32
+ "cell_type": "code",
33
+ "execution_count": null,
34
+ "metadata": {
35
+ "colab": {
36
+ "base_uri": "https://localhost:8080/"
37
+ },
38
+ "id": "jYHkQveBL7JQ",
39
+ "outputId": "7b23f722-2369-4842-c8ed-7e274bdbe589"
40
+ },
41
+ "outputs": [
42
+ {
43
+ "output_type": "stream",
44
+ "name": "stdout",
45
+ "text": [
46
+ "Drive already mounted at /content/drive; to attempt to forcibly remount, call drive.mount(\"/content/drive\", force_remount=True).\n"
47
+ ]
48
+ }
49
+ ],
50
+ "source": [
51
+ "from google.colab import drive\n",
52
+ "drive.mount('/content/drive')"
53
+ ]
54
+ },
55
+ {
56
+ "cell_type": "code",
57
+ "source": [
58
+ "data_path = \"/content/drive/MyDrive/Colab Notebooks/ML RESUME PROJECTS/image classiication/data\""
59
+ ],
60
+ "metadata": {
61
+ "id": "dDXJUfqX8u1f"
62
+ },
63
+ "execution_count": null,
64
+ "outputs": []
65
+ },
66
+ {
67
+ "cell_type": "code",
68
+ "source": [
69
+ "#verify the folders\n",
70
+ "for folder in os.listdir(data_path):\n",
71
+ " print(folder, len(os.listdir(os.path.join(data_path, folder))), \"images\")"
72
+ ],
73
+ "metadata": {
74
+ "colab": {
75
+ "base_uri": "https://localhost:8080/"
76
+ },
77
+ "id": "O53-h2jYt67_",
78
+ "outputId": "f811f07c-4c56-4239-d025-e8afe0cb05dd"
79
+ },
80
+ "execution_count": null,
81
+ "outputs": [
82
+ {
83
+ "output_type": "stream",
84
+ "name": "stdout",
85
+ "text": [
86
+ "rottenbanana 2226 images\n",
87
+ "rottenoranges 1601 images\n",
88
+ "rottenapples 2342 images\n",
89
+ "freshbanana 1581 images\n",
90
+ "freshoranges 1466 images\n",
91
+ "freshapples 1697 images\n"
92
+ ]
93
+ }
94
+ ]
95
+ },
96
+ {
97
+ "cell_type": "code",
98
+ "source": [
99
+ "folder_path = \"/content/drive/MyDrive/Colab Notebooks/ML RESUME PROJECTS/image classiication/data/rottenbanana\"\n",
100
+ "X_list = []\n",
101
+ "y_list = []\n",
102
+ "\n",
103
+ "for file in os.listdir(folder_path):\n",
104
+ " img_path = os.path.join(folder_path, file)\n",
105
+ " img = cv2.imread(img_path)\n",
106
+ " img = cv2.resize(img, (64,64))\n",
107
+ " img_flat = img.flatten().astype(np.uint8)\n",
108
+ " X_list.append(img_flat)\n",
109
+ " y_list.append('rottenbanana')\n",
110
+ "\n",
111
+ "df_rottenbanana = pd.DataFrame(X_list)\n",
112
+ "df_rottenbanana['target'] = y_list\n",
113
+ "\n",
114
+ "print(\"rottenbanana shape:\", df_rottenbanana.shape)"
115
+ ],
116
+ "metadata": {
117
+ "colab": {
118
+ "base_uri": "https://localhost:8080/"
119
+ },
120
+ "id": "wXi7RhlVufIi",
121
+ "outputId": "5bafc4d8-e709-4e9a-dca8-35ad753cbc2b"
122
+ },
123
+ "execution_count": null,
124
+ "outputs": [
125
+ {
126
+ "output_type": "stream",
127
+ "name": "stdout",
128
+ "text": [
129
+ "rottenbanana shape: (2226, 12289)\n"
130
+ ]
131
+ }
132
+ ]
133
+ },
134
+ {
135
+ "cell_type": "code",
136
+ "source": [
137
+ "folder_path = \"/content/drive/MyDrive/Colab Notebooks/ML RESUME PROJECTS/image classiication/data/rottenoranges\"\n",
138
+ "X_list = []\n",
139
+ "y_list = []\n",
140
+ "\n",
141
+ "for file in os.listdir(folder_path):\n",
142
+ " img_path = os.path.join(folder_path, file)\n",
143
+ " img = cv2.imread(img_path)\n",
144
+ " img = cv2.resize(img, (64,64))\n",
145
+ " img_flat = img.flatten().astype(np.uint8)\n",
146
+ " X_list.append(img_flat)\n",
147
+ " y_list.append('rottenoranges')\n",
148
+ "\n",
149
+ "df_rottenoranges = pd.DataFrame(X_list)\n",
150
+ "df_rottenoranges['target'] = y_list\n",
151
+ "\n",
152
+ "print(\"rottenoranges shape:\", df_rottenoranges.shape)\n"
153
+ ],
154
+ "metadata": {
155
+ "colab": {
156
+ "base_uri": "https://localhost:8080/"
157
+ },
158
+ "id": "5AxSMVuTy5On",
159
+ "outputId": "1ed146c6-2bb7-40ef-f391-f7c4e70ac62f"
160
+ },
161
+ "execution_count": null,
162
+ "outputs": [
163
+ {
164
+ "output_type": "stream",
165
+ "name": "stdout",
166
+ "text": [
167
+ "rottenoranges shape: (1601, 12289)\n"
168
+ ]
169
+ }
170
+ ]
171
+ },
172
+ {
173
+ "cell_type": "code",
174
+ "source": [
175
+ "folder_path = \"/content/drive/MyDrive/Colab Notebooks/ML RESUME PROJECTS/image classiication/data/rottenapples\"\n",
176
+ "X_list = []\n",
177
+ "y_list = []\n",
178
+ "\n",
179
+ "for file in os.listdir(folder_path):\n",
180
+ " img_path = os.path.join(folder_path, file)\n",
181
+ " img = cv2.imread(img_path)\n",
182
+ " img = cv2.resize(img, (64,64))\n",
183
+ " img_flat = img.flatten().astype(np.uint8)\n",
184
+ " X_list.append(img_flat)\n",
185
+ " y_list.append('rottenapples')\n",
186
+ "\n",
187
+ "df_rottenapples = pd.DataFrame(X_list)\n",
188
+ "df_rottenapples['target'] = y_list\n",
189
+ "\n",
190
+ "print(\"rottenapples shape:\", df_rottenapples.shape)\n"
191
+ ],
192
+ "metadata": {
193
+ "colab": {
194
+ "base_uri": "https://localhost:8080/"
195
+ },
196
+ "id": "xkumK75uzA5i",
197
+ "outputId": "8e2e3b2b-e1bb-404a-a3fb-b9c379031195"
198
+ },
199
+ "execution_count": null,
200
+ "outputs": [
201
+ {
202
+ "output_type": "stream",
203
+ "name": "stdout",
204
+ "text": [
205
+ "rottenapples shape: (2342, 12289)\n"
206
+ ]
207
+ }
208
+ ]
209
+ },
210
+ {
211
+ "cell_type": "code",
212
+ "source": [
213
+ "folder_path = \"/content/drive/MyDrive/Colab Notebooks/ML RESUME PROJECTS/image classiication/data/freshbanana\"\n",
214
+ "X_list = []\n",
215
+ "y_list = []\n",
216
+ "\n",
217
+ "for file in os.listdir(folder_path):\n",
218
+ " img_path = os.path.join(folder_path, file)\n",
219
+ " img = cv2.imread(img_path)\n",
220
+ " img = cv2.resize(img, (64,64))\n",
221
+ " img_flat = img.flatten().astype(np.uint8)\n",
222
+ " X_list.append(img_flat)\n",
223
+ " y_list.append('freshbanana')\n",
224
+ "\n",
225
+ "df_freshbanana = pd.DataFrame(X_list)\n",
226
+ "df_freshbanana['target'] = y_list\n",
227
+ "\n",
228
+ "print(\"freshbanana shape:\", df_freshbanana.shape)\n"
229
+ ],
230
+ "metadata": {
231
+ "colab": {
232
+ "base_uri": "https://localhost:8080/"
233
+ },
234
+ "id": "sebO1Zl5zUX6",
235
+ "outputId": "3b455d4c-5d9f-41e2-906d-3b5c71015d93"
236
+ },
237
+ "execution_count": null,
238
+ "outputs": [
239
+ {
240
+ "output_type": "stream",
241
+ "name": "stdout",
242
+ "text": [
243
+ "freshbanana shape: (1581, 12289)\n"
244
+ ]
245
+ }
246
+ ]
247
+ },
248
+ {
249
+ "cell_type": "code",
250
+ "source": [
251
+ "folder_path = \"/content/drive/MyDrive/Colab Notebooks/ML RESUME PROJECTS/image classiication/data/freshoranges\"\n",
252
+ "X_list = []\n",
253
+ "y_list = []\n",
254
+ "\n",
255
+ "for file in os.listdir(folder_path):\n",
256
+ " img_path = os.path.join(folder_path, file)\n",
257
+ " img = cv2.imread(img_path)\n",
258
+ " img = cv2.resize(img, (64,64))\n",
259
+ " img_flat = img.flatten().astype(np.uint8)\n",
260
+ " X_list.append(img_flat)\n",
261
+ " y_list.append('freshoranges')\n",
262
+ "\n",
263
+ "df_freshoranges = pd.DataFrame(X_list)\n",
264
+ "df_freshoranges['target'] = y_list\n",
265
+ "\n",
266
+ "print(\"freshoranges shape:\", df_freshoranges.shape)\n"
267
+ ],
268
+ "metadata": {
269
+ "colab": {
270
+ "base_uri": "https://localhost:8080/"
271
+ },
272
+ "id": "wLloeGpZz-fk",
273
+ "outputId": "d8e6f564-a2b8-4768-b447-ec40bb9a5af7"
274
+ },
275
+ "execution_count": null,
276
+ "outputs": [
277
+ {
278
+ "output_type": "stream",
279
+ "name": "stdout",
280
+ "text": [
281
+ "freshoranges shape: (1466, 12289)\n"
282
+ ]
283
+ }
284
+ ]
285
+ },
286
+ {
287
+ "cell_type": "code",
288
+ "source": [
289
+ "folder_path = \"/content/drive/MyDrive/Colab Notebooks/ML RESUME PROJECTS/image classiication/data/freshapples\"\n",
290
+ "X_list = []\n",
291
+ "y_list = []\n",
292
+ "\n",
293
+ "for file in os.listdir(folder_path):\n",
294
+ " img_path = os.path.join(folder_path, file)\n",
295
+ " img = cv2.imread(img_path)\n",
296
+ " img = cv2.resize(img, (64,64))\n",
297
+ " img_flat = img.flatten().astype(np.uint8)\n",
298
+ " X_list.append(img_flat)\n",
299
+ " y_list.append('freshapples')\n",
300
+ "\n",
301
+ "df_freshapples = pd.DataFrame(X_list)\n",
302
+ "df_freshapples['target'] = y_list\n",
303
+ "\n",
304
+ "print(\"freshapples shape:\", df_freshapples.shape)\n"
305
+ ],
306
+ "metadata": {
307
+ "colab": {
308
+ "base_uri": "https://localhost:8080/"
309
+ },
310
+ "id": "2npMz_sO0Er6",
311
+ "outputId": "0d7cbb85-64a9-4c53-ff52-5b8f55a1bb24"
312
+ },
313
+ "execution_count": null,
314
+ "outputs": [
315
+ {
316
+ "output_type": "stream",
317
+ "name": "stdout",
318
+ "text": [
319
+ "freshapples shape: (1697, 12289)\n"
320
+ ]
321
+ }
322
+ ]
323
+ },
324
+ {
325
+ "cell_type": "code",
326
+ "source": [
327
+ "df_all = pd.concat([\n",
328
+ " df_rottenbanana,\n",
329
+ " df_rottenoranges,\n",
330
+ " df_rottenapples,\n",
331
+ " df_freshbanana,\n",
332
+ " df_freshoranges,\n",
333
+ " df_freshapples\n",
334
+ "], ignore_index=True)\n",
335
+ "\n",
336
+ "print(\"Merged DataFrame shape:\", df_all.shape)\n",
337
+ "print(df_all['target'].value_counts())"
338
+ ],
339
+ "metadata": {
340
+ "colab": {
341
+ "base_uri": "https://localhost:8080/"
342
+ },
343
+ "id": "bosmiLIr0Wd7",
344
+ "outputId": "92d95ed4-e752-41ab-fad6-37a83c6fbee3"
345
+ },
346
+ "execution_count": null,
347
+ "outputs": [
348
+ {
349
+ "output_type": "stream",
350
+ "name": "stdout",
351
+ "text": [
352
+ "Merged DataFrame shape: (10913, 12289)\n",
353
+ "target\n",
354
+ "rottenapples 2342\n",
355
+ "rottenbanana 2226\n",
356
+ "freshapples 1697\n",
357
+ "rottenoranges 1601\n",
358
+ "freshbanana 1581\n",
359
+ "freshoranges 1466\n",
360
+ "Name: count, dtype: int64\n"
361
+ ]
362
+ }
363
+ ]
364
+ },
365
+ {
366
+ "cell_type": "code",
367
+ "source": [
368
+ "# Save to CSV\n",
369
+ "df_all.to_csv(\"fruit_dataset.csv\", index=False)\n",
370
+ "print(\"CSV saved as:\", \"fruit_dataset.csv\")"
371
+ ],
372
+ "metadata": {
373
+ "colab": {
374
+ "base_uri": "https://localhost:8080/"
375
+ },
376
+ "id": "Hqs_-9A6BkpV",
377
+ "outputId": "0418d9e5-dbf6-40b3-9963-60e1c2adb0a9"
378
+ },
379
+ "execution_count": null,
380
+ "outputs": [
381
+ {
382
+ "output_type": "stream",
383
+ "name": "stdout",
384
+ "text": [
385
+ "CSV saved as: fruit_dataset.csv\n"
386
+ ]
387
+ }
388
+ ]
389
+ },
390
+ {
391
+ "cell_type": "markdown",
392
+ "source": [
393
+ "loading dataset"
394
+ ],
395
+ "metadata": {
396
+ "id": "dL8zxlyZq0hv"
397
+ }
398
+ },
399
+ {
400
+ "cell_type": "code",
401
+ "source": [
402
+ "import pandas as pd\n",
403
+ "import numpy as np"
404
+ ],
405
+ "metadata": {
406
+ "id": "RMW9VmBqq0Sv"
407
+ },
408
+ "execution_count": null,
409
+ "outputs": []
410
+ },
411
+ {
412
+ "cell_type": "code",
413
+ "source": [
414
+ "df = pd.read_csv('/content/fruit_dataset.csv')"
415
+ ],
416
+ "metadata": {
417
+ "id": "m4vL0JnbFsQL"
418
+ },
419
+ "execution_count": null,
420
+ "outputs": []
421
+ },
422
+ {
423
+ "cell_type": "code",
424
+ "source": [
425
+ "df.head()"
426
+ ],
427
+ "metadata": {
428
+ "id": "cVjG80lnDy4O",
429
+ "colab": {
430
+ "base_uri": "https://localhost:8080/",
431
+ "height": 255
432
+ },
433
+ "outputId": "a3bbf90f-9487-4dee-91b3-03f215540aab"
434
+ },
435
+ "execution_count": null,
436
+ "outputs": [
437
+ {
438
+ "output_type": "execute_result",
439
+ "data": {
440
+ "text/plain": [
441
+ " 0 1 2 3 4 5 6 7 8 9 ... 12279 12280 12281 \\\n",
442
+ "0 0 0 0 0 0 0 0 0 0 0 ... 0 0 0 \n",
443
+ "1 255 255 255 255 255 255 254 254 254 254 ... 254 254 254 \n",
444
+ "2 0 0 0 0 0 0 0 0 0 0 ... 0 0 0 \n",
445
+ "3 0 0 0 0 0 0 0 0 0 0 ... 0 0 0 \n",
446
+ "4 0 0 0 0 0 0 0 0 0 0 ... 0 0 0 \n",
447
+ "\n",
448
+ " 12282 12283 12284 12285 12286 12287 target \n",
449
+ "0 0 0 0 0 0 0 rottenbanana \n",
450
+ "1 244 244 244 255 255 255 rottenbanana \n",
451
+ "2 0 0 0 0 0 0 rottenbanana \n",
452
+ "3 0 0 0 0 0 0 rottenbanana \n",
453
+ "4 0 0 0 0 0 0 rottenbanana \n",
454
+ "\n",
455
+ "[5 rows x 12289 columns]"
456
+ ],
457
+ "text/html": [
458
+ "\n",
459
+ " <div id=\"df-7f735763-7b2d-45b8-b187-b8390373cc58\" class=\"colab-df-container\">\n",
460
+ " <div>\n",
461
+ "<style scoped>\n",
462
+ " .dataframe tbody tr th:only-of-type {\n",
463
+ " vertical-align: middle;\n",
464
+ " }\n",
465
+ "\n",
466
+ " .dataframe tbody tr th {\n",
467
+ " vertical-align: top;\n",
468
+ " }\n",
469
+ "\n",
470
+ " .dataframe thead th {\n",
471
+ " text-align: right;\n",
472
+ " }\n",
473
+ "</style>\n",
474
+ "<table border=\"1\" class=\"dataframe\">\n",
475
+ " <thead>\n",
476
+ " <tr style=\"text-align: right;\">\n",
477
+ " <th></th>\n",
478
+ " <th>0</th>\n",
479
+ " <th>1</th>\n",
480
+ " <th>2</th>\n",
481
+ " <th>3</th>\n",
482
+ " <th>4</th>\n",
483
+ " <th>5</th>\n",
484
+ " <th>6</th>\n",
485
+ " <th>7</th>\n",
486
+ " <th>8</th>\n",
487
+ " <th>9</th>\n",
488
+ " <th>...</th>\n",
489
+ " <th>12279</th>\n",
490
+ " <th>12280</th>\n",
491
+ " <th>12281</th>\n",
492
+ " <th>12282</th>\n",
493
+ " <th>12283</th>\n",
494
+ " <th>12284</th>\n",
495
+ " <th>12285</th>\n",
496
+ " <th>12286</th>\n",
497
+ " <th>12287</th>\n",
498
+ " <th>target</th>\n",
499
+ " </tr>\n",
500
+ " </thead>\n",
501
+ " <tbody>\n",
502
+ " <tr>\n",
503
+ " <th>0</th>\n",
504
+ " <td>0</td>\n",
505
+ " <td>0</td>\n",
506
+ " <td>0</td>\n",
507
+ " <td>0</td>\n",
508
+ " <td>0</td>\n",
509
+ " <td>0</td>\n",
510
+ " <td>0</td>\n",
511
+ " <td>0</td>\n",
512
+ " <td>0</td>\n",
513
+ " <td>0</td>\n",
514
+ " <td>...</td>\n",
515
+ " <td>0</td>\n",
516
+ " <td>0</td>\n",
517
+ " <td>0</td>\n",
518
+ " <td>0</td>\n",
519
+ " <td>0</td>\n",
520
+ " <td>0</td>\n",
521
+ " <td>0</td>\n",
522
+ " <td>0</td>\n",
523
+ " <td>0</td>\n",
524
+ " <td>rottenbanana</td>\n",
525
+ " </tr>\n",
526
+ " <tr>\n",
527
+ " <th>1</th>\n",
528
+ " <td>255</td>\n",
529
+ " <td>255</td>\n",
530
+ " <td>255</td>\n",
531
+ " <td>255</td>\n",
532
+ " <td>255</td>\n",
533
+ " <td>255</td>\n",
534
+ " <td>254</td>\n",
535
+ " <td>254</td>\n",
536
+ " <td>254</td>\n",
537
+ " <td>254</td>\n",
538
+ " <td>...</td>\n",
539
+ " <td>254</td>\n",
540
+ " <td>254</td>\n",
541
+ " <td>254</td>\n",
542
+ " <td>244</td>\n",
543
+ " <td>244</td>\n",
544
+ " <td>244</td>\n",
545
+ " <td>255</td>\n",
546
+ " <td>255</td>\n",
547
+ " <td>255</td>\n",
548
+ " <td>rottenbanana</td>\n",
549
+ " </tr>\n",
550
+ " <tr>\n",
551
+ " <th>2</th>\n",
552
+ " <td>0</td>\n",
553
+ " <td>0</td>\n",
554
+ " <td>0</td>\n",
555
+ " <td>0</td>\n",
556
+ " <td>0</td>\n",
557
+ " <td>0</td>\n",
558
+ " <td>0</td>\n",
559
+ " <td>0</td>\n",
560
+ " <td>0</td>\n",
561
+ " <td>0</td>\n",
562
+ " <td>...</td>\n",
563
+ " <td>0</td>\n",
564
+ " <td>0</td>\n",
565
+ " <td>0</td>\n",
566
+ " <td>0</td>\n",
567
+ " <td>0</td>\n",
568
+ " <td>0</td>\n",
569
+ " <td>0</td>\n",
570
+ " <td>0</td>\n",
571
+ " <td>0</td>\n",
572
+ " <td>rottenbanana</td>\n",
573
+ " </tr>\n",
574
+ " <tr>\n",
575
+ " <th>3</th>\n",
576
+ " <td>0</td>\n",
577
+ " <td>0</td>\n",
578
+ " <td>0</td>\n",
579
+ " <td>0</td>\n",
580
+ " <td>0</td>\n",
581
+ " <td>0</td>\n",
582
+ " <td>0</td>\n",
583
+ " <td>0</td>\n",
584
+ " <td>0</td>\n",
585
+ " <td>0</td>\n",
586
+ " <td>...</td>\n",
587
+ " <td>0</td>\n",
588
+ " <td>0</td>\n",
589
+ " <td>0</td>\n",
590
+ " <td>0</td>\n",
591
+ " <td>0</td>\n",
592
+ " <td>0</td>\n",
593
+ " <td>0</td>\n",
594
+ " <td>0</td>\n",
595
+ " <td>0</td>\n",
596
+ " <td>rottenbanana</td>\n",
597
+ " </tr>\n",
598
+ " <tr>\n",
599
+ " <th>4</th>\n",
600
+ " <td>0</td>\n",
601
+ " <td>0</td>\n",
602
+ " <td>0</td>\n",
603
+ " <td>0</td>\n",
604
+ " <td>0</td>\n",
605
+ " <td>0</td>\n",
606
+ " <td>0</td>\n",
607
+ " <td>0</td>\n",
608
+ " <td>0</td>\n",
609
+ " <td>0</td>\n",
610
+ " <td>...</td>\n",
611
+ " <td>0</td>\n",
612
+ " <td>0</td>\n",
613
+ " <td>0</td>\n",
614
+ " <td>0</td>\n",
615
+ " <td>0</td>\n",
616
+ " <td>0</td>\n",
617
+ " <td>0</td>\n",
618
+ " <td>0</td>\n",
619
+ " <td>0</td>\n",
620
+ " <td>rottenbanana</td>\n",
621
+ " </tr>\n",
622
+ " </tbody>\n",
623
+ "</table>\n",
624
+ "<p>5 rows Γ— 12289 columns</p>\n",
625
+ "</div>\n",
626
+ " <div class=\"colab-df-buttons\">\n",
627
+ "\n",
628
+ " <div class=\"colab-df-container\">\n",
629
+ " <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-7f735763-7b2d-45b8-b187-b8390373cc58')\"\n",
630
+ " title=\"Convert this dataframe to an interactive table.\"\n",
631
+ " style=\"display:none;\">\n",
632
+ "\n",
633
+ " <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\" viewBox=\"0 -960 960 960\">\n",
634
+ " <path d=\"M120-120v-720h720v720H120Zm60-500h600v-160H180v160Zm220 220h160v-160H400v160Zm0 220h160v-160H400v160ZM180-400h160v-160H180v160Zm440 0h160v-160H620v160ZM180-180h160v-160H180v160Zm440 0h160v-160H620v160Z\"/>\n",
635
+ " </svg>\n",
636
+ " </button>\n",
637
+ "\n",
638
+ " <style>\n",
639
+ " .colab-df-container {\n",
640
+ " display:flex;\n",
641
+ " gap: 12px;\n",
642
+ " }\n",
643
+ "\n",
644
+ " .colab-df-convert {\n",
645
+ " background-color: #E8F0FE;\n",
646
+ " border: none;\n",
647
+ " border-radius: 50%;\n",
648
+ " cursor: pointer;\n",
649
+ " display: none;\n",
650
+ " fill: #1967D2;\n",
651
+ " height: 32px;\n",
652
+ " padding: 0 0 0 0;\n",
653
+ " width: 32px;\n",
654
+ " }\n",
655
+ "\n",
656
+ " .colab-df-convert:hover {\n",
657
+ " background-color: #E2EBFA;\n",
658
+ " box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
659
+ " fill: #174EA6;\n",
660
+ " }\n",
661
+ "\n",
662
+ " .colab-df-buttons div {\n",
663
+ " margin-bottom: 4px;\n",
664
+ " }\n",
665
+ "\n",
666
+ " [theme=dark] .colab-df-convert {\n",
667
+ " background-color: #3B4455;\n",
668
+ " fill: #D2E3FC;\n",
669
+ " }\n",
670
+ "\n",
671
+ " [theme=dark] .colab-df-convert:hover {\n",
672
+ " background-color: #434B5C;\n",
673
+ " box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n",
674
+ " filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n",
675
+ " fill: #FFFFFF;\n",
676
+ " }\n",
677
+ " </style>\n",
678
+ "\n",
679
+ " <script>\n",
680
+ " const buttonEl =\n",
681
+ " document.querySelector('#df-7f735763-7b2d-45b8-b187-b8390373cc58 button.colab-df-convert');\n",
682
+ " buttonEl.style.display =\n",
683
+ " google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
684
+ "\n",
685
+ " async function convertToInteractive(key) {\n",
686
+ " const element = document.querySelector('#df-7f735763-7b2d-45b8-b187-b8390373cc58');\n",
687
+ " const dataTable =\n",
688
+ " await google.colab.kernel.invokeFunction('convertToInteractive',\n",
689
+ " [key], {});\n",
690
+ " if (!dataTable) return;\n",
691
+ "\n",
692
+ " const docLinkHtml = 'Like what you see? Visit the ' +\n",
693
+ " '<a target=\"_blank\" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'\n",
694
+ " + ' to learn more about interactive tables.';\n",
695
+ " element.innerHTML = '';\n",
696
+ " dataTable['output_type'] = 'display_data';\n",
697
+ " await google.colab.output.renderOutput(dataTable, element);\n",
698
+ " const docLink = document.createElement('div');\n",
699
+ " docLink.innerHTML = docLinkHtml;\n",
700
+ " element.appendChild(docLink);\n",
701
+ " }\n",
702
+ " </script>\n",
703
+ " </div>\n",
704
+ "\n",
705
+ "\n",
706
+ " <div id=\"df-4e00a366-d4f3-44b8-8fa7-389ea116336d\">\n",
707
+ " <button class=\"colab-df-quickchart\" onclick=\"quickchart('df-4e00a366-d4f3-44b8-8fa7-389ea116336d')\"\n",
708
+ " title=\"Suggest charts\"\n",
709
+ " style=\"display:none;\">\n",
710
+ "\n",
711
+ "<svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\"viewBox=\"0 0 24 24\"\n",
712
+ " width=\"24px\">\n",
713
+ " <g>\n",
714
+ " <path d=\"M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zM9 17H7v-7h2v7zm4 0h-2V7h2v10zm4 0h-2v-4h2v4z\"/>\n",
715
+ " </g>\n",
716
+ "</svg>\n",
717
+ " </button>\n",
718
+ "\n",
719
+ "<style>\n",
720
+ " .colab-df-quickchart {\n",
721
+ " --bg-color: #E8F0FE;\n",
722
+ " --fill-color: #1967D2;\n",
723
+ " --hover-bg-color: #E2EBFA;\n",
724
+ " --hover-fill-color: #174EA6;\n",
725
+ " --disabled-fill-color: #AAA;\n",
726
+ " --disabled-bg-color: #DDD;\n",
727
+ " }\n",
728
+ "\n",
729
+ " [theme=dark] .colab-df-quickchart {\n",
730
+ " --bg-color: #3B4455;\n",
731
+ " --fill-color: #D2E3FC;\n",
732
+ " --hover-bg-color: #434B5C;\n",
733
+ " --hover-fill-color: #FFFFFF;\n",
734
+ " --disabled-bg-color: #3B4455;\n",
735
+ " --disabled-fill-color: #666;\n",
736
+ " }\n",
737
+ "\n",
738
+ " .colab-df-quickchart {\n",
739
+ " background-color: var(--bg-color);\n",
740
+ " border: none;\n",
741
+ " border-radius: 50%;\n",
742
+ " cursor: pointer;\n",
743
+ " display: none;\n",
744
+ " fill: var(--fill-color);\n",
745
+ " height: 32px;\n",
746
+ " padding: 0;\n",
747
+ " width: 32px;\n",
748
+ " }\n",
749
+ "\n",
750
+ " .colab-df-quickchart:hover {\n",
751
+ " background-color: var(--hover-bg-color);\n",
752
+ " box-shadow: 0 1px 2px rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
753
+ " fill: var(--button-hover-fill-color);\n",
754
+ " }\n",
755
+ "\n",
756
+ " .colab-df-quickchart-complete:disabled,\n",
757
+ " .colab-df-quickchart-complete:disabled:hover {\n",
758
+ " background-color: var(--disabled-bg-color);\n",
759
+ " fill: var(--disabled-fill-color);\n",
760
+ " box-shadow: none;\n",
761
+ " }\n",
762
+ "\n",
763
+ " .colab-df-spinner {\n",
764
+ " border: 2px solid var(--fill-color);\n",
765
+ " border-color: transparent;\n",
766
+ " border-bottom-color: var(--fill-color);\n",
767
+ " animation:\n",
768
+ " spin 1s steps(1) infinite;\n",
769
+ " }\n",
770
+ "\n",
771
+ " @keyframes spin {\n",
772
+ " 0% {\n",
773
+ " border-color: transparent;\n",
774
+ " border-bottom-color: var(--fill-color);\n",
775
+ " border-left-color: var(--fill-color);\n",
776
+ " }\n",
777
+ " 20% {\n",
778
+ " border-color: transparent;\n",
779
+ " border-left-color: var(--fill-color);\n",
780
+ " border-top-color: var(--fill-color);\n",
781
+ " }\n",
782
+ " 30% {\n",
783
+ " border-color: transparent;\n",
784
+ " border-left-color: var(--fill-color);\n",
785
+ " border-top-color: var(--fill-color);\n",
786
+ " border-right-color: var(--fill-color);\n",
787
+ " }\n",
788
+ " 40% {\n",
789
+ " border-color: transparent;\n",
790
+ " border-right-color: var(--fill-color);\n",
791
+ " border-top-color: var(--fill-color);\n",
792
+ " }\n",
793
+ " 60% {\n",
794
+ " border-color: transparent;\n",
795
+ " border-right-color: var(--fill-color);\n",
796
+ " }\n",
797
+ " 80% {\n",
798
+ " border-color: transparent;\n",
799
+ " border-right-color: var(--fill-color);\n",
800
+ " border-bottom-color: var(--fill-color);\n",
801
+ " }\n",
802
+ " 90% {\n",
803
+ " border-color: transparent;\n",
804
+ " border-bottom-color: var(--fill-color);\n",
805
+ " }\n",
806
+ " }\n",
807
+ "</style>\n",
808
+ "\n",
809
+ " <script>\n",
810
+ " async function quickchart(key) {\n",
811
+ " const quickchartButtonEl =\n",
812
+ " document.querySelector('#' + key + ' button');\n",
813
+ " quickchartButtonEl.disabled = true; // To prevent multiple clicks.\n",
814
+ " quickchartButtonEl.classList.add('colab-df-spinner');\n",
815
+ " try {\n",
816
+ " const charts = await google.colab.kernel.invokeFunction(\n",
817
+ " 'suggestCharts', [key], {});\n",
818
+ " } catch (error) {\n",
819
+ " console.error('Error during call to suggestCharts:', error);\n",
820
+ " }\n",
821
+ " quickchartButtonEl.classList.remove('colab-df-spinner');\n",
822
+ " quickchartButtonEl.classList.add('colab-df-quickchart-complete');\n",
823
+ " }\n",
824
+ " (() => {\n",
825
+ " let quickchartButtonEl =\n",
826
+ " document.querySelector('#df-4e00a366-d4f3-44b8-8fa7-389ea116336d button');\n",
827
+ " quickchartButtonEl.style.display =\n",
828
+ " google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
829
+ " })();\n",
830
+ " </script>\n",
831
+ " </div>\n",
832
+ "\n",
833
+ " </div>\n",
834
+ " </div>\n"
835
+ ],
836
+ "application/vnd.google.colaboratory.intrinsic+json": {
837
+ "type": "dataframe",
838
+ "variable_name": "df"
839
+ }
840
+ },
841
+ "metadata": {},
842
+ "execution_count": 16
843
+ }
844
+ ]
845
+ },
846
+ {
847
+ "cell_type": "code",
848
+ "source": [
849
+ "print(df['target'].value_counts())"
850
+ ],
851
+ "metadata": {
852
+ "colab": {
853
+ "base_uri": "https://localhost:8080/"
854
+ },
855
+ "id": "0fgwuVGcsIKa",
856
+ "outputId": "ddc13cf6-c30a-443e-d105-54d2c2e3886a"
857
+ },
858
+ "execution_count": null,
859
+ "outputs": [
860
+ {
861
+ "output_type": "stream",
862
+ "name": "stdout",
863
+ "text": [
864
+ "target\n",
865
+ "rottenapples 2342\n",
866
+ "rottenbanana 2226\n",
867
+ "freshapples 1697\n",
868
+ "rottenoranges 1601\n",
869
+ "freshbanana 1581\n",
870
+ "freshoranges 1466\n",
871
+ "Name: count, dtype: int64\n"
872
+ ]
873
+ }
874
+ ]
875
+ },
876
+ {
877
+ "cell_type": "code",
878
+ "source": [
879
+ "# Features\n",
880
+ "X = df.drop(\"target\", axis=1)\n",
881
+ "# Target\n",
882
+ "y = df[\"target\"]\n",
883
+ "print(X.shape)\n",
884
+ "print(y.shape)"
885
+ ],
886
+ "metadata": {
887
+ "colab": {
888
+ "base_uri": "https://localhost:8080/"
889
+ },
890
+ "id": "jmM8wZxtrFxz",
891
+ "outputId": "47dd5d41-7f3e-4fef-c164-66cb82abaefc"
892
+ },
893
+ "execution_count": null,
894
+ "outputs": [
895
+ {
896
+ "output_type": "stream",
897
+ "name": "stdout",
898
+ "text": [
899
+ "(10913, 12288)\n",
900
+ "(10913,)\n"
901
+ ]
902
+ }
903
+ ]
904
+ },
905
+ {
906
+ "cell_type": "markdown",
907
+ "source": [
908
+ "# **Encode target**"
909
+ ],
910
+ "metadata": {
911
+ "id": "ww0O5SqiraKP"
912
+ }
913
+ },
914
+ {
915
+ "cell_type": "code",
916
+ "source": [
917
+ "from sklearn.preprocessing import LabelEncoder\n",
918
+ "\n",
919
+ "# Create encoder\n",
920
+ "le = LabelEncoder()\n",
921
+ "\n",
922
+ "# Fit on y and transform\n",
923
+ "y_enc = le.fit_transform(y)\n",
924
+ "\n",
925
+ "# Check mapping\n",
926
+ "label_mapping = dict(zip(le.classes_, le.transform(le.classes_)))\n",
927
+ "print(\"Label mapping:\", label_mapping)\n",
928
+ "\n",
929
+ "print(\"Encoded y shape:\", y_enc.shape)\n",
930
+ "print(\"First 10 encoded labels:\", y_enc[:10])"
931
+ ],
932
+ "metadata": {
933
+ "colab": {
934
+ "base_uri": "https://localhost:8080/"
935
+ },
936
+ "id": "b1uiyJxWrUP5",
937
+ "outputId": "4c6e6529-e877-4057-a2a8-998c27db8275"
938
+ },
939
+ "execution_count": null,
940
+ "outputs": [
941
+ {
942
+ "output_type": "stream",
943
+ "name": "stdout",
944
+ "text": [
945
+ "Label mapping: {'freshapples': np.int64(0), 'freshbanana': np.int64(1), 'freshoranges': np.int64(2), 'rottenapples': np.int64(3), 'rottenbanana': np.int64(4), 'rottenoranges': np.int64(5)}\n",
946
+ "Encoded y shape: (10913,)\n",
947
+ "First 10 encoded labels: [4 4 4 4 4 4 4 4 4 4]\n"
948
+ ]
949
+ }
950
+ ]
951
+ },
952
+ {
953
+ "cell_type": "markdown",
954
+ "source": [
955
+ "# **Train-test split**"
956
+ ],
957
+ "metadata": {
958
+ "id": "jVlICnkKrfGT"
959
+ }
960
+ },
961
+ {
962
+ "cell_type": "code",
963
+ "source": [
964
+ "from sklearn.model_selection import train_test_split\n",
965
+ "\n",
966
+ "X_train, X_test, y_train, y_test = train_test_split(X, y_enc, test_size=0.2, random_state=42, stratify=y_enc)\n",
967
+ "print(X_train.shape)\n",
968
+ "print(X_test.shape)\n",
969
+ "print(y_train.shape)\n",
970
+ "print(y_test.shape)"
971
+ ],
972
+ "metadata": {
973
+ "colab": {
974
+ "base_uri": "https://localhost:8080/"
975
+ },
976
+ "id": "dN0vUxG8rdn4",
977
+ "outputId": "c3f04af5-493f-4724-87e3-3896c03351af"
978
+ },
979
+ "execution_count": null,
980
+ "outputs": [
981
+ {
982
+ "output_type": "stream",
983
+ "name": "stdout",
984
+ "text": [
985
+ "(8730, 12288)\n",
986
+ "(2183, 12288)\n",
987
+ "(8730,)\n",
988
+ "(2183,)\n"
989
+ ]
990
+ }
991
+ ]
992
+ },
993
+ {
994
+ "cell_type": "markdown",
995
+ "source": [
996
+ "Scale the data and reduce dimensionality"
997
+ ],
998
+ "metadata": {
999
+ "id": "5mG4wNmF3mJv"
1000
+ }
1001
+ },
1002
+ {
1003
+ "cell_type": "code",
1004
+ "source": [
1005
+ "from sklearn.preprocessing import LabelEncoder, StandardScaler\n",
1006
+ "# Fit scaler on training data\n",
1007
+ "scaler = StandardScaler()\n",
1008
+ "X_train_scaled = scaler.fit_transform(X_train)\n",
1009
+ "X_test_scaled = scaler.transform(X_test)"
1010
+ ],
1011
+ "metadata": {
1012
+ "id": "JkMhNWcA3riD"
1013
+ },
1014
+ "execution_count": null,
1015
+ "outputs": []
1016
+ },
1017
+ {
1018
+ "cell_type": "code",
1019
+ "source": [
1020
+ "from sklearn.decomposition import PCA\n",
1021
+ "# Fit PCA on training data\n",
1022
+ "pca = PCA(n_components=0.95)\n",
1023
+ "X_train = pca.fit_transform(X_train_scaled)\n",
1024
+ "X_test = pca.transform(X_test_scaled)"
1025
+ ],
1026
+ "metadata": {
1027
+ "id": "uqETOPY_4Al0"
1028
+ },
1029
+ "execution_count": null,
1030
+ "outputs": []
1031
+ },
1032
+ {
1033
+ "cell_type": "code",
1034
+ "source": [
1035
+ "# Save train set\n",
1036
+ "df_train = pd.DataFrame(X_train)\n",
1037
+ "df_train[\"target\"] = y_train\n",
1038
+ "df_train.to_csv(\"X_train_pca.csv\", index=False)\n",
1039
+ "\n",
1040
+ "# Save test set\n",
1041
+ "df_test = pd.DataFrame(X_test)\n",
1042
+ "df_test[\"target\"] = y_test\n",
1043
+ "df_test.to_csv(\"X_test_pca.csv\", index=False)\n",
1044
+ "\n",
1045
+ "print(\"PCA-transformed train & test saved to CSV\")"
1046
+ ],
1047
+ "metadata": {
1048
+ "colab": {
1049
+ "base_uri": "https://localhost:8080/"
1050
+ },
1051
+ "id": "qH5JIDWy9SpQ",
1052
+ "outputId": "a37870ff-ce42-40e4-fc0c-8d749f49798e"
1053
+ },
1054
+ "execution_count": null,
1055
+ "outputs": [
1056
+ {
1057
+ "output_type": "stream",
1058
+ "name": "stdout",
1059
+ "text": [
1060
+ "PCA-transformed train & test saved to CSV\n"
1061
+ ]
1062
+ }
1063
+ ]
1064
+ },
1065
+ {
1066
+ "cell_type": "code",
1067
+ "source": [
1068
+ "# ML utilities\n",
1069
+ "from sklearn.pipeline import Pipeline\n",
1070
+ "from sklearn.metrics import accuracy_score, confusion_matrix, classification_report\n",
1071
+ "\n",
1072
+ "# Classifiers\n",
1073
+ "from sklearn.neighbors import KNeighborsClassifier\n",
1074
+ "from sklearn.naive_bayes import GaussianNB\n",
1075
+ "from sklearn.tree import DecisionTreeClassifier\n",
1076
+ "from sklearn.ensemble import RandomForestClassifier, AdaBoostClassifier, GradientBoostingClassifier\n",
1077
+ "from sklearn.linear_model import LogisticRegression\n",
1078
+ "from sklearn.svm import SVC\n",
1079
+ "import xgboost as xgb"
1080
+ ],
1081
+ "metadata": {
1082
+ "id": "OnCnSxe_rsIf"
1083
+ },
1084
+ "execution_count": null,
1085
+ "outputs": []
1086
+ },
1087
+ {
1088
+ "cell_type": "markdown",
1089
+ "source": [
1090
+ "KNN"
1091
+ ],
1092
+ "metadata": {
1093
+ "id": "NgBQ3EYj2ZNw"
1094
+ }
1095
+ },
1096
+ {
1097
+ "cell_type": "code",
1098
+ "source": [
1099
+ "knn = KNeighborsClassifier(n_neighbors=5)\n",
1100
+ "knn.fit(X_train, y_train)\n",
1101
+ "y_pred = knn.predict(X_test)\n",
1102
+ "\n",
1103
+ "print(\"=== KNN ===\")\n",
1104
+ "print(\"Accuracy:\", accuracy_score(y_test, y_pred))\n",
1105
+ "print(\"Confusion Matrix:\\n\", confusion_matrix(y_test, y_pred))\n",
1106
+ "print(\"Classification Report:\\n\", classification_report(y_test, y_pred))\n"
1107
+ ],
1108
+ "metadata": {
1109
+ "colab": {
1110
+ "base_uri": "https://localhost:8080/"
1111
+ },
1112
+ "id": "X4exR8G32Xb8",
1113
+ "outputId": "153022d2-bc2e-47d6-f7fb-143ddb25e8dc"
1114
+ },
1115
+ "execution_count": null,
1116
+ "outputs": [
1117
+ {
1118
+ "output_type": "stream",
1119
+ "name": "stdout",
1120
+ "text": [
1121
+ "=== KNN ===\n",
1122
+ "Accuracy: 0.7998167659184608\n",
1123
+ "Confusion Matrix:\n",
1124
+ " [[288 0 10 42 0 0]\n",
1125
+ " [ 5 288 2 12 3 6]\n",
1126
+ " [ 5 9 262 14 0 3]\n",
1127
+ " [ 36 1 51 374 0 7]\n",
1128
+ " [ 5 37 2 51 340 10]\n",
1129
+ " [ 10 13 34 69 0 194]]\n",
1130
+ "Classification Report:\n",
1131
+ " precision recall f1-score support\n",
1132
+ "\n",
1133
+ " 0 0.83 0.85 0.84 340\n",
1134
+ " 1 0.83 0.91 0.87 316\n",
1135
+ " 2 0.73 0.89 0.80 293\n",
1136
+ " 3 0.67 0.80 0.73 469\n",
1137
+ " 4 0.99 0.76 0.86 445\n",
1138
+ " 5 0.88 0.61 0.72 320\n",
1139
+ "\n",
1140
+ " accuracy 0.80 2183\n",
1141
+ " macro avg 0.82 0.80 0.80 2183\n",
1142
+ "weighted avg 0.82 0.80 0.80 2183\n",
1143
+ "\n"
1144
+ ]
1145
+ }
1146
+ ]
1147
+ },
1148
+ {
1149
+ "cell_type": "markdown",
1150
+ "source": [
1151
+ "Naive Bayes"
1152
+ ],
1153
+ "metadata": {
1154
+ "id": "eFmZGDQV8cna"
1155
+ }
1156
+ },
1157
+ {
1158
+ "cell_type": "code",
1159
+ "source": [
1160
+ "nb = GaussianNB()\n",
1161
+ "nb.fit(X_train, y_train)\n",
1162
+ "y_pred = nb.predict(X_test)\n",
1163
+ "\n",
1164
+ "print(\"=== Naive Bayes ===\")\n",
1165
+ "print(\"Accuracy:\", accuracy_score(y_test, y_pred))\n",
1166
+ "print(\"Confusion Matrix:\\n\", confusion_matrix(y_test, y_pred))\n",
1167
+ "print(\"Classification Report:\\n\", classification_report(y_test, y_pred))\n"
1168
+ ],
1169
+ "metadata": {
1170
+ "colab": {
1171
+ "base_uri": "https://localhost:8080/"
1172
+ },
1173
+ "id": "upieyjX62ck2",
1174
+ "outputId": "87170015-b901-42df-eda0-f468d8105021"
1175
+ },
1176
+ "execution_count": null,
1177
+ "outputs": [
1178
+ {
1179
+ "output_type": "stream",
1180
+ "name": "stdout",
1181
+ "text": [
1182
+ "=== Naive Bayes ===\n",
1183
+ "Accuracy: 0.5451213925790197\n",
1184
+ "Confusion Matrix:\n",
1185
+ " [[121 11 3 144 51 10]\n",
1186
+ " [ 5 143 7 27 49 85]\n",
1187
+ " [ 8 33 111 105 27 9]\n",
1188
+ " [ 62 21 16 336 14 20]\n",
1189
+ " [ 32 82 0 16 298 17]\n",
1190
+ " [ 16 24 16 60 23 181]]\n",
1191
+ "Classification Report:\n",
1192
+ " precision recall f1-score support\n",
1193
+ "\n",
1194
+ " 0 0.50 0.36 0.41 340\n",
1195
+ " 1 0.46 0.45 0.45 316\n",
1196
+ " 2 0.73 0.38 0.50 293\n",
1197
+ " 3 0.49 0.72 0.58 469\n",
1198
+ " 4 0.65 0.67 0.66 445\n",
1199
+ " 5 0.56 0.57 0.56 320\n",
1200
+ "\n",
1201
+ " accuracy 0.55 2183\n",
1202
+ " macro avg 0.56 0.52 0.53 2183\n",
1203
+ "weighted avg 0.56 0.55 0.54 2183\n",
1204
+ "\n"
1205
+ ]
1206
+ }
1207
+ ]
1208
+ },
1209
+ {
1210
+ "cell_type": "markdown",
1211
+ "source": [
1212
+ "Decision Tree"
1213
+ ],
1214
+ "metadata": {
1215
+ "id": "D9Pzm77r8kin"
1216
+ }
1217
+ },
1218
+ {
1219
+ "cell_type": "code",
1220
+ "source": [
1221
+ "dt = DecisionTreeClassifier(random_state=42)\n",
1222
+ "dt.fit(X_train, y_train)\n",
1223
+ "y_pred = dt.predict(X_test)\n",
1224
+ "\n",
1225
+ "print(\"=== Decision Tree ===\")\n",
1226
+ "print(\"Accuracy:\", accuracy_score(y_test, y_pred))\n",
1227
+ "print(\"Confusion Matrix:\\n\", confusion_matrix(y_test, y_pred))\n",
1228
+ "print(\"Classification Report:\\n\", classification_report(y_test, y_pred))\n"
1229
+ ],
1230
+ "metadata": {
1231
+ "colab": {
1232
+ "base_uri": "https://localhost:8080/"
1233
+ },
1234
+ "id": "AnVfOKH_8f9B",
1235
+ "outputId": "f3cfd65c-695d-4c23-b685-a704fc29e2f0"
1236
+ },
1237
+ "execution_count": null,
1238
+ "outputs": [
1239
+ {
1240
+ "output_type": "stream",
1241
+ "name": "stdout",
1242
+ "text": [
1243
+ "=== Decision Tree ===\n",
1244
+ "Accuracy: 0.6775080164910673\n",
1245
+ "Confusion Matrix:\n",
1246
+ " [[239 7 9 54 10 21]\n",
1247
+ " [ 6 255 16 11 14 14]\n",
1248
+ " [ 25 10 181 34 3 40]\n",
1249
+ " [ 58 10 43 279 21 58]\n",
1250
+ " [ 12 13 6 28 343 43]\n",
1251
+ " [ 22 13 20 60 23 182]]\n",
1252
+ "Classification Report:\n",
1253
+ " precision recall f1-score support\n",
1254
+ "\n",
1255
+ " 0 0.66 0.70 0.68 340\n",
1256
+ " 1 0.83 0.81 0.82 316\n",
1257
+ " 2 0.66 0.62 0.64 293\n",
1258
+ " 3 0.60 0.59 0.60 469\n",
1259
+ " 4 0.83 0.77 0.80 445\n",
1260
+ " 5 0.51 0.57 0.54 320\n",
1261
+ "\n",
1262
+ " accuracy 0.68 2183\n",
1263
+ " macro avg 0.68 0.68 0.68 2183\n",
1264
+ "weighted avg 0.68 0.68 0.68 2183\n",
1265
+ "\n"
1266
+ ]
1267
+ }
1268
+ ]
1269
+ },
1270
+ {
1271
+ "cell_type": "markdown",
1272
+ "source": [
1273
+ "Random Forest"
1274
+ ],
1275
+ "metadata": {
1276
+ "id": "3TGFtiKF8ywK"
1277
+ }
1278
+ },
1279
+ {
1280
+ "cell_type": "code",
1281
+ "source": [
1282
+ "rf = RandomForestClassifier(random_state=42)\n",
1283
+ "rf.fit(X_train, y_train)\n",
1284
+ "y_pred = rf.predict(X_test)\n",
1285
+ "\n",
1286
+ "print(\"=== Random Forest ===\")\n",
1287
+ "print(\"Accuracy:\", accuracy_score(y_test, y_pred))\n",
1288
+ "print(\"Confusion Matrix:\\n\", confusion_matrix(y_test, y_pred))\n",
1289
+ "print(\"Classification Report:\\n\", classification_report(y_test, y_pred))\n"
1290
+ ],
1291
+ "metadata": {
1292
+ "colab": {
1293
+ "base_uri": "https://localhost:8080/"
1294
+ },
1295
+ "id": "EazoOQyS8ySB",
1296
+ "outputId": "f72620ea-4ed4-424a-a857-d32332b61c85"
1297
+ },
1298
+ "execution_count": null,
1299
+ "outputs": [
1300
+ {
1301
+ "output_type": "stream",
1302
+ "name": "stdout",
1303
+ "text": [
1304
+ "=== Random Forest ===\n",
1305
+ "Accuracy: 0.8176820888685296\n",
1306
+ "Confusion Matrix:\n",
1307
+ " [[262 1 6 59 6 6]\n",
1308
+ " [ 5 271 2 11 20 7]\n",
1309
+ " [ 4 3 222 43 16 5]\n",
1310
+ " [ 22 1 16 407 15 8]\n",
1311
+ " [ 1 5 0 6 425 8]\n",
1312
+ " [ 10 14 11 65 22 198]]\n",
1313
+ "Classification Report:\n",
1314
+ " precision recall f1-score support\n",
1315
+ "\n",
1316
+ " 0 0.86 0.77 0.81 340\n",
1317
+ " 1 0.92 0.86 0.89 316\n",
1318
+ " 2 0.86 0.76 0.81 293\n",
1319
+ " 3 0.69 0.87 0.77 469\n",
1320
+ " 4 0.84 0.96 0.90 445\n",
1321
+ " 5 0.85 0.62 0.72 320\n",
1322
+ "\n",
1323
+ " accuracy 0.82 2183\n",
1324
+ " macro avg 0.84 0.80 0.81 2183\n",
1325
+ "weighted avg 0.83 0.82 0.82 2183\n",
1326
+ "\n"
1327
+ ]
1328
+ }
1329
+ ]
1330
+ },
1331
+ {
1332
+ "cell_type": "markdown",
1333
+ "source": [
1334
+ "AdaBoost"
1335
+ ],
1336
+ "metadata": {
1337
+ "id": "UYzYo4Kc9GaZ"
1338
+ }
1339
+ },
1340
+ {
1341
+ "cell_type": "code",
1342
+ "source": [
1343
+ "ada = AdaBoostClassifier(random_state=42)\n",
1344
+ "ada.fit(X_train, y_train)\n",
1345
+ "y_pred = ada.predict(X_test)\n",
1346
+ "\n",
1347
+ "print(\"=== AdaBoost ===\")\n",
1348
+ "print(\"Accuracy:\", accuracy_score(y_test, y_pred))\n",
1349
+ "print(\"Confusion Matrix:\\n\", confusion_matrix(y_test, y_pred))\n",
1350
+ "print(\"Classification Report:\\n\", classification_report(y_test, y_pred))\n"
1351
+ ],
1352
+ "metadata": {
1353
+ "colab": {
1354
+ "base_uri": "https://localhost:8080/"
1355
+ },
1356
+ "id": "6ECM3jrs8nYX",
1357
+ "outputId": "dd4cb104-6bd1-4d71-beea-c1b22d1c7ee4"
1358
+ },
1359
+ "execution_count": null,
1360
+ "outputs": [
1361
+ {
1362
+ "output_type": "stream",
1363
+ "name": "stdout",
1364
+ "text": [
1365
+ "=== AdaBoost ===\n",
1366
+ "Accuracy: 0.5794777828676134\n",
1367
+ "Confusion Matrix:\n",
1368
+ " [[ 88 11 15 194 13 19]\n",
1369
+ " [ 8 233 20 7 9 39]\n",
1370
+ " [ 9 4 165 93 0 22]\n",
1371
+ " [ 43 6 27 339 19 35]\n",
1372
+ " [ 22 24 2 39 327 31]\n",
1373
+ " [ 25 18 39 99 26 113]]\n",
1374
+ "Classification Report:\n",
1375
+ " precision recall f1-score support\n",
1376
+ "\n",
1377
+ " 0 0.45 0.26 0.33 340\n",
1378
+ " 1 0.79 0.74 0.76 316\n",
1379
+ " 2 0.62 0.56 0.59 293\n",
1380
+ " 3 0.44 0.72 0.55 469\n",
1381
+ " 4 0.83 0.73 0.78 445\n",
1382
+ " 5 0.44 0.35 0.39 320\n",
1383
+ "\n",
1384
+ " accuracy 0.58 2183\n",
1385
+ " macro avg 0.59 0.56 0.57 2183\n",
1386
+ "weighted avg 0.59 0.58 0.57 2183\n",
1387
+ "\n"
1388
+ ]
1389
+ }
1390
+ ]
1391
+ },
1392
+ {
1393
+ "cell_type": "markdown",
1394
+ "source": [
1395
+ "took a little more time"
1396
+ ],
1397
+ "metadata": {
1398
+ "id": "9RjtfuMG9Ybb"
1399
+ }
1400
+ },
1401
+ {
1402
+ "cell_type": "markdown",
1403
+ "source": [
1404
+ "Gradient Boosting"
1405
+ ],
1406
+ "metadata": {
1407
+ "id": "YVQ8uldm9dsA"
1408
+ }
1409
+ },
1410
+ {
1411
+ "cell_type": "code",
1412
+ "source": [
1413
+ "gb = GradientBoostingClassifier(random_state=42)\n",
1414
+ "gb.fit(X_train, y_train)\n",
1415
+ "y_pred = gb.predict(X_test)\n",
1416
+ "\n",
1417
+ "print(\"=== Gradient Boosting ===\")\n",
1418
+ "print(\"Accuracy:\", accuracy_score(y_test, y_pred))\n",
1419
+ "print(\"Confusion Matrix:\\n\", confusion_matrix(y_test, y_pred))\n",
1420
+ "print(\"Classification Report:\\n\", classification_report(y_test, y_pred))\n"
1421
+ ],
1422
+ "metadata": {
1423
+ "colab": {
1424
+ "base_uri": "https://localhost:8080/",
1425
+ "height": 391
1426
+ },
1427
+ "id": "0JEKc1pE9LtT",
1428
+ "outputId": "b1cd2022-c1fd-4dd1-8bc6-cffddee55110"
1429
+ },
1430
+ "execution_count": null,
1431
+ "outputs": [
1432
+ {
1433
+ "output_type": "error",
1434
+ "ename": "KeyboardInterrupt",
1435
+ "evalue": "",
1436
+ "traceback": [
1437
+ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
1438
+ "\u001b[0;31mKeyboardInterrupt\u001b[0m Traceback (most recent call last)",
1439
+ "\u001b[0;32m/tmp/ipython-input-707962318.py\u001b[0m in \u001b[0;36m<cell line: 0>\u001b[0;34m()\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0mgb\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mGradientBoostingClassifier\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mrandom_state\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m42\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m \u001b[0mgb\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mfit\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mX_train\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0my_train\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 3\u001b[0m \u001b[0my_pred\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mgb\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mpredict\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mX_test\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 5\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"=== Gradient Boosting ===\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
1440
+ "\u001b[0;32m/usr/local/lib/python3.12/dist-packages/sklearn/base.py\u001b[0m in \u001b[0;36mwrapper\u001b[0;34m(estimator, *args, **kwargs)\u001b[0m\n\u001b[1;32m 1387\u001b[0m )\n\u001b[1;32m 1388\u001b[0m ):\n\u001b[0;32m-> 1389\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mfit_method\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mestimator\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m*\u001b[0m\u001b[0margs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 1390\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1391\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mwrapper\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
1441
+ "\u001b[0;32m/usr/local/lib/python3.12/dist-packages/sklearn/ensemble/_gb.py\u001b[0m in \u001b[0;36mfit\u001b[0;34m(self, X, y, sample_weight, monitor)\u001b[0m\n\u001b[1;32m 785\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 786\u001b[0m \u001b[0;31m# fit the boosting stages\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 787\u001b[0;31m n_stages = self._fit_stages(\n\u001b[0m\u001b[1;32m 788\u001b[0m \u001b[0mX_train\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 789\u001b[0m \u001b[0my_train\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
1442
+ "\u001b[0;32m/usr/local/lib/python3.12/dist-packages/sklearn/ensemble/_gb.py\u001b[0m in \u001b[0;36m_fit_stages\u001b[0;34m(self, X, y, raw_predictions, sample_weight, random_state, X_val, y_val, sample_weight_val, begin_at_stage, monitor)\u001b[0m\n\u001b[1;32m 881\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 882\u001b[0m \u001b[0;31m# fit next stage of trees\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 883\u001b[0;31m raw_predictions = self._fit_stage(\n\u001b[0m\u001b[1;32m 884\u001b[0m \u001b[0mi\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 885\u001b[0m \u001b[0mX\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
1443
+ "\u001b[0;32m/usr/local/lib/python3.12/dist-packages/sklearn/ensemble/_gb.py\u001b[0m in \u001b[0;36m_fit_stage\u001b[0;34m(self, i, X, y, raw_predictions, sample_weight, sample_mask, random_state, X_csc, X_csr)\u001b[0m\n\u001b[1;32m 487\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 488\u001b[0m \u001b[0mX\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mX_csc\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mX_csc\u001b[0m \u001b[0;32mis\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0;32mNone\u001b[0m \u001b[0;32melse\u001b[0m \u001b[0mX\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 489\u001b[0;31m tree.fit(\n\u001b[0m\u001b[1;32m 490\u001b[0m \u001b[0mX\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mneg_g_view\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mk\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0msample_weight\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0msample_weight\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcheck_input\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mFalse\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 491\u001b[0m )\n",
1444
+ "\u001b[0;32m/usr/local/lib/python3.12/dist-packages/sklearn/base.py\u001b[0m in \u001b[0;36mwrapper\u001b[0;34m(estimator, *args, **kwargs)\u001b[0m\n\u001b[1;32m 1387\u001b[0m )\n\u001b[1;32m 1388\u001b[0m ):\n\u001b[0;32m-> 1389\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mfit_method\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mestimator\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m*\u001b[0m\u001b[0margs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 1390\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1391\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mwrapper\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
1445
+ "\u001b[0;32m/usr/local/lib/python3.12/dist-packages/sklearn/tree/_classes.py\u001b[0m in \u001b[0;36mfit\u001b[0;34m(self, X, y, sample_weight, check_input)\u001b[0m\n\u001b[1;32m 1402\u001b[0m \"\"\"\n\u001b[1;32m 1403\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1404\u001b[0;31m super()._fit(\n\u001b[0m\u001b[1;32m 1405\u001b[0m \u001b[0mX\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1406\u001b[0m \u001b[0my\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
1446
+ "\u001b[0;32m/usr/local/lib/python3.12/dist-packages/sklearn/tree/_classes.py\u001b[0m in \u001b[0;36m_fit\u001b[0;34m(self, X, y, sample_weight, check_input, missing_values_in_feature_mask)\u001b[0m\n\u001b[1;32m 470\u001b[0m )\n\u001b[1;32m 471\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 472\u001b[0;31m \u001b[0mbuilder\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mbuild\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtree_\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mX\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0my\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0msample_weight\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mmissing_values_in_feature_mask\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 473\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 474\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mn_outputs_\u001b[0m \u001b[0;34m==\u001b[0m \u001b[0;36m1\u001b[0m \u001b[0;32mand\u001b[0m \u001b[0mis_classifier\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
1447
+ "\u001b[0;31mKeyboardInterrupt\u001b[0m: "
1448
+ ]
1449
+ }
1450
+ ]
1451
+ },
1452
+ {
1453
+ "cell_type": "markdown",
1454
+ "source": [
1455
+ "took so much more time"
1456
+ ],
1457
+ "metadata": {
1458
+ "id": "-jU-m4XN9uyr"
1459
+ }
1460
+ },
1461
+ {
1462
+ "cell_type": "markdown",
1463
+ "source": [
1464
+ "XGBoost"
1465
+ ],
1466
+ "metadata": {
1467
+ "id": "DcCzq53-9nZP"
1468
+ }
1469
+ },
1470
+ {
1471
+ "cell_type": "code",
1472
+ "source": [
1473
+ "xgb_model = xgb.XGBClassifier(n_estimators=100, eval_metric='mlogloss', use_label_encoder=False, random_state=42)\n",
1474
+ "xgb_model.fit(X_train, y_train)\n",
1475
+ "y_pred = xgb_model.predict(X_test)\n",
1476
+ "\n",
1477
+ "print(\"=== XGBoost ===\")\n",
1478
+ "print(\"Accuracy:\", accuracy_score(y_test, y_pred))\n",
1479
+ "print(\"Confusion Matrix:\\n\", confusion_matrix(y_test, y_pred))\n",
1480
+ "print(\"Classification Report:\\n\", classification_report(y_test, y_pred))\n"
1481
+ ],
1482
+ "metadata": {
1483
+ "colab": {
1484
+ "base_uri": "https://localhost:8080/",
1485
+ "height": 480
1486
+ },
1487
+ "id": "FKIx7AtR9tE1",
1488
+ "outputId": "716685f3-5452-409b-fc32-5da59128621a"
1489
+ },
1490
+ "execution_count": null,
1491
+ "outputs": [
1492
+ {
1493
+ "output_type": "stream",
1494
+ "name": "stderr",
1495
+ "text": [
1496
+ "/usr/local/lib/python3.12/dist-packages/xgboost/training.py:183: UserWarning: [09:12:11] WARNING: /workspace/src/learner.cc:738: \n",
1497
+ "Parameters: { \"use_label_encoder\" } are not used.\n",
1498
+ "\n",
1499
+ " bst.update(dtrain, iteration=i, fobj=obj)\n"
1500
+ ]
1501
+ },
1502
+ {
1503
+ "output_type": "error",
1504
+ "ename": "KeyboardInterrupt",
1505
+ "evalue": "",
1506
+ "traceback": [
1507
+ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
1508
+ "\u001b[0;31mKeyboardInterrupt\u001b[0m Traceback (most recent call last)",
1509
+ "\u001b[0;32m/tmp/ipython-input-417072136.py\u001b[0m in \u001b[0;36m<cell line: 0>\u001b[0;34m()\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0mxgb_model\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mxgb\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mXGBClassifier\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mn_estimators\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m100\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0meval_metric\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m'mlogloss'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0muse_label_encoder\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mFalse\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mrandom_state\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m42\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m \u001b[0mxgb_model\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mfit\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mX_train\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0my_train\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 3\u001b[0m \u001b[0my_pred\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mxgb_model\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mpredict\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mX_test\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 5\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"=== XGBoost ===\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
1510
+ "\u001b[0;32m/usr/local/lib/python3.12/dist-packages/xgboost/core.py\u001b[0m in \u001b[0;36minner_f\u001b[0;34m(*args, **kwargs)\u001b[0m\n\u001b[1;32m 727\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mk\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0marg\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mzip\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0msig\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mparameters\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0margs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 728\u001b[0m \u001b[0mkwargs\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mk\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0marg\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 729\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mfunc\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 730\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 731\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0minner_f\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
1511
+ "\u001b[0;32m/usr/local/lib/python3.12/dist-packages/xgboost/sklearn.py\u001b[0m in \u001b[0;36mfit\u001b[0;34m(self, X, y, sample_weight, base_margin, eval_set, verbose, xgb_model, sample_weight_eval_set, base_margin_eval_set, feature_weights)\u001b[0m\n\u001b[1;32m 1681\u001b[0m )\n\u001b[1;32m 1682\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1683\u001b[0;31m self._Booster = train(\n\u001b[0m\u001b[1;32m 1684\u001b[0m \u001b[0mparams\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1685\u001b[0m \u001b[0mtrain_dmatrix\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
1512
+ "\u001b[0;32m/usr/local/lib/python3.12/dist-packages/xgboost/core.py\u001b[0m in \u001b[0;36minner_f\u001b[0;34m(*args, **kwargs)\u001b[0m\n\u001b[1;32m 727\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mk\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0marg\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mzip\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0msig\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mparameters\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0margs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 728\u001b[0m \u001b[0mkwargs\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mk\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0marg\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 729\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mfunc\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 730\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 731\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0minner_f\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
1513
+ "\u001b[0;32m/usr/local/lib/python3.12/dist-packages/xgboost/training.py\u001b[0m in \u001b[0;36mtrain\u001b[0;34m(params, dtrain, num_boost_round, evals, obj, maximize, early_stopping_rounds, evals_result, verbose_eval, xgb_model, callbacks, custom_metric)\u001b[0m\n\u001b[1;32m 181\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mcb_container\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mbefore_iteration\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mbst\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mi\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdtrain\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mevals\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 182\u001b[0m \u001b[0;32mbreak\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 183\u001b[0;31m \u001b[0mbst\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mupdate\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdtrain\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0miteration\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mi\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mfobj\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mobj\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 184\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mcb_container\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mafter_iteration\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mbst\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mi\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdtrain\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mevals\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 185\u001b[0m \u001b[0;32mbreak\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
1514
+ "\u001b[0;32m/usr/local/lib/python3.12/dist-packages/xgboost/core.py\u001b[0m in \u001b[0;36mupdate\u001b[0;34m(self, dtrain, iteration, fobj)\u001b[0m\n\u001b[1;32m 2245\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mfobj\u001b[0m \u001b[0;32mis\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 2246\u001b[0m _check_call(\n\u001b[0;32m-> 2247\u001b[0;31m _LIB.XGBoosterUpdateOneIter(\n\u001b[0m\u001b[1;32m 2248\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mhandle\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mctypes\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mc_int\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0miteration\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdtrain\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mhandle\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 2249\u001b[0m )\n",
1515
+ "\u001b[0;31mKeyboardInterrupt\u001b[0m: "
1516
+ ]
1517
+ }
1518
+ ]
1519
+ },
1520
+ {
1521
+ "cell_type": "markdown",
1522
+ "source": [
1523
+ "Logistic Regression"
1524
+ ],
1525
+ "metadata": {
1526
+ "id": "cVF6t_td9oZ0"
1527
+ }
1528
+ },
1529
+ {
1530
+ "cell_type": "code",
1531
+ "source": [
1532
+ "lr = LogisticRegression(max_iter=1000, random_state=42)\n",
1533
+ "lr.fit(X_train, y_train)\n",
1534
+ "y_pred = lr.predict(X_test)\n",
1535
+ "\n",
1536
+ "print(\"=== Logistic Regression ===\")\n",
1537
+ "print(\"Accuracy:\", accuracy_score(y_test, y_pred))\n",
1538
+ "print(\"Confusion Matrix:\\n\", confusion_matrix(y_test, y_pred))\n",
1539
+ "print(\"Classification Report:\\n\", classification_report(y_test, y_pred))\n"
1540
+ ],
1541
+ "metadata": {
1542
+ "colab": {
1543
+ "base_uri": "https://localhost:8080/"
1544
+ },
1545
+ "id": "3Hyrqs5V9trq",
1546
+ "outputId": "b11970af-c5a8-4b1c-f2d8-949add167423"
1547
+ },
1548
+ "execution_count": null,
1549
+ "outputs": [
1550
+ {
1551
+ "output_type": "stream",
1552
+ "name": "stdout",
1553
+ "text": [
1554
+ "=== Logistic Regression ===\n",
1555
+ "Accuracy: 0.7480531378836464\n",
1556
+ "Confusion Matrix:\n",
1557
+ " [[227 9 6 67 2 29]\n",
1558
+ " [ 7 283 3 3 7 13]\n",
1559
+ " [ 13 2 238 22 1 17]\n",
1560
+ " [ 68 3 32 320 12 34]\n",
1561
+ " [ 13 11 1 14 374 32]\n",
1562
+ " [ 25 8 14 55 27 191]]\n",
1563
+ "Classification Report:\n",
1564
+ " precision recall f1-score support\n",
1565
+ "\n",
1566
+ " 0 0.64 0.67 0.66 340\n",
1567
+ " 1 0.90 0.90 0.90 316\n",
1568
+ " 2 0.81 0.81 0.81 293\n",
1569
+ " 3 0.67 0.68 0.67 469\n",
1570
+ " 4 0.88 0.84 0.86 445\n",
1571
+ " 5 0.60 0.60 0.60 320\n",
1572
+ "\n",
1573
+ " accuracy 0.75 2183\n",
1574
+ " macro avg 0.75 0.75 0.75 2183\n",
1575
+ "weighted avg 0.75 0.75 0.75 2183\n",
1576
+ "\n"
1577
+ ]
1578
+ },
1579
+ {
1580
+ "output_type": "stream",
1581
+ "name": "stderr",
1582
+ "text": [
1583
+ "/usr/local/lib/python3.12/dist-packages/sklearn/linear_model/_logistic.py:465: ConvergenceWarning: lbfgs failed to converge (status=1):\n",
1584
+ "STOP: TOTAL NO. OF ITERATIONS REACHED LIMIT.\n",
1585
+ "\n",
1586
+ "Increase the number of iterations (max_iter) or scale the data as shown in:\n",
1587
+ " https://scikit-learn.org/stable/modules/preprocessing.html\n",
1588
+ "Please also refer to the documentation for alternative solver options:\n",
1589
+ " https://scikit-learn.org/stable/modules/linear_model.html#logistic-regression\n",
1590
+ " n_iter_i = _check_optimize_result(\n"
1591
+ ]
1592
+ }
1593
+ ]
1594
+ },
1595
+ {
1596
+ "cell_type": "markdown",
1597
+ "source": [
1598
+ "SVC"
1599
+ ],
1600
+ "metadata": {
1601
+ "id": "Ygj8VQJc9qix"
1602
+ }
1603
+ },
1604
+ {
1605
+ "cell_type": "code",
1606
+ "source": [
1607
+ "svc = SVC(random_state=42)\n",
1608
+ "svc.fit(X_train, y_train)\n",
1609
+ "y_pred = svc.predict(X_test)\n",
1610
+ "\n",
1611
+ "print(\"=== SVC ===\")\n",
1612
+ "print(\"Accuracy:\", accuracy_score(y_test, y_pred))\n",
1613
+ "print(\"Confusion Matrix:\\n\", confusion_matrix(y_test, y_pred))\n",
1614
+ "print(\"Classification Report:\\n\", classification_report(y_test, y_pred))\n"
1615
+ ],
1616
+ "metadata": {
1617
+ "colab": {
1618
+ "base_uri": "https://localhost:8080/"
1619
+ },
1620
+ "id": "YNUh055l9hcj",
1621
+ "outputId": "d134b0bb-7ed9-4880-ad85-4e82936d44ea"
1622
+ },
1623
+ "execution_count": null,
1624
+ "outputs": [
1625
+ {
1626
+ "output_type": "stream",
1627
+ "name": "stdout",
1628
+ "text": [
1629
+ "=== SVC ===\n",
1630
+ "Accuracy: 0.9060925332111773\n",
1631
+ "Confusion Matrix:\n",
1632
+ " [[303 0 0 31 1 5]\n",
1633
+ " [ 7 304 0 1 3 1]\n",
1634
+ " [ 4 2 269 13 0 5]\n",
1635
+ " [ 7 1 15 433 5 8]\n",
1636
+ " [ 2 1 0 6 428 8]\n",
1637
+ " [ 4 0 11 59 5 241]]\n",
1638
+ "Classification Report:\n",
1639
+ " precision recall f1-score support\n",
1640
+ "\n",
1641
+ " 0 0.93 0.89 0.91 340\n",
1642
+ " 1 0.99 0.96 0.97 316\n",
1643
+ " 2 0.91 0.92 0.91 293\n",
1644
+ " 3 0.80 0.92 0.86 469\n",
1645
+ " 4 0.97 0.96 0.97 445\n",
1646
+ " 5 0.90 0.75 0.82 320\n",
1647
+ "\n",
1648
+ " accuracy 0.91 2183\n",
1649
+ " macro avg 0.92 0.90 0.91 2183\n",
1650
+ "weighted avg 0.91 0.91 0.91 2183\n",
1651
+ "\n"
1652
+ ]
1653
+ }
1654
+ ]
1655
+ },
1656
+ {
1657
+ "cell_type": "markdown",
1658
+ "source": [
1659
+ "βœ… SVC (Support Vector Classifier) is clearly the winner here (91% accuracy) β€” this is expected since:\n",
1660
+ "\n",
1661
+ "You scaled the data βœ…\n",
1662
+ "\n",
1663
+ "You did PCA (reduces noise & keeps variance) βœ…\n",
1664
+ "\n",
1665
+ "SVC works very well on high-dimensional but dense feature spaces (like PCA image features).\n",
1666
+ "\n",
1667
+ "⚑ Random Forest also did well (82%), but SVC is significantly better."
1668
+ ],
1669
+ "metadata": {
1670
+ "id": "i6zF3_gaAH7D"
1671
+ }
1672
+ },
1673
+ {
1674
+ "cell_type": "code",
1675
+ "source": [
1676
+ "import pickle\n",
1677
+ "\n",
1678
+ "# ---- Save the trained SVC model ----\n",
1679
+ "with open(\"svc_model.pkl\", \"wb\") as f:\n",
1680
+ " pickle.dump(svc, f)\n",
1681
+ "\n",
1682
+ "print(\"SVC model saved as svc_model.pkl\")\n"
1683
+ ],
1684
+ "metadata": {
1685
+ "colab": {
1686
+ "base_uri": "https://localhost:8080/"
1687
+ },
1688
+ "id": "7uFLb8WC_697",
1689
+ "outputId": "5286a2d1-de14-43fa-ea67-06b590bea87d"
1690
+ },
1691
+ "execution_count": null,
1692
+ "outputs": [
1693
+ {
1694
+ "output_type": "stream",
1695
+ "name": "stdout",
1696
+ "text": [
1697
+ "SVC model saved as svc_model.pkl\n"
1698
+ ]
1699
+ }
1700
+ ]
1701
+ },
1702
+ {
1703
+ "cell_type": "code",
1704
+ "source": [],
1705
+ "metadata": {
1706
+ "id": "fdPko5vsBlUv"
1707
+ },
1708
+ "execution_count": null,
1709
+ "outputs": []
1710
+ }
1711
+ ]
1712
+ }
src/fruit_dataset.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:0bc9d8549f72cbe1d14855283010be6ba7d63cc17e8186c6097e6f54ffb8c1e6
3
+ size 482139823
src/pca_model.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:dae2c0c01d477f20ea7658936b9e5f398c07c164698c4f8aa47827aad47c79da
3
+ size 31465747
src/scaler.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9a4692ba1b04f7f9253c1281d0664432620d91153c5cd5dcbe211bfc535d02a5
3
+ size 382726
src/svc_model.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:61d8cfa9539124be99badf278e6cd1c3967ac70dead266ca076f689442d242f6
3
+ size 13420304