LinekerS0125 commited on
Commit
4870f4e
·
verified ·
1 Parent(s): 0fe444c

Upload folder using huggingface_hub

Browse files
.ipynb_checkpoints/training_clustering-checkpoint.ipynb ADDED
The diff for this file is too large to render. See raw diff
 
model.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a88ceef41d9bfe93e326528b00a4818116629f7174d7cca44047141ee6d6d1cb
3
+ size 15827
training_clustering.ipynb ADDED
@@ -0,0 +1,1147 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "markdown",
5
+ "id": "781ff07a-10bb-49a5-9daf-2b87b86774e0",
6
+ "metadata": {},
7
+ "source": [
8
+ "## Basic description of data \n",
9
+ "\n",
10
+ "Dataset of Thai fashion and cosmetics retail sellers. Each sellers Facebook post being of a different nature (video, photos, and links). Engagement metrics consist of comments, shares, and reactions (likes, shares, comments, etc)."
11
+ ]
12
+ },
13
+ {
14
+ "cell_type": "markdown",
15
+ "id": "8aff33d6-5510-428c-a10b-db8c84cb6fd0",
16
+ "metadata": {},
17
+ "source": [
18
+ "## Clustering is unsupervised learning...\n",
19
+ "this means that we are given no labels for each point, not knowing what each group is. The goal of clustering is to find how close alike (or not at all) features are within the dataset and find any possible patterns."
20
+ ]
21
+ },
22
+ {
23
+ "cell_type": "markdown",
24
+ "id": "73f9dca4-0aae-4a09-8403-9199bb885996",
25
+ "metadata": {},
26
+ "source": [
27
+ "## Do you expect the model to work well? If not, why?\n",
28
+ "I belive that the clustering model will work well with this dataset becasue of the different variables used and its value range is large."
29
+ ]
30
+ },
31
+ {
32
+ "cell_type": "code",
33
+ "execution_count": 82,
34
+ "id": "b29f6fc7-5e98-4bbb-8458-71c6d5947424",
35
+ "metadata": {},
36
+ "outputs": [],
37
+ "source": [
38
+ "import seaborn as sns\n",
39
+ "import numpy as np\n",
40
+ "from sklearn import datasets\n",
41
+ "from sklearn.cluster import KMeans\n",
42
+ "from sklearn import metrics\n",
43
+ "import pandas as pd\n",
44
+ "import matplotlib.pyplot as plt\n",
45
+ "import itertools\n",
46
+ "import itertools as it\n",
47
+ "import string\n",
48
+ "from sklearn.model_selection import train_test_split\n",
49
+ "import os\n",
50
+ "import json\n",
51
+ "from huggingface_hub import HfApi\n",
52
+ "import skops.io as sio\n",
53
+ "from skops import card\n",
54
+ "\n",
55
+ "sns.set_theme(palette='colorblind')\n",
56
+ "\n",
57
+ "# set global random seed so that the notes are the same each time the site builds\n",
58
+ "np.random.seed(1103)\n",
59
+ "np.random.seed(113)"
60
+ ]
61
+ },
62
+ {
63
+ "cell_type": "code",
64
+ "execution_count": 83,
65
+ "id": "57b88ef8-aef7-4395-bc2c-d140ddb125f1",
66
+ "metadata": {},
67
+ "outputs": [],
68
+ "source": [
69
+ "from ucimlrepo import fetch_ucirepo\n",
70
+ "import pandas as pd\n",
71
+ "\n",
72
+ "Thai_datase = fetch_ucirepo(id=488)\n",
73
+ "\n",
74
+ "thai_X = pd.DataFrame(Thai_datase.data.features) \n",
75
+ "\n",
76
+ "thai_df = pd.DataFrame(Thai_datase.data.features) "
77
+ ]
78
+ },
79
+ {
80
+ "cell_type": "code",
81
+ "execution_count": 84,
82
+ "id": "56ec5b49-eed7-4031-b3ea-f12ec43db395",
83
+ "metadata": {},
84
+ "outputs": [],
85
+ "source": [
86
+ "thai_X = thai_X.drop(columns=['status_type','status_published'])"
87
+ ]
88
+ },
89
+ {
90
+ "cell_type": "code",
91
+ "execution_count": 85,
92
+ "id": "ab242b36-818b-4cee-859b-abdf1d06da50",
93
+ "metadata": {},
94
+ "outputs": [],
95
+ "source": [
96
+ "thai_X_train, thai_X_test= train_test_split(thai_X, train_size = 0.8)"
97
+ ]
98
+ },
99
+ {
100
+ "cell_type": "code",
101
+ "execution_count": 86,
102
+ "id": "a9f09724-a0b0-48de-9c73-1f84e8eed0f0",
103
+ "metadata": {},
104
+ "outputs": [],
105
+ "source": [
106
+ "thai_df = thai_df.drop(columns=['status_type','status_published'])"
107
+ ]
108
+ },
109
+ {
110
+ "cell_type": "code",
111
+ "execution_count": null,
112
+ "id": "2f2525ec-a98b-428e-9c53-68520bdb6c0e",
113
+ "metadata": {},
114
+ "outputs": [],
115
+ "source": []
116
+ },
117
+ {
118
+ "cell_type": "code",
119
+ "execution_count": 87,
120
+ "id": "7fc50f0b-6870-4917-9ecc-0cb9a943e22a",
121
+ "metadata": {},
122
+ "outputs": [],
123
+ "source": [
124
+ "km = KMeans(n_clusters=5)"
125
+ ]
126
+ },
127
+ {
128
+ "cell_type": "code",
129
+ "execution_count": 88,
130
+ "id": "433f8230-b5f9-4c76-8bc7-02f68e514e77",
131
+ "metadata": {},
132
+ "outputs": [
133
+ {
134
+ "data": {
135
+ "text/html": [
136
+ "<style>#sk-container-id-8 {\n",
137
+ " /* Definition of color scheme common for light and dark mode */\n",
138
+ " --sklearn-color-text: #000;\n",
139
+ " --sklearn-color-text-muted: #666;\n",
140
+ " --sklearn-color-line: gray;\n",
141
+ " /* Definition of color scheme for unfitted estimators */\n",
142
+ " --sklearn-color-unfitted-level-0: #fff5e6;\n",
143
+ " --sklearn-color-unfitted-level-1: #f6e4d2;\n",
144
+ " --sklearn-color-unfitted-level-2: #ffe0b3;\n",
145
+ " --sklearn-color-unfitted-level-3: chocolate;\n",
146
+ " /* Definition of color scheme for fitted estimators */\n",
147
+ " --sklearn-color-fitted-level-0: #f0f8ff;\n",
148
+ " --sklearn-color-fitted-level-1: #d4ebff;\n",
149
+ " --sklearn-color-fitted-level-2: #b3dbfd;\n",
150
+ " --sklearn-color-fitted-level-3: cornflowerblue;\n",
151
+ "\n",
152
+ " /* Specific color for light theme */\n",
153
+ " --sklearn-color-text-on-default-background: var(--sg-text-color, var(--theme-code-foreground, var(--jp-content-font-color1, black)));\n",
154
+ " --sklearn-color-background: var(--sg-background-color, var(--theme-background, var(--jp-layout-color0, white)));\n",
155
+ " --sklearn-color-border-box: var(--sg-text-color, var(--theme-code-foreground, var(--jp-content-font-color1, black)));\n",
156
+ " --sklearn-color-icon: #696969;\n",
157
+ "\n",
158
+ " @media (prefers-color-scheme: dark) {\n",
159
+ " /* Redefinition of color scheme for dark theme */\n",
160
+ " --sklearn-color-text-on-default-background: var(--sg-text-color, var(--theme-code-foreground, var(--jp-content-font-color1, white)));\n",
161
+ " --sklearn-color-background: var(--sg-background-color, var(--theme-background, var(--jp-layout-color0, #111)));\n",
162
+ " --sklearn-color-border-box: var(--sg-text-color, var(--theme-code-foreground, var(--jp-content-font-color1, white)));\n",
163
+ " --sklearn-color-icon: #878787;\n",
164
+ " }\n",
165
+ "}\n",
166
+ "\n",
167
+ "#sk-container-id-8 {\n",
168
+ " color: var(--sklearn-color-text);\n",
169
+ "}\n",
170
+ "\n",
171
+ "#sk-container-id-8 pre {\n",
172
+ " padding: 0;\n",
173
+ "}\n",
174
+ "\n",
175
+ "#sk-container-id-8 input.sk-hidden--visually {\n",
176
+ " border: 0;\n",
177
+ " clip: rect(1px 1px 1px 1px);\n",
178
+ " clip: rect(1px, 1px, 1px, 1px);\n",
179
+ " height: 1px;\n",
180
+ " margin: -1px;\n",
181
+ " overflow: hidden;\n",
182
+ " padding: 0;\n",
183
+ " position: absolute;\n",
184
+ " width: 1px;\n",
185
+ "}\n",
186
+ "\n",
187
+ "#sk-container-id-8 div.sk-dashed-wrapped {\n",
188
+ " border: 1px dashed var(--sklearn-color-line);\n",
189
+ " margin: 0 0.4em 0.5em 0.4em;\n",
190
+ " box-sizing: border-box;\n",
191
+ " padding-bottom: 0.4em;\n",
192
+ " background-color: var(--sklearn-color-background);\n",
193
+ "}\n",
194
+ "\n",
195
+ "#sk-container-id-8 div.sk-container {\n",
196
+ " /* jupyter's `normalize.less` sets `[hidden] { display: none; }`\n",
197
+ " but bootstrap.min.css set `[hidden] { display: none !important; }`\n",
198
+ " so we also need the `!important` here to be able to override the\n",
199
+ " default hidden behavior on the sphinx rendered scikit-learn.org.\n",
200
+ " See: https://github.com/scikit-learn/scikit-learn/issues/21755 */\n",
201
+ " display: inline-block !important;\n",
202
+ " position: relative;\n",
203
+ "}\n",
204
+ "\n",
205
+ "#sk-container-id-8 div.sk-text-repr-fallback {\n",
206
+ " display: none;\n",
207
+ "}\n",
208
+ "\n",
209
+ "div.sk-parallel-item,\n",
210
+ "div.sk-serial,\n",
211
+ "div.sk-item {\n",
212
+ " /* draw centered vertical line to link estimators */\n",
213
+ " background-image: linear-gradient(var(--sklearn-color-text-on-default-background), var(--sklearn-color-text-on-default-background));\n",
214
+ " background-size: 2px 100%;\n",
215
+ " background-repeat: no-repeat;\n",
216
+ " background-position: center center;\n",
217
+ "}\n",
218
+ "\n",
219
+ "/* Parallel-specific style estimator block */\n",
220
+ "\n",
221
+ "#sk-container-id-8 div.sk-parallel-item::after {\n",
222
+ " content: \"\";\n",
223
+ " width: 100%;\n",
224
+ " border-bottom: 2px solid var(--sklearn-color-text-on-default-background);\n",
225
+ " flex-grow: 1;\n",
226
+ "}\n",
227
+ "\n",
228
+ "#sk-container-id-8 div.sk-parallel {\n",
229
+ " display: flex;\n",
230
+ " align-items: stretch;\n",
231
+ " justify-content: center;\n",
232
+ " background-color: var(--sklearn-color-background);\n",
233
+ " position: relative;\n",
234
+ "}\n",
235
+ "\n",
236
+ "#sk-container-id-8 div.sk-parallel-item {\n",
237
+ " display: flex;\n",
238
+ " flex-direction: column;\n",
239
+ "}\n",
240
+ "\n",
241
+ "#sk-container-id-8 div.sk-parallel-item:first-child::after {\n",
242
+ " align-self: flex-end;\n",
243
+ " width: 50%;\n",
244
+ "}\n",
245
+ "\n",
246
+ "#sk-container-id-8 div.sk-parallel-item:last-child::after {\n",
247
+ " align-self: flex-start;\n",
248
+ " width: 50%;\n",
249
+ "}\n",
250
+ "\n",
251
+ "#sk-container-id-8 div.sk-parallel-item:only-child::after {\n",
252
+ " width: 0;\n",
253
+ "}\n",
254
+ "\n",
255
+ "/* Serial-specific style estimator block */\n",
256
+ "\n",
257
+ "#sk-container-id-8 div.sk-serial {\n",
258
+ " display: flex;\n",
259
+ " flex-direction: column;\n",
260
+ " align-items: center;\n",
261
+ " background-color: var(--sklearn-color-background);\n",
262
+ " padding-right: 1em;\n",
263
+ " padding-left: 1em;\n",
264
+ "}\n",
265
+ "\n",
266
+ "\n",
267
+ "/* Toggleable style: style used for estimator/Pipeline/ColumnTransformer box that is\n",
268
+ "clickable and can be expanded/collapsed.\n",
269
+ "- Pipeline and ColumnTransformer use this feature and define the default style\n",
270
+ "- Estimators will overwrite some part of the style using the `sk-estimator` class\n",
271
+ "*/\n",
272
+ "\n",
273
+ "/* Pipeline and ColumnTransformer style (default) */\n",
274
+ "\n",
275
+ "#sk-container-id-8 div.sk-toggleable {\n",
276
+ " /* Default theme specific background. It is overwritten whether we have a\n",
277
+ " specific estimator or a Pipeline/ColumnTransformer */\n",
278
+ " background-color: var(--sklearn-color-background);\n",
279
+ "}\n",
280
+ "\n",
281
+ "/* Toggleable label */\n",
282
+ "#sk-container-id-8 label.sk-toggleable__label {\n",
283
+ " cursor: pointer;\n",
284
+ " display: flex;\n",
285
+ " width: 100%;\n",
286
+ " margin-bottom: 0;\n",
287
+ " padding: 0.5em;\n",
288
+ " box-sizing: border-box;\n",
289
+ " text-align: center;\n",
290
+ " align-items: start;\n",
291
+ " justify-content: space-between;\n",
292
+ " gap: 0.5em;\n",
293
+ "}\n",
294
+ "\n",
295
+ "#sk-container-id-8 label.sk-toggleable__label .caption {\n",
296
+ " font-size: 0.6rem;\n",
297
+ " font-weight: lighter;\n",
298
+ " color: var(--sklearn-color-text-muted);\n",
299
+ "}\n",
300
+ "\n",
301
+ "#sk-container-id-8 label.sk-toggleable__label-arrow:before {\n",
302
+ " /* Arrow on the left of the label */\n",
303
+ " content: \"▸\";\n",
304
+ " float: left;\n",
305
+ " margin-right: 0.25em;\n",
306
+ " color: var(--sklearn-color-icon);\n",
307
+ "}\n",
308
+ "\n",
309
+ "#sk-container-id-8 label.sk-toggleable__label-arrow:hover:before {\n",
310
+ " color: var(--sklearn-color-text);\n",
311
+ "}\n",
312
+ "\n",
313
+ "/* Toggleable content - dropdown */\n",
314
+ "\n",
315
+ "#sk-container-id-8 div.sk-toggleable__content {\n",
316
+ " display: none;\n",
317
+ " text-align: left;\n",
318
+ " /* unfitted */\n",
319
+ " background-color: var(--sklearn-color-unfitted-level-0);\n",
320
+ "}\n",
321
+ "\n",
322
+ "#sk-container-id-8 div.sk-toggleable__content.fitted {\n",
323
+ " /* fitted */\n",
324
+ " background-color: var(--sklearn-color-fitted-level-0);\n",
325
+ "}\n",
326
+ "\n",
327
+ "#sk-container-id-8 div.sk-toggleable__content pre {\n",
328
+ " margin: 0.2em;\n",
329
+ " border-radius: 0.25em;\n",
330
+ " color: var(--sklearn-color-text);\n",
331
+ " /* unfitted */\n",
332
+ " background-color: var(--sklearn-color-unfitted-level-0);\n",
333
+ "}\n",
334
+ "\n",
335
+ "#sk-container-id-8 div.sk-toggleable__content.fitted pre {\n",
336
+ " /* unfitted */\n",
337
+ " background-color: var(--sklearn-color-fitted-level-0);\n",
338
+ "}\n",
339
+ "\n",
340
+ "#sk-container-id-8 input.sk-toggleable__control:checked~div.sk-toggleable__content {\n",
341
+ " /* Expand drop-down */\n",
342
+ " display: block;\n",
343
+ " width: 100%;\n",
344
+ " overflow: visible;\n",
345
+ "}\n",
346
+ "\n",
347
+ "#sk-container-id-8 input.sk-toggleable__control:checked~label.sk-toggleable__label-arrow:before {\n",
348
+ " content: \"▾\";\n",
349
+ "}\n",
350
+ "\n",
351
+ "/* Pipeline/ColumnTransformer-specific style */\n",
352
+ "\n",
353
+ "#sk-container-id-8 div.sk-label input.sk-toggleable__control:checked~label.sk-toggleable__label {\n",
354
+ " color: var(--sklearn-color-text);\n",
355
+ " background-color: var(--sklearn-color-unfitted-level-2);\n",
356
+ "}\n",
357
+ "\n",
358
+ "#sk-container-id-8 div.sk-label.fitted input.sk-toggleable__control:checked~label.sk-toggleable__label {\n",
359
+ " background-color: var(--sklearn-color-fitted-level-2);\n",
360
+ "}\n",
361
+ "\n",
362
+ "/* Estimator-specific style */\n",
363
+ "\n",
364
+ "/* Colorize estimator box */\n",
365
+ "#sk-container-id-8 div.sk-estimator input.sk-toggleable__control:checked~label.sk-toggleable__label {\n",
366
+ " /* unfitted */\n",
367
+ " background-color: var(--sklearn-color-unfitted-level-2);\n",
368
+ "}\n",
369
+ "\n",
370
+ "#sk-container-id-8 div.sk-estimator.fitted input.sk-toggleable__control:checked~label.sk-toggleable__label {\n",
371
+ " /* fitted */\n",
372
+ " background-color: var(--sklearn-color-fitted-level-2);\n",
373
+ "}\n",
374
+ "\n",
375
+ "#sk-container-id-8 div.sk-label label.sk-toggleable__label,\n",
376
+ "#sk-container-id-8 div.sk-label label {\n",
377
+ " /* The background is the default theme color */\n",
378
+ " color: var(--sklearn-color-text-on-default-background);\n",
379
+ "}\n",
380
+ "\n",
381
+ "/* On hover, darken the color of the background */\n",
382
+ "#sk-container-id-8 div.sk-label:hover label.sk-toggleable__label {\n",
383
+ " color: var(--sklearn-color-text);\n",
384
+ " background-color: var(--sklearn-color-unfitted-level-2);\n",
385
+ "}\n",
386
+ "\n",
387
+ "/* Label box, darken color on hover, fitted */\n",
388
+ "#sk-container-id-8 div.sk-label.fitted:hover label.sk-toggleable__label.fitted {\n",
389
+ " color: var(--sklearn-color-text);\n",
390
+ " background-color: var(--sklearn-color-fitted-level-2);\n",
391
+ "}\n",
392
+ "\n",
393
+ "/* Estimator label */\n",
394
+ "\n",
395
+ "#sk-container-id-8 div.sk-label label {\n",
396
+ " font-family: monospace;\n",
397
+ " font-weight: bold;\n",
398
+ " display: inline-block;\n",
399
+ " line-height: 1.2em;\n",
400
+ "}\n",
401
+ "\n",
402
+ "#sk-container-id-8 div.sk-label-container {\n",
403
+ " text-align: center;\n",
404
+ "}\n",
405
+ "\n",
406
+ "/* Estimator-specific */\n",
407
+ "#sk-container-id-8 div.sk-estimator {\n",
408
+ " font-family: monospace;\n",
409
+ " border: 1px dotted var(--sklearn-color-border-box);\n",
410
+ " border-radius: 0.25em;\n",
411
+ " box-sizing: border-box;\n",
412
+ " margin-bottom: 0.5em;\n",
413
+ " /* unfitted */\n",
414
+ " background-color: var(--sklearn-color-unfitted-level-0);\n",
415
+ "}\n",
416
+ "\n",
417
+ "#sk-container-id-8 div.sk-estimator.fitted {\n",
418
+ " /* fitted */\n",
419
+ " background-color: var(--sklearn-color-fitted-level-0);\n",
420
+ "}\n",
421
+ "\n",
422
+ "/* on hover */\n",
423
+ "#sk-container-id-8 div.sk-estimator:hover {\n",
424
+ " /* unfitted */\n",
425
+ " background-color: var(--sklearn-color-unfitted-level-2);\n",
426
+ "}\n",
427
+ "\n",
428
+ "#sk-container-id-8 div.sk-estimator.fitted:hover {\n",
429
+ " /* fitted */\n",
430
+ " background-color: var(--sklearn-color-fitted-level-2);\n",
431
+ "}\n",
432
+ "\n",
433
+ "/* Specification for estimator info (e.g. \"i\" and \"?\") */\n",
434
+ "\n",
435
+ "/* Common style for \"i\" and \"?\" */\n",
436
+ "\n",
437
+ ".sk-estimator-doc-link,\n",
438
+ "a:link.sk-estimator-doc-link,\n",
439
+ "a:visited.sk-estimator-doc-link {\n",
440
+ " float: right;\n",
441
+ " font-size: smaller;\n",
442
+ " line-height: 1em;\n",
443
+ " font-family: monospace;\n",
444
+ " background-color: var(--sklearn-color-background);\n",
445
+ " border-radius: 1em;\n",
446
+ " height: 1em;\n",
447
+ " width: 1em;\n",
448
+ " text-decoration: none !important;\n",
449
+ " margin-left: 0.5em;\n",
450
+ " text-align: center;\n",
451
+ " /* unfitted */\n",
452
+ " border: var(--sklearn-color-unfitted-level-1) 1pt solid;\n",
453
+ " color: var(--sklearn-color-unfitted-level-1);\n",
454
+ "}\n",
455
+ "\n",
456
+ ".sk-estimator-doc-link.fitted,\n",
457
+ "a:link.sk-estimator-doc-link.fitted,\n",
458
+ "a:visited.sk-estimator-doc-link.fitted {\n",
459
+ " /* fitted */\n",
460
+ " border: var(--sklearn-color-fitted-level-1) 1pt solid;\n",
461
+ " color: var(--sklearn-color-fitted-level-1);\n",
462
+ "}\n",
463
+ "\n",
464
+ "/* On hover */\n",
465
+ "div.sk-estimator:hover .sk-estimator-doc-link:hover,\n",
466
+ ".sk-estimator-doc-link:hover,\n",
467
+ "div.sk-label-container:hover .sk-estimator-doc-link:hover,\n",
468
+ ".sk-estimator-doc-link:hover {\n",
469
+ " /* unfitted */\n",
470
+ " background-color: var(--sklearn-color-unfitted-level-3);\n",
471
+ " color: var(--sklearn-color-background);\n",
472
+ " text-decoration: none;\n",
473
+ "}\n",
474
+ "\n",
475
+ "div.sk-estimator.fitted:hover .sk-estimator-doc-link.fitted:hover,\n",
476
+ ".sk-estimator-doc-link.fitted:hover,\n",
477
+ "div.sk-label-container:hover .sk-estimator-doc-link.fitted:hover,\n",
478
+ ".sk-estimator-doc-link.fitted:hover {\n",
479
+ " /* fitted */\n",
480
+ " background-color: var(--sklearn-color-fitted-level-3);\n",
481
+ " color: var(--sklearn-color-background);\n",
482
+ " text-decoration: none;\n",
483
+ "}\n",
484
+ "\n",
485
+ "/* Span, style for the box shown on hovering the info icon */\n",
486
+ ".sk-estimator-doc-link span {\n",
487
+ " display: none;\n",
488
+ " z-index: 9999;\n",
489
+ " position: relative;\n",
490
+ " font-weight: normal;\n",
491
+ " right: .2ex;\n",
492
+ " padding: .5ex;\n",
493
+ " margin: .5ex;\n",
494
+ " width: min-content;\n",
495
+ " min-width: 20ex;\n",
496
+ " max-width: 50ex;\n",
497
+ " color: var(--sklearn-color-text);\n",
498
+ " box-shadow: 2pt 2pt 4pt #999;\n",
499
+ " /* unfitted */\n",
500
+ " background: var(--sklearn-color-unfitted-level-0);\n",
501
+ " border: .5pt solid var(--sklearn-color-unfitted-level-3);\n",
502
+ "}\n",
503
+ "\n",
504
+ ".sk-estimator-doc-link.fitted span {\n",
505
+ " /* fitted */\n",
506
+ " background: var(--sklearn-color-fitted-level-0);\n",
507
+ " border: var(--sklearn-color-fitted-level-3);\n",
508
+ "}\n",
509
+ "\n",
510
+ ".sk-estimator-doc-link:hover span {\n",
511
+ " display: block;\n",
512
+ "}\n",
513
+ "\n",
514
+ "/* \"?\"-specific style due to the `<a>` HTML tag */\n",
515
+ "\n",
516
+ "#sk-container-id-8 a.estimator_doc_link {\n",
517
+ " float: right;\n",
518
+ " font-size: 1rem;\n",
519
+ " line-height: 1em;\n",
520
+ " font-family: monospace;\n",
521
+ " background-color: var(--sklearn-color-background);\n",
522
+ " border-radius: 1rem;\n",
523
+ " height: 1rem;\n",
524
+ " width: 1rem;\n",
525
+ " text-decoration: none;\n",
526
+ " /* unfitted */\n",
527
+ " color: var(--sklearn-color-unfitted-level-1);\n",
528
+ " border: var(--sklearn-color-unfitted-level-1) 1pt solid;\n",
529
+ "}\n",
530
+ "\n",
531
+ "#sk-container-id-8 a.estimator_doc_link.fitted {\n",
532
+ " /* fitted */\n",
533
+ " border: var(--sklearn-color-fitted-level-1) 1pt solid;\n",
534
+ " color: var(--sklearn-color-fitted-level-1);\n",
535
+ "}\n",
536
+ "\n",
537
+ "/* On hover */\n",
538
+ "#sk-container-id-8 a.estimator_doc_link:hover {\n",
539
+ " /* unfitted */\n",
540
+ " background-color: var(--sklearn-color-unfitted-level-3);\n",
541
+ " color: var(--sklearn-color-background);\n",
542
+ " text-decoration: none;\n",
543
+ "}\n",
544
+ "\n",
545
+ "#sk-container-id-8 a.estimator_doc_link.fitted:hover {\n",
546
+ " /* fitted */\n",
547
+ " background-color: var(--sklearn-color-fitted-level-3);\n",
548
+ "}\n",
549
+ "\n",
550
+ ".estimator-table summary {\n",
551
+ " padding: .5rem;\n",
552
+ " font-family: monospace;\n",
553
+ " cursor: pointer;\n",
554
+ "}\n",
555
+ "\n",
556
+ ".estimator-table details[open] {\n",
557
+ " padding-left: 0.1rem;\n",
558
+ " padding-right: 0.1rem;\n",
559
+ " padding-bottom: 0.3rem;\n",
560
+ "}\n",
561
+ "\n",
562
+ ".estimator-table .parameters-table {\n",
563
+ " margin-left: auto !important;\n",
564
+ " margin-right: auto !important;\n",
565
+ "}\n",
566
+ "\n",
567
+ ".estimator-table .parameters-table tr:nth-child(odd) {\n",
568
+ " background-color: #fff;\n",
569
+ "}\n",
570
+ "\n",
571
+ ".estimator-table .parameters-table tr:nth-child(even) {\n",
572
+ " background-color: #f6f6f6;\n",
573
+ "}\n",
574
+ "\n",
575
+ ".estimator-table .parameters-table tr:hover {\n",
576
+ " background-color: #e0e0e0;\n",
577
+ "}\n",
578
+ "\n",
579
+ ".estimator-table table td {\n",
580
+ " border: 1px solid rgba(106, 105, 104, 0.232);\n",
581
+ "}\n",
582
+ "\n",
583
+ ".user-set td {\n",
584
+ " color:rgb(255, 94, 0);\n",
585
+ " text-align: left;\n",
586
+ "}\n",
587
+ "\n",
588
+ ".user-set td.value pre {\n",
589
+ " color:rgb(255, 94, 0) !important;\n",
590
+ " background-color: transparent !important;\n",
591
+ "}\n",
592
+ "\n",
593
+ ".default td {\n",
594
+ " color: black;\n",
595
+ " text-align: left;\n",
596
+ "}\n",
597
+ "\n",
598
+ ".user-set td i,\n",
599
+ ".default td i {\n",
600
+ " color: black;\n",
601
+ "}\n",
602
+ "\n",
603
+ ".copy-paste-icon {\n",
604
+ " background-image: url(data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA0NDggNTEyIj48IS0tIUZvbnQgQXdlc29tZSBGcmVlIDYuNy4yIGJ5IEBmb250YXdlc29tZSAtIGh0dHBzOi8vZm9udGF3ZXNvbWUuY29tIExpY2Vuc2UgLSBodHRwczovL2ZvbnRhd2Vzb21lLmNvbS9saWNlbnNlL2ZyZWUgQ29weXJpZ2h0IDIwMjUgRm9udGljb25zLCBJbmMuLS0+PHBhdGggZD0iTTIwOCAwTDMzMi4xIDBjMTIuNyAwIDI0LjkgNS4xIDMzLjkgMTQuMWw2Ny45IDY3LjljOSA5IDE0LjEgMjEuMiAxNC4xIDMzLjlMNDQ4IDMzNmMwIDI2LjUtMjEuNSA0OC00OCA0OGwtMTkyIDBjLTI2LjUgMC00OC0yMS41LTQ4LTQ4bDAtMjg4YzAtMjYuNSAyMS41LTQ4IDQ4LTQ4ek00OCAxMjhsODAgMCAwIDY0LTY0IDAgMCAyNTYgMTkyIDAgMC0zMiA2NCAwIDAgNDhjMCAyNi41LTIxLjUgNDgtNDggNDhMNDggNTEyYy0yNi41IDAtNDgtMjEuNS00OC00OEwwIDE3NmMwLTI2LjUgMjEuNS00OCA0OC00OHoiLz48L3N2Zz4=);\n",
605
+ " background-repeat: no-repeat;\n",
606
+ " background-size: 14px 14px;\n",
607
+ " background-position: 0;\n",
608
+ " display: inline-block;\n",
609
+ " width: 14px;\n",
610
+ " height: 14px;\n",
611
+ " cursor: pointer;\n",
612
+ "}\n",
613
+ "</style><body><div id=\"sk-container-id-8\" class=\"sk-top-container\"><div class=\"sk-text-repr-fallback\"><pre>KMeans(n_clusters=5)</pre><b>In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook. <br />On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.</b></div><div class=\"sk-container\" hidden><div class=\"sk-item\"><div class=\"sk-estimator fitted sk-toggleable\"><input class=\"sk-toggleable__control sk-hidden--visually\" id=\"sk-estimator-id-8\" type=\"checkbox\" checked><label for=\"sk-estimator-id-8\" class=\"sk-toggleable__label fitted sk-toggleable__label-arrow\"><div><div>KMeans</div></div><div><a class=\"sk-estimator-doc-link fitted\" rel=\"noreferrer\" target=\"_blank\" href=\"https://scikit-learn.org/1.7/modules/generated/sklearn.cluster.KMeans.html\">?<span>Documentation for KMeans</span></a><span class=\"sk-estimator-doc-link fitted\">i<span>Fitted</span></span></div></label><div class=\"sk-toggleable__content fitted\" data-param-prefix=\"\">\n",
614
+ " <div class=\"estimator-table\">\n",
615
+ " <details>\n",
616
+ " <summary>Parameters</summary>\n",
617
+ " <table class=\"parameters-table\">\n",
618
+ " <tbody>\n",
619
+ " \n",
620
+ " <tr class=\"user-set\">\n",
621
+ " <td><i class=\"copy-paste-icon\"\n",
622
+ " onclick=\"copyToClipboard('n_clusters',\n",
623
+ " this.parentElement.nextElementSibling)\"\n",
624
+ " ></i></td>\n",
625
+ " <td class=\"param\">n_clusters&nbsp;</td>\n",
626
+ " <td class=\"value\">5</td>\n",
627
+ " </tr>\n",
628
+ " \n",
629
+ "\n",
630
+ " <tr class=\"default\">\n",
631
+ " <td><i class=\"copy-paste-icon\"\n",
632
+ " onclick=\"copyToClipboard('init',\n",
633
+ " this.parentElement.nextElementSibling)\"\n",
634
+ " ></i></td>\n",
635
+ " <td class=\"param\">init&nbsp;</td>\n",
636
+ " <td class=\"value\">&#x27;k-means++&#x27;</td>\n",
637
+ " </tr>\n",
638
+ " \n",
639
+ "\n",
640
+ " <tr class=\"default\">\n",
641
+ " <td><i class=\"copy-paste-icon\"\n",
642
+ " onclick=\"copyToClipboard('n_init',\n",
643
+ " this.parentElement.nextElementSibling)\"\n",
644
+ " ></i></td>\n",
645
+ " <td class=\"param\">n_init&nbsp;</td>\n",
646
+ " <td class=\"value\">&#x27;auto&#x27;</td>\n",
647
+ " </tr>\n",
648
+ " \n",
649
+ "\n",
650
+ " <tr class=\"default\">\n",
651
+ " <td><i class=\"copy-paste-icon\"\n",
652
+ " onclick=\"copyToClipboard('max_iter',\n",
653
+ " this.parentElement.nextElementSibling)\"\n",
654
+ " ></i></td>\n",
655
+ " <td class=\"param\">max_iter&nbsp;</td>\n",
656
+ " <td class=\"value\">300</td>\n",
657
+ " </tr>\n",
658
+ " \n",
659
+ "\n",
660
+ " <tr class=\"default\">\n",
661
+ " <td><i class=\"copy-paste-icon\"\n",
662
+ " onclick=\"copyToClipboard('tol',\n",
663
+ " this.parentElement.nextElementSibling)\"\n",
664
+ " ></i></td>\n",
665
+ " <td class=\"param\">tol&nbsp;</td>\n",
666
+ " <td class=\"value\">0.0001</td>\n",
667
+ " </tr>\n",
668
+ " \n",
669
+ "\n",
670
+ " <tr class=\"default\">\n",
671
+ " <td><i class=\"copy-paste-icon\"\n",
672
+ " onclick=\"copyToClipboard('verbose',\n",
673
+ " this.parentElement.nextElementSibling)\"\n",
674
+ " ></i></td>\n",
675
+ " <td class=\"param\">verbose&nbsp;</td>\n",
676
+ " <td class=\"value\">0</td>\n",
677
+ " </tr>\n",
678
+ " \n",
679
+ "\n",
680
+ " <tr class=\"default\">\n",
681
+ " <td><i class=\"copy-paste-icon\"\n",
682
+ " onclick=\"copyToClipboard('random_state',\n",
683
+ " this.parentElement.nextElementSibling)\"\n",
684
+ " ></i></td>\n",
685
+ " <td class=\"param\">random_state&nbsp;</td>\n",
686
+ " <td class=\"value\">None</td>\n",
687
+ " </tr>\n",
688
+ " \n",
689
+ "\n",
690
+ " <tr class=\"default\">\n",
691
+ " <td><i class=\"copy-paste-icon\"\n",
692
+ " onclick=\"copyToClipboard('copy_x',\n",
693
+ " this.parentElement.nextElementSibling)\"\n",
694
+ " ></i></td>\n",
695
+ " <td class=\"param\">copy_x&nbsp;</td>\n",
696
+ " <td class=\"value\">True</td>\n",
697
+ " </tr>\n",
698
+ " \n",
699
+ "\n",
700
+ " <tr class=\"default\">\n",
701
+ " <td><i class=\"copy-paste-icon\"\n",
702
+ " onclick=\"copyToClipboard('algorithm',\n",
703
+ " this.parentElement.nextElementSibling)\"\n",
704
+ " ></i></td>\n",
705
+ " <td class=\"param\">algorithm&nbsp;</td>\n",
706
+ " <td class=\"value\">&#x27;lloyd&#x27;</td>\n",
707
+ " </tr>\n",
708
+ " \n",
709
+ " </tbody>\n",
710
+ " </table>\n",
711
+ " </details>\n",
712
+ " </div>\n",
713
+ " </div></div></div></div></div><script>function copyToClipboard(text, element) {\n",
714
+ " // Get the parameter prefix from the closest toggleable content\n",
715
+ " const toggleableContent = element.closest('.sk-toggleable__content');\n",
716
+ " const paramPrefix = toggleableContent ? toggleableContent.dataset.paramPrefix : '';\n",
717
+ " const fullParamName = paramPrefix ? `${paramPrefix}${text}` : text;\n",
718
+ "\n",
719
+ " const originalStyle = element.style;\n",
720
+ " const computedStyle = window.getComputedStyle(element);\n",
721
+ " const originalWidth = computedStyle.width;\n",
722
+ " const originalHTML = element.innerHTML.replace('Copied!', '');\n",
723
+ "\n",
724
+ " navigator.clipboard.writeText(fullParamName)\n",
725
+ " .then(() => {\n",
726
+ " element.style.width = originalWidth;\n",
727
+ " element.style.color = 'green';\n",
728
+ " element.innerHTML = \"Copied!\";\n",
729
+ "\n",
730
+ " setTimeout(() => {\n",
731
+ " element.innerHTML = originalHTML;\n",
732
+ " element.style = originalStyle;\n",
733
+ " }, 2000);\n",
734
+ " })\n",
735
+ " .catch(err => {\n",
736
+ " console.error('Failed to copy:', err);\n",
737
+ " element.style.color = 'red';\n",
738
+ " element.innerHTML = \"Failed!\";\n",
739
+ " setTimeout(() => {\n",
740
+ " element.innerHTML = originalHTML;\n",
741
+ " element.style = originalStyle;\n",
742
+ " }, 2000);\n",
743
+ " });\n",
744
+ " return false;\n",
745
+ "}\n",
746
+ "\n",
747
+ "document.querySelectorAll('.fa-regular.fa-copy').forEach(function(element) {\n",
748
+ " const toggleableContent = element.closest('.sk-toggleable__content');\n",
749
+ " const paramPrefix = toggleableContent ? toggleableContent.dataset.paramPrefix : '';\n",
750
+ " const paramName = element.parentElement.nextElementSibling.textContent.trim();\n",
751
+ " const fullParamName = paramPrefix ? `${paramPrefix}${paramName}` : paramName;\n",
752
+ "\n",
753
+ " element.setAttribute('title', fullParamName);\n",
754
+ "});\n",
755
+ "</script></body>"
756
+ ],
757
+ "text/plain": [
758
+ "KMeans(n_clusters=5)"
759
+ ]
760
+ },
761
+ "execution_count": 88,
762
+ "metadata": {},
763
+ "output_type": "execute_result"
764
+ }
765
+ ],
766
+ "source": [
767
+ "km.fit(thai_X_train)"
768
+ ]
769
+ },
770
+ {
771
+ "cell_type": "markdown",
772
+ "id": "08f2ef95-e316-484f-9dd6-1041fa1cdf7a",
773
+ "metadata": {},
774
+ "source": [
775
+ "# These plots will be show...\n",
776
+ "how users interact with each facebook post: positive engagement (likes, loves, wows, hahas), negative engagement (sads, angrys), and voluntary acitons (reactions, shares, comments)"
777
+ ]
778
+ },
779
+ {
780
+ "cell_type": "code",
781
+ "execution_count": null,
782
+ "id": "e22f53ac-677a-426a-ba31-f9397bbd3ab7",
783
+ "metadata": {
784
+ "scrolled": true
785
+ },
786
+ "outputs": [],
787
+ "source": [
788
+ "thai_df['km5'] = km.predict(thai_X).astype(str)\n",
789
+ "sns.pairplot(thai_df, hue='km5')"
790
+ ]
791
+ },
792
+ {
793
+ "cell_type": "code",
794
+ "execution_count": null,
795
+ "id": "b7296548-7bcb-4e15-bbec-ad030c5d55f4",
796
+ "metadata": {},
797
+ "outputs": [],
798
+ "source": [
799
+ "sns.scatterplot(data =thai_df,x='num_comments',y='num_loves',hue='km5')"
800
+ ]
801
+ },
802
+ {
803
+ "cell_type": "markdown",
804
+ "id": "0ffd0513-16f1-49b3-bf79-1388722fc143",
805
+ "metadata": {},
806
+ "source": [
807
+ "(above) clear section groups of colors"
808
+ ]
809
+ },
810
+ {
811
+ "cell_type": "code",
812
+ "execution_count": null,
813
+ "id": "39b58ab4-01e8-48d8-9493-373e750a44e1",
814
+ "metadata": {},
815
+ "outputs": [],
816
+ "source": [
817
+ "sns.scatterplot(data =thai_df,x='num_sads',y='num_loves',hue='km5')"
818
+ ]
819
+ },
820
+ {
821
+ "cell_type": "markdown",
822
+ "id": "f244fad1-21eb-4569-a19c-49a1a69ff3c5",
823
+ "metadata": {},
824
+ "source": [
825
+ "(above) Unorganized clump of plots in the corner"
826
+ ]
827
+ },
828
+ {
829
+ "cell_type": "code",
830
+ "execution_count": 74,
831
+ "id": "514c8f53-442f-44ba-b51a-4e097ee8e45b",
832
+ "metadata": {},
833
+ "outputs": [
834
+ {
835
+ "ename": "KeyError",
836
+ "evalue": "'km4'",
837
+ "output_type": "error",
838
+ "traceback": [
839
+ "\u001b[31m---------------------------------------------------------------------------\u001b[39m",
840
+ "\u001b[31mKeyError\u001b[39m Traceback (most recent call last)",
841
+ "\u001b[36mFile \u001b[39m\u001b[32m~\\miniforge3\\Lib\\site-packages\\pandas\\core\\indexes\\base.py:3812\u001b[39m, in \u001b[36mIndex.get_loc\u001b[39m\u001b[34m(self, key)\u001b[39m\n\u001b[32m 3811\u001b[39m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[32m-> \u001b[39m\u001b[32m3812\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43m_engine\u001b[49m\u001b[43m.\u001b[49m\u001b[43mget_loc\u001b[49m\u001b[43m(\u001b[49m\u001b[43mcasted_key\u001b[49m\u001b[43m)\u001b[49m\n\u001b[32m 3813\u001b[39m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mKeyError\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m err:\n",
842
+ "\u001b[36mFile \u001b[39m\u001b[32mpandas/_libs/index.pyx:167\u001b[39m, in \u001b[36mpandas._libs.index.IndexEngine.get_loc\u001b[39m\u001b[34m()\u001b[39m\n",
843
+ "\u001b[36mFile \u001b[39m\u001b[32mpandas/_libs/index.pyx:196\u001b[39m, in \u001b[36mpandas._libs.index.IndexEngine.get_loc\u001b[39m\u001b[34m()\u001b[39m\n",
844
+ "\u001b[36mFile \u001b[39m\u001b[32mpandas/_libs/hashtable_class_helper.pxi:7088\u001b[39m, in \u001b[36mpandas._libs.hashtable.PyObjectHashTable.get_item\u001b[39m\u001b[34m()\u001b[39m\n",
845
+ "\u001b[36mFile \u001b[39m\u001b[32mpandas/_libs/hashtable_class_helper.pxi:7096\u001b[39m, in \u001b[36mpandas._libs.hashtable.PyObjectHashTable.get_item\u001b[39m\u001b[34m()\u001b[39m\n",
846
+ "\u001b[31mKeyError\u001b[39m: 'km4'",
847
+ "\nThe above exception was the direct cause of the following exception:\n",
848
+ "\u001b[31mKeyError\u001b[39m Traceback (most recent call last)",
849
+ "\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[74]\u001b[39m\u001b[32m, line 1\u001b[39m\n\u001b[32m----> \u001b[39m\u001b[32m1\u001b[39m metrics.silhouette_score(thai_X_train, \u001b[43mthai_df\u001b[49m\u001b[43m[\u001b[49m\u001b[33;43m'\u001b[39;49m\u001b[33;43mkm4\u001b[39;49m\u001b[33;43m'\u001b[39;49m\u001b[43m]\u001b[49m)\n",
850
+ "\u001b[36mFile \u001b[39m\u001b[32m~\\miniforge3\\Lib\\site-packages\\pandas\\core\\frame.py:4107\u001b[39m, in \u001b[36mDataFrame.__getitem__\u001b[39m\u001b[34m(self, key)\u001b[39m\n\u001b[32m 4105\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mself\u001b[39m.columns.nlevels > \u001b[32m1\u001b[39m:\n\u001b[32m 4106\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m._getitem_multilevel(key)\n\u001b[32m-> \u001b[39m\u001b[32m4107\u001b[39m indexer = \u001b[38;5;28;43mself\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43mcolumns\u001b[49m\u001b[43m.\u001b[49m\u001b[43mget_loc\u001b[49m\u001b[43m(\u001b[49m\u001b[43mkey\u001b[49m\u001b[43m)\u001b[49m\n\u001b[32m 4108\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m is_integer(indexer):\n\u001b[32m 4109\u001b[39m indexer = [indexer]\n",
851
+ "\u001b[36mFile \u001b[39m\u001b[32m~\\miniforge3\\Lib\\site-packages\\pandas\\core\\indexes\\base.py:3819\u001b[39m, in \u001b[36mIndex.get_loc\u001b[39m\u001b[34m(self, key)\u001b[39m\n\u001b[32m 3814\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(casted_key, \u001b[38;5;28mslice\u001b[39m) \u001b[38;5;129;01mor\u001b[39;00m (\n\u001b[32m 3815\u001b[39m \u001b[38;5;28misinstance\u001b[39m(casted_key, abc.Iterable)\n\u001b[32m 3816\u001b[39m \u001b[38;5;129;01mand\u001b[39;00m \u001b[38;5;28many\u001b[39m(\u001b[38;5;28misinstance\u001b[39m(x, \u001b[38;5;28mslice\u001b[39m) \u001b[38;5;28;01mfor\u001b[39;00m x \u001b[38;5;129;01min\u001b[39;00m casted_key)\n\u001b[32m 3817\u001b[39m ):\n\u001b[32m 3818\u001b[39m \u001b[38;5;28;01mraise\u001b[39;00m InvalidIndexError(key)\n\u001b[32m-> \u001b[39m\u001b[32m3819\u001b[39m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mKeyError\u001b[39;00m(key) \u001b[38;5;28;01mfrom\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01merr\u001b[39;00m\n\u001b[32m 3820\u001b[39m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mTypeError\u001b[39;00m:\n\u001b[32m 3821\u001b[39m \u001b[38;5;66;03m# If we have a listlike key, _check_indexing_error will raise\u001b[39;00m\n\u001b[32m 3822\u001b[39m \u001b[38;5;66;03m# InvalidIndexError. Otherwise we fall through and re-raise\u001b[39;00m\n\u001b[32m 3823\u001b[39m \u001b[38;5;66;03m# the TypeError.\u001b[39;00m\n\u001b[32m 3824\u001b[39m \u001b[38;5;28mself\u001b[39m._check_indexing_error(key)\n",
852
+ "\u001b[31mKeyError\u001b[39m: 'km4'"
853
+ ]
854
+ }
855
+ ],
856
+ "source": [
857
+ "metrics.silhouette_score(thai_X_train, thai_df['km4'])"
858
+ ]
859
+ },
860
+ {
861
+ "cell_type": "code",
862
+ "execution_count": null,
863
+ "id": "3cee6401-5ca0-4094-8abd-72f1cf36eb6b",
864
+ "metadata": {},
865
+ "outputs": [],
866
+ "source": [
867
+ "metrics.adjusted_mutual_info_score(thai_df['num_reactions'],thai_df['km4'])"
868
+ ]
869
+ },
870
+ {
871
+ "cell_type": "markdown",
872
+ "id": "09fc81c0-2beb-4b13-ac9a-600413e5ab2c",
873
+ "metadata": {},
874
+ "source": [
875
+ "___\n",
876
+ "___\n",
877
+ "## Clustering"
878
+ ]
879
+ },
880
+ {
881
+ "cell_type": "markdown",
882
+ "id": "70729a6c-a13d-449e-8daf-9654cf0cefdb",
883
+ "metadata": {},
884
+ "source": [
885
+ "**Describe what question you would be asking in applying clustering to this dataset. What does it mean if clustering does not work well?**"
886
+ ]
887
+ },
888
+ {
889
+ "cell_type": "markdown",
890
+ "id": "365f8d5c-daf8-4a1f-b2ca-745bafaace1d",
891
+ "metadata": {},
892
+ "source": [
893
+ "**How does this task compare to what the classification task on this dataset?**\n",
894
+ "\n",
895
+ "For this specific dataset, finding a correlation between people social media interations is a better fit job for clustering. Classification would not be able to recognize patterns or groupings in the dataset, only predictions about certain points."
896
+ ]
897
+ },
898
+ {
899
+ "cell_type": "markdown",
900
+ "id": "cdb29b55-9e49-4600-a5a0-569e936f4ed2",
901
+ "metadata": {},
902
+ "source": [
903
+ "**Evaluate how well clustering worked on the data:**\n",
904
+ "\n",
905
+ "* using a true clustering metric and\n",
906
+ "\n",
907
+ "* using visualization and\n",
908
+ "\n",
909
+ "* using a clustering metric that uses the ground truth labels\n"
910
+ ]
911
+ },
912
+ {
913
+ "cell_type": "markdown",
914
+ "id": "3887e4a7-cb2d-4285-b99a-58d734f7616b",
915
+ "metadata": {},
916
+ "source": [
917
+ "\n",
918
+ "* Does this clustering work better or worse than expected based on the classification performance (if you didn’t complete assignment 7, also apply a classifier)\n",
919
+ "*\n",
920
+ "___\n",
921
+ "___"
922
+ ]
923
+ },
924
+ {
925
+ "cell_type": "markdown",
926
+ "id": "023feeb4-d682-408c-be46-e2ec0f62d7c7",
927
+ "metadata": {},
928
+ "source": [
929
+ "**sharing code (below)**"
930
+ ]
931
+ },
932
+ {
933
+ "cell_type": "code",
934
+ "execution_count": null,
935
+ "id": "9eaed342-7d5b-4b24-9e4d-9e5f59b14f43",
936
+ "metadata": {},
937
+ "outputs": [],
938
+ "source": [
939
+ "api = HfApi()\n",
940
+ "api.create_repo(repo_id=\"CSC310-fall25/Lineker_clustering\",)"
941
+ ]
942
+ },
943
+ {
944
+ "cell_type": "code",
945
+ "execution_count": null,
946
+ "id": "4793a9da-c619-4bf7-96f4-e5bbd9e8438f",
947
+ "metadata": {},
948
+ "outputs": [],
949
+ "source": [
950
+ "thai_X_test.to_csv('applesauce/thai_sellers.csv')"
951
+ ]
952
+ },
953
+ {
954
+ "cell_type": "code",
955
+ "execution_count": null,
956
+ "id": "550e1ef2-1eec-4440-8faa-17cf4eec41a7",
957
+ "metadata": {},
958
+ "outputs": [],
959
+ "source": [
960
+ "config = {\n",
961
+ " \"sklearn\": {\n",
962
+ " \"columns\": [\n",
963
+ " \"status_type\",\n",
964
+ " \"status_published\",\n",
965
+ " \"num_reactions\",\n",
966
+ " \"num_comments\",\n",
967
+ " \"num_shares\",\n",
968
+ " \"num_likes\",\n",
969
+ " \"num_loves\",\n",
970
+ " \"num_wows\",\n",
971
+ " \"num_hahas\",\n",
972
+ " \"num_sads\",\n",
973
+ " \"num_angrys\"\n",
974
+ " ],\n",
975
+ " \"environment\": [\n",
976
+ " \"scikit-learn=1.0.2\"\n",
977
+ " ],\n",
978
+ " \"example_input\": {\n",
979
+ " \"num_reactions\": [\n",
980
+ " 529,\n",
981
+ " 150,\n",
982
+ " 227\n",
983
+ " ],\n",
984
+ " \"num_shares\": [\n",
985
+ " 512,\n",
986
+ " 0,\n",
987
+ " 236\n",
988
+ " ],\n",
989
+ " },\n",
990
+ " \"model\": {\n",
991
+ " \"file\": \"model.pkl\"\n",
992
+ " },\n",
993
+ " \"task\": \"clustering\"\n",
994
+ " }\n",
995
+ "}\n",
996
+ "with open(os.path.join(local_repo,'config.json'),'w')as f:\n",
997
+ " f.write(json.dumps(config))"
998
+ ]
999
+ },
1000
+ {
1001
+ "cell_type": "code",
1002
+ "execution_count": 80,
1003
+ "id": "08179324-2609-43be-b288-fe7457933a17",
1004
+ "metadata": {},
1005
+ "outputs": [
1006
+ {
1007
+ "data": {
1008
+ "text/plain": [
1009
+ "Card(\n",
1010
+ " model=KMeans(n_clusters=5),\n",
1011
+ " Model description=This is a Clustering model t... and cosmeticsretail sellers.,\n",
1012
+ " Model description/Intended uses & limitations=Plots not repr...sults may vary.,\n",
1013
+ " Model description/Training Procedure/Hyperparameters=TableSection(9x2),\n",
1014
+ " Model description/Training Procedure/Model Plot=<style>#sk-co...script></body>,\n",
1015
+ " Model Card Authors=Lineker Sanchez,\n",
1016
+ " Intended uses & limitations=Plots not representing ...person,results may vary.,\n",
1017
+ ")"
1018
+ ]
1019
+ },
1020
+ "execution_count": 80,
1021
+ "metadata": {},
1022
+ "output_type": "execute_result"
1023
+ }
1024
+ ],
1025
+ "source": [
1026
+ "model_card = card.Card(km)\n",
1027
+ "limitations = (\n",
1028
+ " \"Plots not representing different forms of media(photo, video, GIF, etc).\"\n",
1029
+ " \"Social media frequency and way of use differs from person to person,\"\n",
1030
+ " \"results may vary.\"\n",
1031
+ ")\n",
1032
+ "model_description = (\n",
1033
+ " \"This is a Clustering model trained on a dataset of Thai fashion and cosmetics\" \n",
1034
+ " \"retail sellers.\"\n",
1035
+ ")\n",
1036
+ "model_card_authors = \"Lineker Sanchez\"\n",
1037
+ "model_card.add(\n",
1038
+ " folded=False,\n",
1039
+ " **{\n",
1040
+ " \"Model Card Authors\": model_card_authors,\n",
1041
+ " \"Intended uses & limitations\": limitations,\n",
1042
+ " \"Model description\": model_description,\n",
1043
+ " \"Model description/Intended uses & limitations\": limitations,\n",
1044
+ " },\n",
1045
+ ")"
1046
+ ]
1047
+ },
1048
+ {
1049
+ "cell_type": "code",
1050
+ "execution_count": 81,
1051
+ "id": "760adbe8-36e9-4bf6-a1bf-5b56b651dedb",
1052
+ "metadata": {},
1053
+ "outputs": [
1054
+ {
1055
+ "ename": "NameError",
1056
+ "evalue": "name 'local_repo' is not defined",
1057
+ "output_type": "error",
1058
+ "traceback": [
1059
+ "\u001b[31m---------------------------------------------------------------------------\u001b[39m",
1060
+ "\u001b[31mNameError\u001b[39m Traceback (most recent call last)",
1061
+ "\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[81]\u001b[39m\u001b[32m, line 1\u001b[39m\n\u001b[32m----> \u001b[39m\u001b[32m1\u001b[39m mc_path =os.path.join(\u001b[43mlocal_repo\u001b[49m, \u001b[33m\"\u001b[39m\u001b[33mREADME.md\u001b[39m\u001b[33m\"\u001b[39m)\n\u001b[32m 2\u001b[39m model_card.save(mc_path)\n",
1062
+ "\u001b[31mNameError\u001b[39m: name 'local_repo' is not defined"
1063
+ ]
1064
+ }
1065
+ ],
1066
+ "source": [
1067
+ "mc_path =os.path.join(local_repo, \"README.md\")\n",
1068
+ "model_card.save(mc_path)"
1069
+ ]
1070
+ },
1071
+ {
1072
+ "cell_type": "code",
1073
+ "execution_count": null,
1074
+ "id": "4f4aac17-0dd5-482b-bdfc-1a3a2dfea6fd",
1075
+ "metadata": {},
1076
+ "outputs": [],
1077
+ "source": [
1078
+ "api = HfApi(token=os.getenv(\"PercyToken\"))\n",
1079
+ "api.upload_folder(\n",
1080
+ " folder_path=\"\",\n",
1081
+ " repo_id=\"CSC310-fall25/Lineker_clustering\",\n",
1082
+ " repo_type=\"model\",\n",
1083
+ ")"
1084
+ ]
1085
+ },
1086
+ {
1087
+ "cell_type": "code",
1088
+ "execution_count": null,
1089
+ "id": "a32ff7ae-e2d5-45b6-930c-0da65ec0a382",
1090
+ "metadata": {},
1091
+ "outputs": [],
1092
+ "source": [
1093
+ "from huggingface_hub import hf_hub_download\n",
1094
+ "hf_hub_download(repo_id=\"CSC310-fall25/example_decision_tree\", filename=\"model.pkl\",local_dir='.')\n",
1095
+ "km_loaded = sio.load('model.pkl')"
1096
+ ]
1097
+ },
1098
+ {
1099
+ "cell_type": "code",
1100
+ "execution_count": null,
1101
+ "id": "63c01bcf-f9e8-422b-bfb2-dc53272c87dd",
1102
+ "metadata": {},
1103
+ "outputs": [],
1104
+ "source": [
1105
+ "km.score(thai_X_test)\n",
1106
+ "\n"
1107
+ ]
1108
+ },
1109
+ {
1110
+ "cell_type": "code",
1111
+ "execution_count": null,
1112
+ "id": "aaf44a4d-ce08-4e52-9acf-8edc4e6eb1b2",
1113
+ "metadata": {},
1114
+ "outputs": [],
1115
+ "source": []
1116
+ },
1117
+ {
1118
+ "cell_type": "code",
1119
+ "execution_count": null,
1120
+ "id": "278dfb84-3295-4d5a-9d16-8dd379a3de82",
1121
+ "metadata": {},
1122
+ "outputs": [],
1123
+ "source": []
1124
+ }
1125
+ ],
1126
+ "metadata": {
1127
+ "kernelspec": {
1128
+ "display_name": "Python 3 (ipykernel)",
1129
+ "language": "python",
1130
+ "name": "python3"
1131
+ },
1132
+ "language_info": {
1133
+ "codemirror_mode": {
1134
+ "name": "ipython",
1135
+ "version": 3
1136
+ },
1137
+ "file_extension": ".py",
1138
+ "mimetype": "text/x-python",
1139
+ "name": "python",
1140
+ "nbconvert_exporter": "python",
1141
+ "pygments_lexer": "ipython3",
1142
+ "version": "3.12.11"
1143
+ }
1144
+ },
1145
+ "nbformat": 4,
1146
+ "nbformat_minor": 5
1147
+ }