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count": 1,
6
+ "id": "e1bdbd46-1f35-4373-80ec-727f0e26f009",
7
+ "metadata": {},
8
+ "outputs": [],
9
+ "source": [
10
+ "import numpy as np\n",
11
+ "import pandas as pd\n",
12
+ "from sklearn.datasets import load_iris\n",
13
+ "from sklearn.model_selection import train_test_split\n",
14
+ "from sklearn.linear_model import LinearRegression\n",
15
+ "from sklearn.metrics import accuracy_score\n",
16
+ "\n",
17
+ "import warnings\n",
18
+ "warnings.filterwarnings(\"ignore\")"
19
+ ]
20
+ },
21
+ {
22
+ "cell_type": "code",
23
+ "execution_count": 2,
24
+ "id": "327dafe0-68d4-4200-a889-b03bc97a1057",
25
+ "metadata": {},
26
+ "outputs": [],
27
+ "source": [
28
+ "iris = load_iris()"
29
+ ]
30
+ },
31
+ {
32
+ "cell_type": "code",
33
+ "execution_count": 3,
34
+ "id": "5ced7579-bb9f-4a20-abe2-c0c258ef4073",
35
+ "metadata": {},
36
+ "outputs": [],
37
+ "source": [
38
+ "X = iris.data[:, :1]\n",
39
+ "y = iris.target"
40
+ ]
41
+ },
42
+ {
43
+ "cell_type": "code",
44
+ "execution_count": 4,
45
+ "id": "c8e84e37-e034-4dcb-af3d-03d9cae87a92",
46
+ "metadata": {},
47
+ "outputs": [],
48
+ "source": [
49
+ "X = np.array([tuple(i.tolist()) for i in X], dtype=[(\"col1\", float)])\n",
50
+ "y = np.array([i for i in y], dtype=[(\"col3\", y.dtype)])"
51
+ ]
52
+ },
53
+ {
54
+ "cell_type": "code",
55
+ "execution_count": 5,
56
+ "id": "fab25223-225c-430b-a58d-368466d7fe02",
57
+ "metadata": {},
58
+ "outputs": [],
59
+ "source": [
60
+ "X = X.reshape(-1, 1)"
61
+ ]
62
+ },
63
+ {
64
+ "cell_type": "code",
65
+ "execution_count": 6,
66
+ "id": "50359601-4b0d-4a94-a1c8-44a833b8f4e5",
67
+ "metadata": {
68
+ "tags": []
69
+ },
70
+ "outputs": [],
71
+ "source": [
72
+ "x_train, x_test, y_train, y_test = train_test_split(X, y, test_size=0.1, random_state=42)"
73
+ ]
74
+ },
75
+ {
76
+ "cell_type": "code",
77
+ "execution_count": 7,
78
+ "id": "17fc4619-c5c0-4beb-81df-81617b1c7a56",
79
+ "metadata": {},
80
+ "outputs": [
81
+ {
82
+ "data": {
83
+ "text/plain": [
84
+ "(array([[(6.3,)],\n",
85
+ " [(6.5,)],\n",
86
+ " [(5.6,)],\n",
87
+ " [(5.7,)],\n",
88
+ " [(6.4,)]], dtype=[('col1', '<f8')]),\n",
89
+ " array([(1,), (2,), (1,), (1,), (2,)], dtype=[('col3', '<i8')]))"
90
+ ]
91
+ },
92
+ "execution_count": 7,
93
+ "metadata": {},
94
+ "output_type": "execute_result"
95
+ }
96
+ ],
97
+ "source": [
98
+ "x_train[:5], y_train[:5]"
99
+ ]
100
+ },
101
+ {
102
+ "cell_type": "code",
103
+ "execution_count": 8,
104
+ "id": "510d7a07-7746-4305-96d6-a74bc5a7f144",
105
+ "metadata": {},
106
+ "outputs": [],
107
+ "source": [
108
+ "model = LinearRegression()"
109
+ ]
110
+ },
111
+ {
112
+ "cell_type": "code",
113
+ "execution_count": 9,
114
+ "id": "733f81f4-fc25-41a2-8c7d-e6e4abd70143",
115
+ "metadata": {},
116
+ "outputs": [
117
+ {
118
+ "data": {
119
+ "text/plain": [
120
+ "LinearRegression()"
121
+ ]
122
+ },
123
+ "execution_count": 9,
124
+ "metadata": {},
125
+ "output_type": "execute_result"
126
+ }
127
+ ],
128
+ "source": [
129
+ "model.fit(x_train, y_train)"
130
+ ]
131
+ },
132
+ {
133
+ "cell_type": "code",
134
+ "execution_count": 10,
135
+ "id": "267ed05e-7285-4873-ae8c-2396f986bf31",
136
+ "metadata": {},
137
+ "outputs": [],
138
+ "source": [
139
+ "y_pred = model.predict(x_test)"
140
+ ]
141
+ },
142
+ {
143
+ "cell_type": "code",
144
+ "execution_count": 11,
145
+ "id": "0dd6f9d6-89d4-461f-9110-601d44126512",
146
+ "metadata": {},
147
+ "outputs": [
148
+ {
149
+ "data": {
150
+ "text/plain": [
151
+ "array([1.22816565, 0.91925051, 2.46382623, 1.15093687, 1.76876716,\n",
152
+ " 0.68756415, 0.84202172, 1.84599594, 1.30539444, 0.99647929,\n",
153
+ " 1.5370808 , 0.22419143, 0.76479293, 0.30142022, 0.45587779])"
154
+ ]
155
+ },
156
+ "execution_count": 11,
157
+ "metadata": {},
158
+ "output_type": "execute_result"
159
+ }
160
+ ],
161
+ "source": [
162
+ "y_pred"
163
+ ]
164
+ },
165
+ {
166
+ "cell_type": "code",
167
+ "execution_count": 12,
168
+ "id": "6a65cd71-b625-4f31-894d-a4d0403fd1b1",
169
+ "metadata": {},
170
+ "outputs": [
171
+ {
172
+ "data": {
173
+ "text/plain": [
174
+ "array([1., 1., 2., 1., 2., 1., 1., 2., 1., 1., 2., 0., 1., 0., 0.])"
175
+ ]
176
+ },
177
+ "execution_count": 12,
178
+ "metadata": {},
179
+ "output_type": "execute_result"
180
+ }
181
+ ],
182
+ "source": [
183
+ "y_pred = np.round(y_pred)\n",
184
+ "y_pred"
185
+ ]
186
+ },
187
+ {
188
+ "cell_type": "code",
189
+ "execution_count": 13,
190
+ "id": "ef5d8327-7ee8-43a6-b4f9-0785e8467d23",
191
+ "metadata": {},
192
+ "outputs": [
193
+ {
194
+ "data": {
195
+ "text/plain": [
196
+ "array([(1,), (0,), (2,), (1,), (1,), (0,), (1,), (2,), (1,), (1,), (2,),\n",
197
+ " (0,), (0,), (0,), (0,)], dtype=[('col3', '<i8')])"
198
+ ]
199
+ },
200
+ "execution_count": 13,
201
+ "metadata": {},
202
+ "output_type": "execute_result"
203
+ }
204
+ ],
205
+ "source": [
206
+ "y_test"
207
+ ]
208
+ },
209
+ {
210
+ "cell_type": "code",
211
+ "execution_count": 14,
212
+ "id": "d01167c5-d4d1-4a67-86df-cc4f88abe421",
213
+ "metadata": {},
214
+ "outputs": [],
215
+ "source": [
216
+ "y_test = np.array([i[0] for i in y_test])"
217
+ ]
218
+ },
219
+ {
220
+ "cell_type": "code",
221
+ "execution_count": 15,
222
+ "id": "b28aa4ac-87ab-45a4-b5c8-e7b125895c25",
223
+ "metadata": {},
224
+ "outputs": [
225
+ {
226
+ "data": {
227
+ "text/plain": [
228
+ "0.7333333333333333"
229
+ ]
230
+ },
231
+ "execution_count": 15,
232
+ "metadata": {},
233
+ "output_type": "execute_result"
234
+ }
235
+ ],
236
+ "source": [
237
+ "accuracy_score(y_test, np.round(y_pred))"
238
+ ]
239
+ },
240
+ {
241
+ "cell_type": "code",
242
+ "execution_count": 16,
243
+ "id": "d5cf8629-f623-4a3e-9400-8d7f6215383e",
244
+ "metadata": {},
245
+ "outputs": [],
246
+ "source": [
247
+ "from joblib import dump, load"
248
+ ]
249
+ },
250
+ {
251
+ "cell_type": "code",
252
+ "execution_count": 17,
253
+ "id": "caa6d389-b358-4160-a342-215013c5b2d9",
254
+ "metadata": {},
255
+ "outputs": [
256
+ {
257
+ "data": {
258
+ "text/plain": [
259
+ "['structured_arr_model_1_dim.joblib']"
260
+ ]
261
+ },
262
+ "execution_count": 17,
263
+ "metadata": {},
264
+ "output_type": "execute_result"
265
+ }
266
+ ],
267
+ "source": [
268
+ "dump(model, \"structured_arr_model_1_dim.joblib\")"
269
+ ]
270
+ },
271
+ {
272
+ "cell_type": "code",
273
+ "execution_count": 18,
274
+ "id": "f0804a91-46d4-4cec-bd60-bb5f022443bf",
275
+ "metadata": {},
276
+ "outputs": [],
277
+ "source": [
278
+ "model = load(\"structured_arr_model_1_dim.joblib\")"
279
+ ]
280
+ },
281
+ {
282
+ "cell_type": "code",
283
+ "execution_count": 19,
284
+ "id": "07584f03-f1da-4014-a539-ca0e033a6356",
285
+ "metadata": {},
286
+ "outputs": [
287
+ {
288
+ "data": {
289
+ "text/plain": [
290
+ "array([1.22816565])"
291
+ ]
292
+ },
293
+ "execution_count": 19,
294
+ "metadata": {},
295
+ "output_type": "execute_result"
296
+ }
297
+ ],
298
+ "source": [
299
+ "model.predict(x_test[:1])"
300
+ ]
301
+ },
302
+ {
303
+ "cell_type": "code",
304
+ "execution_count": 20,
305
+ "id": "06cf5cbb-0a96-4501-8fa6-bfc680d8aa20",
306
+ "metadata": {},
307
+ "outputs": [],
308
+ "source": [
309
+ "import skops.hub_utils as hub_utils"
310
+ ]
311
+ },
312
+ {
313
+ "cell_type": "code",
314
+ "execution_count": 21,
315
+ "id": "f4349089-88c9-49d2-8b65-351cabb74fd8",
316
+ "metadata": {},
317
+ "outputs": [
318
+ {
319
+ "data": {
320
+ "text/plain": [
321
+ "array([[(6.1,)],\n",
322
+ " [(5.7,)],\n",
323
+ " [(7.7,)],\n",
324
+ " [(6. ,)],\n",
325
+ " [(6.8,)],\n",
326
+ " [(5.4,)],\n",
327
+ " [(5.6,)],\n",
328
+ " [(6.9,)],\n",
329
+ " [(6.2,)],\n",
330
+ " [(5.8,)],\n",
331
+ " [(6.5,)],\n",
332
+ " [(4.8,)],\n",
333
+ " [(5.5,)],\n",
334
+ " [(4.9,)],\n",
335
+ " [(5.1,)]], dtype=[('col1', '<f8')])"
336
+ ]
337
+ },
338
+ "execution_count": 21,
339
+ "metadata": {},
340
+ "output_type": "execute_result"
341
+ }
342
+ ],
343
+ "source": [
344
+ "x_test"
345
+ ]
346
+ },
347
+ {
348
+ "cell_type": "code",
349
+ "execution_count": 22,
350
+ "id": "a4294f1f-5eeb-460f-a872-ba487a229093",
351
+ "metadata": {},
352
+ "outputs": [],
353
+ "source": [
354
+ "!rm -rf /Users/macbookpro/MyProjects/dev/dst\n",
355
+ "!mkdir /Users/macbookpro/MyProjects/dev/dst"
356
+ ]
357
+ },
358
+ {
359
+ "cell_type": "code",
360
+ "execution_count": 23,
361
+ "id": "41a49678-1a01-439d-8f92-29f1884e5f79",
362
+ "metadata": {},
363
+ "outputs": [],
364
+ "source": [
365
+ "hub_utils.init(\n",
366
+ " model=\"/Users/macbookpro/MyProjects/dev/structured_arr_model_1_dim.joblib\",\n",
367
+ " requirements=[\"scikit-learn\", \"numpy\"],\n",
368
+ " dst=\"/Users/macbookpro/MyProjects/dev/dst\",\n",
369
+ " task=\"tabular-classification\",\n",
370
+ " data=x_train[:3]\n",
371
+ ")"
372
+ ]
373
+ },
374
+ {
375
+ "cell_type": "code",
376
+ "execution_count": 24,
377
+ "id": "fe1a1620-66e3-4543-a506-1195ac39831e",
378
+ "metadata": {},
379
+ "outputs": [],
380
+ "source": [
381
+ "from skops.card import metadata_from_config"
382
+ ]
383
+ },
384
+ {
385
+ "cell_type": "code",
386
+ "execution_count": 25,
387
+ "id": "9e0a6d81-e1c4-4a75-b510-772eb44e924d",
388
+ "metadata": {},
389
+ "outputs": [
390
+ {
391
+ "data": {
392
+ "text/plain": [
393
+ "library_name: sklearn\n",
394
+ "tags:\n",
395
+ "- sklearn\n",
396
+ "- skops\n",
397
+ "- tabular-classification\n",
398
+ "widget:\n",
399
+ " structuredData:\n",
400
+ " x0:\n",
401
+ " - - 6.3\n",
402
+ " - - 6.5\n",
403
+ " - - 5.6"
404
+ ]
405
+ },
406
+ "execution_count": 25,
407
+ "metadata": {},
408
+ "output_type": "execute_result"
409
+ }
410
+ ],
411
+ "source": [
412
+ "metadata_from_config(\"/Users/macbookpro/MyProjects/dev/dst/config.json\")"
413
+ ]
414
+ },
415
+ {
416
+ "cell_type": "code",
417
+ "execution_count": null,
418
+ "id": "412fc8e8-ab28-44bf-88be-6cac61c168f1",
419
+ "metadata": {},
420
+ "outputs": [],
421
+ "source": []
422
+ }
423
+ ],
424
+ "metadata": {
425
+ "kernelspec": {
426
+ "display_name": "Python 3 (ipykernel)",
427
+ "language": "python",
428
+ "name": "python3"
429
+ },
430
+ "language_info": {
431
+ "codemirror_mode": {
432
+ "name": "ipython",
433
+ "version": 3
434
+ },
435
+ "file_extension": ".py",
436
+ "mimetype": "text/x-python",
437
+ "name": "python",
438
+ "nbconvert_exporter": "python",
439
+ "pygments_lexer": "ipython3",
440
+ "version": "3.9.15"
441
+ }
442
+ },
443
+ "nbformat": 4,
444
+ "nbformat_minor": 5
445
+ }
structured_arr_model_1_dim.joblib ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e5bb34d8b7d267d3f3bd6bcf1a108eb0d2ffdf45e31b773627c776bd08853095
3
+ size 552