-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add more documentation and notebooks (#106)
Showing
14 changed files
with
404 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
:root { | ||
|
||
/* Primary color shades */ | ||
--md-primary-fg-color: #21babe; | ||
--md-primary-fg-color--light: #21babe; | ||
--md-primary-fg-color--dark: #86e6e9; | ||
--md-primary-bg-color: hsla(0, 0%, 100%, 1); | ||
--md-primary-bg-color--light: hsla(0, 0%, 100%, 0.7); | ||
--md-typeset-a-color: #21babe; | ||
|
||
/* Accent color shades */ | ||
--md-accent-fg-color: #006493; | ||
--md-accent-fg-color--transparent: hsla(189, 100%, 37%, 0.1); | ||
--md-accent-bg-color: hsla(0, 0%, 100%, 1); | ||
--md-accent-bg-color--light: hsla(0, 0%, 100%, 0.7); | ||
} | ||
|
||
:root > * { | ||
|
||
/* Code block color shades */ | ||
--md-code-bg-color: hsla(0, 0%, 96%, 1); | ||
--md-code-fg-color: hsla(200, 18%, 26%, 1); | ||
|
||
/* Footer */ | ||
--md-footer-bg-color: #21babe; | ||
--md-footer-bg-color--dark: hsla(0, 0%, 0%, 0.32); | ||
--md-footer-fg-color: hsla(0, 0%, 100%, 1); | ||
--md-footer-fg-color--light: hsla(0, 0%, 100%, 0.7); | ||
--md-footer-fg-color--lighter: hsla(0, 0%, 100%, 0.3); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,10 +14,9 @@ model_monitor = wb.create_model_monitor( | |
name="test", | ||
status=MonitorStatus.active, | ||
metric=MonitorMetrics.accuracy, | ||
feature="feature1", | ||
lower_threshold=0.7, | ||
severity=AlertSeverity.high, | ||
email="[email protected]", | ||
email="[email protected]", | ||
lower_threshold=0.7 | ||
) | ||
``` | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,278 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"attachments": {}, | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# Usaging Whitebox SDK\n", | ||
"\n", | ||
"First of all we need to import the Whitebox class:" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from whitebox import Whitebox" | ||
] | ||
}, | ||
{ | ||
"attachments": {}, | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"Now we create an instance of the Whitebox class adding the host and API key as parameters:" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 2, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"wb = Whitebox(host=\"http://127.0.0.1:8000\", api_key=\"1073a9a03e5c6bf06b3f7a0c23d44ff923842a63dc75929ff0543705bbd3fa26\")" | ||
] | ||
}, | ||
{ | ||
"attachments": {}, | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"In order to start adding training datasets and inferences, you first need to create a model.\n", | ||
"\n", | ||
"Let's create a sample model. When the model is created successfully, the `Model` object that was added into the database is returned." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 3, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"{'id': '5dce48be-a16f-45dc-a878-d80b5b02a1f2',\n", | ||
" 'created_at': '2023-01-17T15:02:27.356199',\n", | ||
" 'updated_at': '2023-01-17T15:02:27.356199',\n", | ||
" 'name': 'Model 1',\n", | ||
" 'description': '',\n", | ||
" 'type': 'binary',\n", | ||
" 'features': {'additionalProp1': 'numerical',\n", | ||
" 'additionalProp2': 'numerical',\n", | ||
" 'target': 'numerical'},\n", | ||
" 'labels': {'additionalProp1': 0, 'additionalProp2': 1},\n", | ||
" 'prediction': 'y_prediction_multi',\n", | ||
" 'probability': 'proba'}" | ||
] | ||
}, | ||
"execution_count": 3, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"wb.create_model(name=\"Model 1\", type=\"binary\", features={'additionalProp1': 'numerical',\n", | ||
" 'additionalProp2': 'numerical',\n", | ||
" 'target': 'numerical'}, labels={'additionalProp1': 0, 'additionalProp2': 1}, prediction=\"y_prediction_multi\", probability=\"proba\")" | ||
] | ||
}, | ||
{ | ||
"attachments": {}, | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"In order to fetch a model from the database we'll need the `model_id`. If the `model_id` exists, a `Model` object will be returned. Otherwise you'll get nothing!" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 4, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"{'id': '5dce48be-a16f-45dc-a878-d80b5b02a1f2',\n", | ||
" 'created_at': '2023-01-17T15:02:27.356199',\n", | ||
" 'updated_at': '2023-01-17T15:02:27.356199',\n", | ||
" 'name': 'Model 1',\n", | ||
" 'description': '',\n", | ||
" 'type': 'binary',\n", | ||
" 'features': {'additionalProp1': 'numerical',\n", | ||
" 'additionalProp2': 'numerical',\n", | ||
" 'target': 'numerical'},\n", | ||
" 'labels': {'additionalProp1': 0, 'additionalProp2': 1},\n", | ||
" 'prediction': 'y_prediction_multi',\n", | ||
" 'probability': 'proba'}" | ||
] | ||
}, | ||
"execution_count": 4, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"wb.get_model(\"5dce48be-a16f-45dc-a878-d80b5b02a1f2\")" | ||
] | ||
}, | ||
{ | ||
"attachments": {}, | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"Once you have created a model you can start loading your data. Let's start with the training dataset!\n", | ||
"\n", | ||
"In our example we will create a pd.DataFrame from a .csv file. Of course you can use any method you like to create your pd.DataFrame as long as your non-processed and processed datasets have the same amount of rows (a.k.a. the same length) and there are more than one rows!\n", | ||
"\n", | ||
"If the training data is successfully saved, `True` will be returned, otherwise `False`." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 5, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"True" | ||
] | ||
}, | ||
"execution_count": 5, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"import pandas as pd\n", | ||
"df = pd.read_csv(\"src/analytics/data/testing/classification_test_data.csv\")\n", | ||
"\n", | ||
"wb.log_training_dataset(model_id=\"5dce48be-a16f-45dc-a878-d80b5b02a1f2\", processed=df, non_processed=df)" | ||
] | ||
}, | ||
{ | ||
"attachments": {}, | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"To load your inferences you have to follow the exact same procedure as with the training datasets. The only difference is that you need to provide a `pd.Series` with the timestamps and (optionally) a `pd.Series` with the actuals, whose indices should match the ones in the non-processed and processed `pd.DataFrames`.\n", | ||
"\n", | ||
"If the inferences are successfully saved, `True` will be returned, otherwise `False`." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 6, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"True" | ||
] | ||
}, | ||
"execution_count": 6, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"import pandas as pd\n", | ||
"from whitebox.tests.v1.mock_data import timestamps, mixed_actuals\n", | ||
"df = pd.read_csv(\"src/analytics/data/testing/classification_test_data.csv\")\n", | ||
"\n", | ||
"\n", | ||
"wb.log_inferences(model_id=\"5dce48be-a16f-45dc-a878-d80b5b02a1f2\", processed=df, non_processed=df, timestamps=timestamps, actuals=mixed_actuals)" | ||
] | ||
}, | ||
{ | ||
"attachments": {}, | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"You can create a monitor in whitebox so that alert are created automaticaly when some value is out of bounds:" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from whitebox import Whitebox\n", | ||
"\n", | ||
"wb = Whitebox(host=\"127.0.0.1:8000\", api_key=\"some_api_key\")\n", | ||
"\n", | ||
"model_monitor = wb.create_model_monitor(\n", | ||
" model_id=\"mock_model_id\",\n", | ||
" name=\"test\",\n", | ||
" status=\"active\",\n", | ||
" metric=\"accuracy\",\n", | ||
" severity=\"high\",\n", | ||
" email=\"jackie.chan@somemail.io\",\n", | ||
" lower_threshold=0.7\n", | ||
")" | ||
] | ||
}, | ||
{ | ||
"attachments": {}, | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"In order to delete a model you hae to provide the `model_id`.\n", | ||
"\n", | ||
"If the model is successfully deleted, `True` will be returned, otherwise `False`." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 7, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"True" | ||
] | ||
}, | ||
"execution_count": 7, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"wb.delete_model(\"5dce48be-a16f-45dc-a878-d80b5b02a1f2\")" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.10.8 | packaged by conda-forge | (main, Nov 22 2022, 08:25:29) [Clang 14.0.6 ]" | ||
}, | ||
"orig_nbformat": 4, | ||
"vscode": { | ||
"interpreter": { | ||
"hash": "32a5a47fe20cdfbd609287887f2e78a4d5f2f7afeda3da775d5794970f9a3f8e" | ||
} | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters