|
1 | 1 | { |
2 | 2 | "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "markdown", |
| 5 | + "metadata": {}, |
| 6 | + "source": [ |
| 7 | + "# Feature distributions from income classifier demo\n", |
| 8 | + "\n", |
| 9 | + "You'll need to have setup the pipeline for the income classifier and done some requests." |
| 10 | + ] |
| 11 | + }, |
| 12 | + { |
| 13 | + "cell_type": "markdown", |
| 14 | + "metadata": {}, |
| 15 | + "source": [ |
| 16 | + "## API Configuration" |
| 17 | + ] |
| 18 | + }, |
3 | 19 | { |
4 | 20 | "cell_type": "code", |
5 | 21 | "execution_count": 3, |
6 | 22 | "metadata": {}, |
7 | 23 | "outputs": [], |
8 | 24 | "source": [ |
9 | 25 | "from seldon_deploy_sdk.rest import ApiException\n", |
10 | | - "\n", |
11 | | - "from seldon_deploy_sdk import MonitorApi,DeploymentFeatureData, Configuration, ApiClient\n", |
| 26 | + "from seldon_deploy_sdk import (\n", |
| 27 | + " MonitorApi,\n", |
| 28 | + " DeploymentFeatureData,\n", |
| 29 | + " Configuration,\n", |
| 30 | + " ApiClient,\n", |
| 31 | + ")\n", |
12 | 32 | "from seldon_deploy_sdk.auth import OIDCAuthenticator" |
13 | 33 | ] |
14 | 34 | }, |
15 | 35 | { |
16 | 36 | "cell_type": "code", |
17 | 37 | "execution_count": 4, |
18 | 38 | "metadata": {}, |
19 | | - "outputs": [ |
20 | | - { |
21 | | - "name": "stderr", |
22 | | - "output_type": "stream", |
23 | | - "text": [ |
24 | | - "DEPRECATED!! Future versions of seldon_deploy_sdk will ignore the access_token field. Use the id_token field instead.\n" |
25 | | - ] |
26 | | - } |
27 | | - ], |
| 39 | + "outputs": [], |
28 | 40 | "source": [ |
29 | | - "INGRESS = \"http://localhost:8000\"\n", |
| 41 | + "# For local testing use\n", |
| 42 | + "INGRESS = \"http://localhost:8080\"\n", |
30 | 43 | "\n", |
| 44 | + "# For production usecase set this to your ingress\n", |
| 45 | + "# for example if your SD URL is http://xxx.yyy.zzz.xyz/seldon-deploy/api/v1alpha1 set\n", |
| 46 | + "# INGRESS = \"http://xxx.yyy.zzz.xyz\"" |
| 47 | + ] |
| 48 | + }, |
| 49 | + { |
| 50 | + "cell_type": "code", |
| 51 | + "execution_count": null, |
| 52 | + "metadata": {}, |
| 53 | + "outputs": [], |
| 54 | + "source": [ |
31 | 55 | "config = Configuration()\n", |
32 | | - "config.host = f\"{INGRESS}/seldon-deploy/api/v1alpha1\"\n", |
33 | | - "config.verify_ssl = False\n", |
| 56 | + "config.host = f\"{INGRESS}/seldon-deploy/api/v1alpha1\"" |
| 57 | + ] |
| 58 | + }, |
| 59 | + { |
| 60 | + "cell_type": "code", |
| 61 | + "execution_count": 7, |
| 62 | + "metadata": {}, |
| 63 | + "outputs": [], |
| 64 | + "source": [ |
| 65 | + "# auth if needed\n", |
34 | 66 | "config.oidc_server = f\"{INGRESS}/auth/realms/deploy-realm\"\n", |
35 | 67 | "config.oidc_client_id = \"sd-api\"\n", |
36 | 68 | "config.oidc_client_secret = \"sd-api-secret\"\n", |
37 | 69 | "config.auth_method = \"client_credentials\"\n", |
| 70 | + "\n", |
| 71 | + "# Alternativey set instead of the \"client_credentials\" flow\n", |
| 72 | + "# config.username = \"admin@seldon.io\"\n", |
| 73 | + "# config.password = \"12341234\"\n", |
| 74 | + "# config.auth_method = \"password\"\n", |
| 75 | + "\n", |
38 | 76 | "auth = OIDCAuthenticator(config)\n", |
39 | | - "config.access_token = auth.authenticate()\n" |
| 77 | + "config.id_token = auth.authenticate()" |
40 | 78 | ] |
41 | 79 | }, |
42 | 80 | { |
|
49 | 87 | "api_instance = MonitorApi(api_client)" |
50 | 88 | ] |
51 | 89 | }, |
| 90 | + { |
| 91 | + "cell_type": "markdown", |
| 92 | + "metadata": {}, |
| 93 | + "source": [ |
| 94 | + "## Request feature distributions" |
| 95 | + ] |
| 96 | + }, |
52 | 97 | { |
53 | 98 | "cell_type": "code", |
54 | 99 | "execution_count": 6, |
55 | 100 | "metadata": {}, |
56 | 101 | "outputs": [], |
57 | 102 | "source": [ |
58 | | - "deployment_name=\"income-classifier\"\n", |
59 | | - "deployment_namespace=\"seldon\"\n", |
| 103 | + "deployment_name = \"income-classifier\"\n", |
| 104 | + "deployment_namespace = \"seldon\"\n", |
60 | 105 | "feature_data = DeploymentFeatureData(\n", |
61 | 106 | " feature=\"Education\",\n", |
62 | 107 | " interaction=\"request\",\n", |
63 | 108 | " aggregate_over_time=True,\n", |
64 | 109 | " deployment_endpoint=\"default\",\n", |
65 | | - " deployment_node=\"income-classifier-container\"\n", |
| 110 | + " deployment_node=\"income-classifier-container\",\n", |
66 | 111 | ")\n", |
67 | 112 | "try:\n", |
68 | 113 | " # Get feature distributions\n", |
69 | | - " api_response = api_instance.seldon_deployment_feature_distributions(deployment_name,deployment_namespace,feature_data)\n", |
| 114 | + " api_response = api_instance.seldon_deployment_feature_distributions(\n", |
| 115 | + " deployment_name, deployment_namespace, feature_data\n", |
| 116 | + " )\n", |
70 | 117 | "except ApiException as e:\n", |
71 | 118 | " print(f\"Couldn't fetch distributions: {e}\")" |
72 | 119 | ] |
|
102 | 149 | ], |
103 | 150 | "source": [ |
104 | 151 | "import matplotlib.pyplot as plt\n", |
| 152 | + "\n", |
105 | 153 | "fig = plt.figure()\n", |
106 | | - "ax = fig.add_axes([0,0,1,1])\n", |
107 | | - "ax.bar(groups,counts)\n", |
| 154 | + "ax = fig.add_axes([0, 0, 1, 1])\n", |
| 155 | + "ax.bar(groups, counts)\n", |
108 | 156 | "plt.show()" |
109 | 157 | ] |
110 | 158 | } |
|
0 commit comments