Skip to content

Commit 24d2a51

Browse files
gustavocidornelaswhoseoyster
authored andcommitted
Completes UNB-2565 - Add code to tutorial notebooks instead of suggesting copy / paste
1 parent caa608d commit 24d2a51

File tree

2 files changed

+175
-249
lines changed

2 files changed

+175
-249
lines changed

examples/tabular-classification/documentation-tutorial/tabular-tutorial-part-1.ipynb

Lines changed: 110 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
},
2222
{
2323
"cell_type": "code",
24-
"execution_count": 22,
24+
"execution_count": 1,
2525
"id": "56758c0a",
2626
"metadata": {},
2727
"outputs": [],
@@ -55,7 +55,7 @@
5555
},
5656
{
5757
"cell_type": "code",
58-
"execution_count": 1,
58+
"execution_count": 3,
5959
"id": "4f69dcb3",
6060
"metadata": {},
6161
"outputs": [],
@@ -80,7 +80,7 @@
8080
},
8181
{
8282
"cell_type": "code",
83-
"execution_count": 2,
83+
"execution_count": 4,
8484
"id": "2ed8bf11",
8585
"metadata": {},
8686
"outputs": [],
@@ -91,7 +91,7 @@
9191
},
9292
{
9393
"cell_type": "code",
94-
"execution_count": 3,
94+
"execution_count": 5,
9595
"id": "ac811397",
9696
"metadata": {},
9797
"outputs": [
@@ -245,7 +245,7 @@
245245
"4 0 "
246246
]
247247
},
248-
"execution_count": 3,
248+
"execution_count": 5,
249249
"metadata": {},
250250
"output_type": "execute_result"
251251
}
@@ -268,7 +268,7 @@
268268
},
269269
{
270270
"cell_type": "code",
271-
"execution_count": 4,
271+
"execution_count": 6,
272272
"id": "0ccaafae",
273273
"metadata": {},
274274
"outputs": [],
@@ -292,7 +292,7 @@
292292
},
293293
{
294294
"cell_type": "code",
295-
"execution_count": 5,
295+
"execution_count": 7,
296296
"id": "29e71531",
297297
"metadata": {},
298298
"outputs": [],
@@ -311,7 +311,7 @@
311311
},
312312
{
313313
"cell_type": "code",
314-
"execution_count": 6,
314+
"execution_count": 8,
315315
"id": "3680efe3",
316316
"metadata": {},
317317
"outputs": [],
@@ -330,7 +330,7 @@
330330
},
331331
{
332332
"cell_type": "code",
333-
"execution_count": 7,
333+
"execution_count": 9,
334334
"id": "0fcfef49",
335335
"metadata": {},
336336
"outputs": [],
@@ -341,7 +341,7 @@
341341
},
342342
{
343343
"cell_type": "code",
344-
"execution_count": 8,
344+
"execution_count": 10,
345345
"id": "53491eab",
346346
"metadata": {},
347347
"outputs": [
@@ -374,7 +374,7 @@
374374
},
375375
{
376376
"cell_type": "code",
377-
"execution_count": 9,
377+
"execution_count": 11,
378378
"id": "a981bc4b",
379379
"metadata": {},
380380
"outputs": [
@@ -384,7 +384,7 @@
384384
"GradientBoostingClassifier(random_state=42)"
385385
]
386386
},
387-
"execution_count": 9,
387+
"execution_count": 11,
388388
"metadata": {},
389389
"output_type": "execute_result"
390390
}
@@ -396,7 +396,7 @@
396396
},
397397
{
398398
"cell_type": "code",
399-
"execution_count": 11,
399+
"execution_count": 12,
400400
"id": "ba829dcd",
401401
"metadata": {},
402402
"outputs": [
@@ -425,16 +425,16 @@
425425
"id": "eb702d1f",
426426
"metadata": {},
427427
"source": [
428-
"## 5. Unbox part -- have fun creating the next few cells!\n",
428+
"## 5. Unbox part!\n",
429429
"\n",
430430
"Now it's up to you! We will just compute a few important variables and concatenate the x and y, because Unbox expects a single dataframe with features and labels for the upload. \n",
431431
"\n",
432-
"Head back to the tutorial to see how you need to fill out the next few cells."
432+
"Head back to the tutorial for an explanation of next few cells."
433433
]
434434
},
435435
{
436436
"cell_type": "code",
437-
"execution_count": 12,
437+
"execution_count": 13,
438438
"id": "b1682ee4",
439439
"metadata": {},
440440
"outputs": [],
@@ -446,7 +446,7 @@
446446
},
447447
{
448448
"cell_type": "code",
449-
"execution_count": 13,
449+
"execution_count": 14,
450450
"id": "d480f0c3",
451451
"metadata": {},
452452
"outputs": [],
@@ -461,6 +461,99 @@
461461
"id": "65964db9",
462462
"metadata": {},
463463
"outputs": [],
464+
"source": [
465+
"# instantiating the client\n",
466+
"import unboxapi\n",
467+
"\n",
468+
"client = unboxapi.UnboxClient('YOUR_API_KEY_HERE')"
469+
]
470+
},
471+
{
472+
"cell_type": "code",
473+
"execution_count": null,
474+
"id": "2dee6250",
475+
"metadata": {},
476+
"outputs": [],
477+
"source": [
478+
"# creating the project\n",
479+
"from unboxapi.tasks import TaskType\n",
480+
"\n",
481+
"project = client.create_project(name=\"Churn prediction\",\n",
482+
" task_type=TaskType.TabularClassification,\n",
483+
" description=\"Evaluation of ML approaches to predict churn\")"
484+
]
485+
},
486+
{
487+
"cell_type": "code",
488+
"execution_count": null,
489+
"id": "d0c680e8",
490+
"metadata": {},
491+
"outputs": [],
492+
"source": [
493+
"# uploading the dataset to the project\n",
494+
"dataset = project.add_dataframe(\n",
495+
" df=validation_set, \n",
496+
" commit_message='churn validation set for October',\n",
497+
" class_names=class_names, \n",
498+
" label_column_name='Exited', \n",
499+
" feature_names=feature_names, \n",
500+
" categorical_feature_names=categorical_feature_names, \n",
501+
")"
502+
]
503+
},
504+
{
505+
"cell_type": "code",
506+
"execution_count": null,
507+
"id": "5b55095c",
508+
"metadata": {},
509+
"outputs": [],
510+
"source": [
511+
"# defining the model's predict probability function\n",
512+
"def predict_proba(model, input_features: np.ndarray, col_names: list, one_hot_encoder, encoders):\n",
513+
" # Pre-processing the categorical features\n",
514+
" df = pd.DataFrame(input_features, columns=col_names)\n",
515+
" encoded_df = one_hot_encoder(df, encoders)\n",
516+
" \n",
517+
" # Getting the model's predictions\n",
518+
" preds = model.predict_proba(encoded_df.to_numpy())\n",
519+
" \n",
520+
" return preds"
521+
]
522+
},
523+
{
524+
"cell_type": "code",
525+
"execution_count": null,
526+
"id": "d22d5cef",
527+
"metadata": {},
528+
"outputs": [],
529+
"source": [
530+
"# uploading the model to the project\n",
531+
"from unboxapi.models import ModelType\n",
532+
"\n",
533+
"model = project.add_model(\n",
534+
" function=predict_proba, \n",
535+
" model=sklearn_model,\n",
536+
" model_type=ModelType.sklearn,\n",
537+
" class_names=class_names,\n",
538+
" name='Churn Classifier',\n",
539+
" commit_message='this is my churn classification model',\n",
540+
" feature_names=feature_names,\n",
541+
" train_sample_df=training_set[:3000],\n",
542+
" train_sample_label_column_name='Exited',\n",
543+
" categorical_feature_names=categorical_feature_names,\n",
544+
" requirements_txt_file='requirements.txt',\n",
545+
" col_names=feature_names,\n",
546+
" one_hot_encoder=data_encode_one_hot,\n",
547+
" encoders=encoders,\n",
548+
")"
549+
]
550+
},
551+
{
552+
"cell_type": "code",
553+
"execution_count": null,
554+
"id": "c9a29256",
555+
"metadata": {},
556+
"outputs": [],
464557
"source": []
465558
}
466559
],

0 commit comments

Comments
 (0)