diff --git a/configuration.ipynb b/configuration.ipynb index f55db70a4..7dd58e44f 100644 --- a/configuration.ipynb +++ b/configuration.ipynb @@ -103,7 +103,7 @@ "source": [ "import azureml.core\n", "\n", - "print(\"This notebook was created using version 1.28.0 of the Azure ML SDK\")\n", + "print(\"This notebook was created using version 1.29.0 of the Azure ML SDK\")\n", "print(\"You are currently using version\", azureml.core.VERSION, \"of the Azure ML SDK\")" ] }, diff --git a/contrib/fairness/fairlearn-azureml-mitigation.ipynb b/contrib/fairness/fairlearn-azureml-mitigation.ipynb index 8e1de72cb..a3b8ff742 100644 --- a/contrib/fairness/fairlearn-azureml-mitigation.ipynb +++ b/contrib/fairness/fairlearn-azureml-mitigation.ipynb @@ -46,9 +46,10 @@ "Please see the [configuration notebook](../../configuration.ipynb) for information about creating one, if required.\n", "This notebook also requires the following packages:\n", "* `azureml-contrib-fairness`\n", - "* `fairlearn==0.4.6` (v0.5.0 will work with minor modifications)\n", + "* `fairlearn>=0.6.2` (pre-v0.5.0 will work with minor modifications)\n", "* `joblib`\n", "* `liac-arff`\n", + "* `raiwidgets==0.4.0`\n", "\n", "Fairlearn relies on features introduced in v0.22.1 of `scikit-learn`. If you have an older version already installed, please uncomment and run the following cell:" ] @@ -85,7 +86,7 @@ "outputs": [], "source": [ "from fairlearn.reductions import GridSearch, DemographicParity, ErrorRate\n", - "from fairlearn.widget import FairlearnDashboard\n", + "from raiwidgets import FairnessDashboard\n", "\n", "from sklearn.compose import ColumnTransformer\n", "from sklearn.impute import SimpleImputer\n", @@ -256,9 +257,9 @@ "metadata": {}, "outputs": [], "source": [ - "FairlearnDashboard(sensitive_features=A_test, sensitive_feature_names=['Sex', 'Race'],\n", - " y_true=y_test,\n", - " y_pred={\"unmitigated\": unmitigated_predictor.predict(X_test)})" + "FairnessDashboard(sensitive_features=A_test,\n", + " y_true=y_test,\n", + " y_pred={\"unmitigated\": unmitigated_predictor.predict(X_test)})" ] }, { @@ -311,8 +312,8 @@ "sweep.fit(X_train, y_train,\n", " sensitive_features=A_train.sex)\n", "\n", - "# For Fairlearn v0.5.0, need sweep.predictors_\n", - "predictors = sweep._predictors" + "# For Fairlearn pre-v0.5.0, need sweep._predictors\n", + "predictors = sweep.predictors_" ] }, { @@ -329,16 +330,14 @@ "outputs": [], "source": [ "errors, disparities = [], []\n", - "for m in predictors:\n", - " classifier = lambda X: m.predict(X)\n", - " \n", + "for predictor in predictors:\n", " error = ErrorRate()\n", " error.load_data(X_train, pd.Series(y_train), sensitive_features=A_train.sex)\n", " disparity = DemographicParity()\n", " disparity.load_data(X_train, pd.Series(y_train), sensitive_features=A_train.sex)\n", " \n", - " errors.append(error.gamma(classifier)[0])\n", - " disparities.append(disparity.gamma(classifier).max())\n", + " errors.append(error.gamma(predictor.predict)[0])\n", + " disparities.append(disparity.gamma(predictor.predict).max())\n", " \n", "all_results = pd.DataFrame( {\"predictor\": predictors, \"error\": errors, \"disparity\": disparities})\n", "\n", @@ -387,10 +386,9 @@ "metadata": {}, "outputs": [], "source": [ - "FairlearnDashboard(sensitive_features=A_test, \n", - " sensitive_feature_names=['Sex', 'Race'],\n", - " y_true=y_test.tolist(),\n", - " y_pred=predictions_dominant)" + "FairnessDashboard(sensitive_features=A_test, \n", + " y_true=y_test.tolist(),\n", + " y_pred=predictions_dominant)" ] }, { @@ -409,7 +407,7 @@ "\n", "## Uploading a Fairness Dashboard to Azure\n", "\n", - "Uploading a fairness dashboard to Azure is a two stage process. The `FairlearnDashboard` invoked in the previous section relies on the underlying Python kernel to compute metrics on demand. This is obviously not available when the fairness dashboard is rendered in AzureML Studio. By default, the dashboard in Azure Machine Learning Studio also requires the models to be registered. The required stages are therefore:\n", + "Uploading a fairness dashboard to Azure is a two stage process. The `FairnessDashboard` invoked in the previous section relies on the underlying Python kernel to compute metrics on demand. This is obviously not available when the fairness dashboard is rendered in AzureML Studio. By default, the dashboard in Azure Machine Learning Studio also requires the models to be registered. The required stages are therefore:\n", "1. Register the dominant models\n", "1. Precompute all the required metrics\n", "1. Upload to Azure\n", diff --git a/contrib/fairness/fairlearn-azureml-mitigation.yml b/contrib/fairness/fairlearn-azureml-mitigation.yml index 384ad5d94..79f0f63e1 100644 --- a/contrib/fairness/fairlearn-azureml-mitigation.yml +++ b/contrib/fairness/fairlearn-azureml-mitigation.yml @@ -3,6 +3,7 @@ dependencies: - pip: - azureml-sdk - azureml-contrib-fairness - - fairlearn==0.4.6 + - fairlearn>=0.6.2 - joblib - liac-arff + - raiwidgets==0.4.0 diff --git a/contrib/fairness/fairness_nb_utils.py b/contrib/fairness/fairness_nb_utils.py index 69e74f07f..a300ac097 100644 --- a/contrib/fairness/fairness_nb_utils.py +++ b/contrib/fairness/fairness_nb_utils.py @@ -21,7 +21,7 @@ def fetch_openml_with_retries(data_id, max_retries=4, retry_delay=60): print("Download attempt {0} of {1}".format(i + 1, max_retries)) data = fetch_openml(data_id=data_id, as_frame=True) break - except Exception as e: + except Exception as e: # noqa: B902 print("Download attempt failed with exception:") print(e) if i + 1 != max_retries: @@ -47,7 +47,7 @@ def fetch_openml_with_retries(data_id, max_retries=4, retry_delay=60): def fetch_census_dataset(): - """Fetch the Adult Census Dataset + """Fetch the Adult Census Dataset. This uses a particular URL for the Adult Census dataset. The code is a simplified version of fetch_openml() in sklearn. @@ -63,17 +63,35 @@ def fetch_census_dataset(): filename = "1595261.gz" data_url = "https://rainotebookscdn.blob.core.windows.net/datasets/" - urlretrieve(data_url + filename, filename) - http_stream = gzip.GzipFile(filename=filename, mode='rb') - - with closing(http_stream): - def _stream_generator(response): - for line in response: - yield line.decode('utf-8') - - stream = _stream_generator(http_stream) - data = arff.load(stream) + remaining_attempts = 5 + sleep_duration = 10 + while remaining_attempts > 0: + try: + urlretrieve(data_url + filename, filename) + + http_stream = gzip.GzipFile(filename=filename, mode='rb') + + with closing(http_stream): + def _stream_generator(response): + for line in response: + yield line.decode('utf-8') + + stream = _stream_generator(http_stream) + data = arff.load(stream) + except Exception as exc: # noqa: B902 + remaining_attempts -= 1 + print("Error downloading dataset from {} ({} attempt(s) remaining)" + .format(data_url, remaining_attempts)) + print(exc) + time.sleep(sleep_duration) + sleep_duration *= 2 + continue + else: + # dataset successfully downloaded + break + else: + raise Exception("Could not retrieve dataset from {}.".format(data_url)) attributes = OrderedDict(data['attributes']) arff_columns = list(attributes) diff --git a/contrib/fairness/upload-fairness-dashboard.ipynb b/contrib/fairness/upload-fairness-dashboard.ipynb index 8880f3c98..a30bbaf71 100644 --- a/contrib/fairness/upload-fairness-dashboard.ipynb +++ b/contrib/fairness/upload-fairness-dashboard.ipynb @@ -30,7 +30,7 @@ "1. [Training Models](#TrainingModels)\n", "1. [Logging in to AzureML](#LoginAzureML)\n", "1. [Registering the Models](#RegisterModels)\n", - "1. [Using the Fairlearn Dashboard](#LocalDashboard)\n", + "1. [Using the Fairness Dashboard](#LocalDashboard)\n", "1. [Uploading a Fairness Dashboard to Azure](#AzureUpload)\n", " 1. Computing Fairness Metrics\n", " 1. Uploading to Azure\n", @@ -48,9 +48,10 @@ "Please see the [configuration notebook](../../configuration.ipynb) for information about creating one, if required.\n", "This notebook also requires the following packages:\n", "* `azureml-contrib-fairness`\n", - "* `fairlearn==0.4.6` (should also work with v0.5.0)\n", + "* `fairlearn>=0.6.2` (also works for pre-v0.5.0 with slight modifications)\n", "* `joblib`\n", "* `liac-arff`\n", + "* `raiwidgets==0.4.0`\n", "\n", "Fairlearn relies on features introduced in v0.22.1 of `scikit-learn`. If you have an older version already installed, please uncomment and run the following cell:" ] @@ -388,12 +389,11 @@ "metadata": {}, "outputs": [], "source": [ - "from fairlearn.widget import FairlearnDashboard\n", + "from raiwidgets import FairnessDashboard\n", "\n", - "FairlearnDashboard(sensitive_features=A_test, \n", - " sensitive_feature_names=['Sex', 'Race'],\n", - " y_true=y_test.tolist(),\n", - " y_pred=ys_pred)" + "FairnessDashboard(sensitive_features=A_test, \n", + " y_true=y_test.tolist(),\n", + " y_pred=ys_pred)" ] }, { @@ -403,7 +403,7 @@ "\n", "## Uploading a Fairness Dashboard to Azure\n", "\n", - "Uploading a fairness dashboard to Azure is a two stage process. The `FairlearnDashboard` invoked in the previous section relies on the underlying Python kernel to compute metrics on demand. This is obviously not available when the fairness dashboard is rendered in AzureML Studio. The required stages are therefore:\n", + "Uploading a fairness dashboard to Azure is a two stage process. The `FairnessDashboard` invoked in the previous section relies on the underlying Python kernel to compute metrics on demand. This is obviously not available when the fairness dashboard is rendered in AzureML Studio. The required stages are therefore:\n", "1. Precompute all the required metrics\n", "1. Upload to Azure\n", "\n", diff --git a/contrib/fairness/upload-fairness-dashboard.yml b/contrib/fairness/upload-fairness-dashboard.yml index 196296e4b..30bab29f7 100644 --- a/contrib/fairness/upload-fairness-dashboard.yml +++ b/contrib/fairness/upload-fairness-dashboard.yml @@ -3,6 +3,7 @@ dependencies: - pip: - azureml-sdk - azureml-contrib-fairness - - fairlearn==0.4.6 + - fairlearn>=0.6.2 - joblib - liac-arff + - raiwidgets==0.4.0 diff --git a/how-to-use-azureml/automated-machine-learning/automl_env.yml b/how-to-use-azureml/automated-machine-learning/automl_env.yml index d4fdbd814..185e35aeb 100644 --- a/how-to-use-azureml/automated-machine-learning/automl_env.yml +++ b/how-to-use-azureml/automated-machine-learning/automl_env.yml @@ -21,8 +21,8 @@ dependencies: - pip: # Required packages for AzureML execution, history, and data preparation. - - azureml-widgets~=1.28.0 + - azureml-widgets~=1.29.0 - pytorch-transformers==1.0.0 - spacy==2.1.8 - https://aka.ms/automl-resources/packages/en_core_web_sm-2.1.0.tar.gz - - -r https://automlresources-prod.azureedge.net/validated-requirements/1.28.0/validated_win32_requirements.txt [--no-deps] + - -r https://automlresources-prod.azureedge.net/validated-requirements/1.29.0/validated_win32_requirements.txt [--no-deps] diff --git a/how-to-use-azureml/automated-machine-learning/automl_env_linux.yml b/how-to-use-azureml/automated-machine-learning/automl_env_linux.yml index a1393cfbc..499519ac1 100644 --- a/how-to-use-azureml/automated-machine-learning/automl_env_linux.yml +++ b/how-to-use-azureml/automated-machine-learning/automl_env_linux.yml @@ -21,8 +21,8 @@ dependencies: - pip: # Required packages for AzureML execution, history, and data preparation. - - azureml-widgets~=1.28.0 + - azureml-widgets~=1.29.0 - pytorch-transformers==1.0.0 - spacy==2.1.8 - https://aka.ms/automl-resources/packages/en_core_web_sm-2.1.0.tar.gz - - -r https://automlresources-prod.azureedge.net/validated-requirements/1.28.0/validated_linux_requirements.txt [--no-deps] + - -r https://automlresources-prod.azureedge.net/validated-requirements/1.29.0/validated_linux_requirements.txt [--no-deps] diff --git a/how-to-use-azureml/automated-machine-learning/automl_env_mac.yml b/how-to-use-azureml/automated-machine-learning/automl_env_mac.yml index 42c4d6a4c..999d6ebc3 100644 --- a/how-to-use-azureml/automated-machine-learning/automl_env_mac.yml +++ b/how-to-use-azureml/automated-machine-learning/automl_env_mac.yml @@ -22,8 +22,8 @@ dependencies: - pip: # Required packages for AzureML execution, history, and data preparation. - - azureml-widgets~=1.28.0 + - azureml-widgets~=1.29.0 - pytorch-transformers==1.0.0 - spacy==2.1.8 - https://aka.ms/automl-resources/packages/en_core_web_sm-2.1.0.tar.gz - - -r https://automlresources-prod.azureedge.net/validated-requirements/1.28.0/validated_darwin_requirements.txt [--no-deps] + - -r https://automlresources-prod.azureedge.net/validated-requirements/1.29.0/validated_darwin_requirements.txt [--no-deps] diff --git a/how-to-use-azureml/automated-machine-learning/classification-bank-marketing-all-features/auto-ml-classification-bank-marketing-all-features.ipynb b/how-to-use-azureml/automated-machine-learning/classification-bank-marketing-all-features/auto-ml-classification-bank-marketing-all-features.ipynb index e0a91ef5b..cfc0f20ef 100644 --- a/how-to-use-azureml/automated-machine-learning/classification-bank-marketing-all-features/auto-ml-classification-bank-marketing-all-features.ipynb +++ b/how-to-use-azureml/automated-machine-learning/classification-bank-marketing-all-features/auto-ml-classification-bank-marketing-all-features.ipynb @@ -105,7 +105,7 @@ "metadata": {}, "outputs": [], "source": [ - "print(\"This notebook was created using version 1.28.0 of the Azure ML SDK\")\n", + "print(\"This notebook was created using version 1.29.0 of the Azure ML SDK\")\n", "print(\"You are currently using version\", azureml.core.VERSION, \"of the Azure ML SDK\")" ] }, diff --git a/how-to-use-azureml/automated-machine-learning/classification-credit-card-fraud/auto-ml-classification-credit-card-fraud.ipynb b/how-to-use-azureml/automated-machine-learning/classification-credit-card-fraud/auto-ml-classification-credit-card-fraud.ipynb index d91bea06d..d12e450b4 100644 --- a/how-to-use-azureml/automated-machine-learning/classification-credit-card-fraud/auto-ml-classification-credit-card-fraud.ipynb +++ b/how-to-use-azureml/automated-machine-learning/classification-credit-card-fraud/auto-ml-classification-credit-card-fraud.ipynb @@ -93,7 +93,7 @@ "metadata": {}, "outputs": [], "source": [ - "print(\"This notebook was created using version 1.28.0 of the Azure ML SDK\")\n", + "print(\"This notebook was created using version 1.29.0 of the Azure ML SDK\")\n", "print(\"You are currently using version\", azureml.core.VERSION, \"of the Azure ML SDK\")" ] }, diff --git a/how-to-use-azureml/automated-machine-learning/classification-text-dnn/auto-ml-classification-text-dnn.ipynb b/how-to-use-azureml/automated-machine-learning/classification-text-dnn/auto-ml-classification-text-dnn.ipynb index 4188cfc59..1691fe861 100644 --- a/how-to-use-azureml/automated-machine-learning/classification-text-dnn/auto-ml-classification-text-dnn.ipynb +++ b/how-to-use-azureml/automated-machine-learning/classification-text-dnn/auto-ml-classification-text-dnn.ipynb @@ -96,7 +96,7 @@ "metadata": {}, "outputs": [], "source": [ - "print(\"This notebook was created using version 1.28.0 of the Azure ML SDK\")\n", + "print(\"This notebook was created using version 1.29.0 of the Azure ML SDK\")\n", "print(\"You are currently using version\", azureml.core.VERSION, \"of the Azure ML SDK\")" ] }, diff --git a/how-to-use-azureml/automated-machine-learning/continuous-retraining/auto-ml-continuous-retraining.ipynb b/how-to-use-azureml/automated-machine-learning/continuous-retraining/auto-ml-continuous-retraining.ipynb index 0e8da95a8..39072a10d 100644 --- a/how-to-use-azureml/automated-machine-learning/continuous-retraining/auto-ml-continuous-retraining.ipynb +++ b/how-to-use-azureml/automated-machine-learning/continuous-retraining/auto-ml-continuous-retraining.ipynb @@ -81,7 +81,7 @@ "metadata": {}, "outputs": [], "source": [ - "print(\"This notebook was created using version 1.28.0 of the Azure ML SDK\")\n", + "print(\"This notebook was created using version 1.29.0 of the Azure ML SDK\")\n", "print(\"You are currently using version\", azureml.core.VERSION, \"of the Azure ML SDK\")" ] }, diff --git a/how-to-use-azureml/automated-machine-learning/experimental/classification-credit-card-fraud-local-managed/auto-ml-classification-credit-card-fraud-local-managed.ipynb b/how-to-use-azureml/automated-machine-learning/experimental/classification-credit-card-fraud-local-managed/auto-ml-classification-credit-card-fraud-local-managed.ipynb new file mode 100644 index 000000000..eca909d35 --- /dev/null +++ b/how-to-use-azureml/automated-machine-learning/experimental/classification-credit-card-fraud-local-managed/auto-ml-classification-credit-card-fraud-local-managed.ipynb @@ -0,0 +1,420 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Copyright (c) Microsoft Corporation. All rights reserved.\n", + "\n", + "Licensed under the MIT License." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "![Impressions](https://PixelServer20190423114238.azurewebsites.net/api/impressions/MachineLearningNotebooks/how-to-use-azureml/automated-machine-learning/experimental/classification-credit-card-fraud/auto-ml-classification-credit-card-fraud.png)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Automated Machine Learning\n", + "_**Classification of credit card fraudulent transactions on local managed compute **_\n", + "\n", + "## Contents\n", + "1. [Introduction](#Introduction)\n", + "1. [Setup](#Setup)\n", + "1. [Train](#Train)\n", + "1. [Results](#Results)\n", + "1. [Test](#Test)\n", + "1. [Acknowledgements](#Acknowledgements)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Introduction\n", + "\n", + "In this example we use the associated credit card dataset to showcase how you can use AutoML for a simple classification problem. The goal is to predict if a credit card transaction is considered a fraudulent charge.\n", + "\n", + "This notebook is using local managed compute to train the model.\n", + "\n", + "If you are using an Azure Machine Learning Compute Instance, you are all set. Otherwise, go through the [configuration](../../../configuration.ipynb) notebook first if you haven't already to establish your connection to the AzureML Workspace. \n", + "\n", + "In this notebook you will learn how to:\n", + "1. Create an experiment using an existing workspace.\n", + "2. Configure AutoML using `AutoMLConfig`.\n", + "3. Train the model using local managed compute.\n", + "4. Explore the results.\n", + "5. Test the fitted model." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Setup\n", + "\n", + "As part of the setup you have already created an Azure ML `Workspace` object. For Automated ML you will need to create an `Experiment` object, which is a named object in a `Workspace` used to run experiments." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "import logging\n", + "\n", + "import pandas as pd\n", + "\n", + "import azureml.core\n", + "from azureml.core.compute_target import LocalTarget\n", + "from azureml.core.experiment import Experiment\n", + "from azureml.core.workspace import Workspace\n", + "from azureml.core.dataset import Dataset\n", + "from azureml.train.automl import AutoMLConfig" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "This sample notebook may use features that are not available in previous versions of the Azure ML SDK." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "print(\"This notebook was created using version 1.29.0 of the Azure ML SDK\")\n", + "print(\"You are currently using version\", azureml.core.VERSION, \"of the Azure ML SDK\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "ws = Workspace.from_config()\n", + "\n", + "# choose a name for experiment\n", + "experiment_name = 'automl-local-managed'\n", + "\n", + "experiment=Experiment(ws, experiment_name)\n", + "\n", + "output = {}\n", + "output['Subscription ID'] = ws.subscription_id\n", + "output['Workspace'] = ws.name\n", + "output['Resource Group'] = ws.resource_group\n", + "output['Location'] = ws.location\n", + "output['Experiment Name'] = experiment.name\n", + "pd.set_option('display.max_colwidth', -1)\n", + "outputDf = pd.DataFrame(data = output, index = [''])\n", + "outputDf.T" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Determine if local docker is configured for Linux images\n", + "\n", + "Local managed runs will leverage a Linux docker container to submit the run to. Due to this, the docker needs to be configured to use Linux containers." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# Check if Docker is installed and Linux containers are enabled\n", + "import subprocess\n", + "from subprocess import CalledProcessError\n", + "try:\n", + " assert subprocess.run(\"docker -v\", shell=True).returncode == 0, 'Local Managed runs require docker to be installed.'\n", + " out = subprocess.check_output(\"docker system info\", shell=True).decode('ascii')\n", + " assert \"OSType: linux\" in out, 'Docker engine needs to be configured to use Linux containers.' \\\n", + " 'https://docs.docker.com/docker-for-windows/#switch-between-windows-and-linux-containers'\n", + "except CalledProcessError as ex:\n", + " raise Exception('Local Managed runs require docker to be installed.') from ex" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Data" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Load Data\n", + "\n", + "Load the credit card dataset from a csv file containing both training features and labels. The features are inputs to the model, while the training labels represent the expected output of the model. Next, we'll split the data using random_split and extract the training data for the model." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "data = \"https://automlsamplenotebookdata.blob.core.windows.net/automl-sample-notebook-data/creditcard.csv\"\n", + "dataset = Dataset.Tabular.from_delimited_files(data)\n", + "training_data, validation_data = dataset.random_split(percentage=0.8, seed=223)\n", + "label_column_name = 'Class'" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Train\n", + "\n", + "Instantiate a AutoMLConfig object. This defines the settings and data used to run the experiment.\n", + "\n", + "|Property|Description|\n", + "|-|-|\n", + "|**task**|classification or regression|\n", + "|**primary_metric**|This is the metric that you want to optimize. Classification supports the following primary metrics:
accuracy
AUC_weighted
average_precision_score_weighted
norm_macro_recall
precision_score_weighted|\n", + "|**enable_early_stopping**|Stop the run if the metric score is not showing improvement.|\n", + "|**n_cross_validations**|Number of cross validation splits.|\n", + "|**training_data**|Input dataset, containing both features and label column.|\n", + "|**label_column_name**|The name of the label column.|\n", + "|**enable_local_managed**|Enable the experimental local-managed scenario.|\n", + "\n", + "**_You can find more information about primary metrics_** [here](https://docs.microsoft.com/en-us/azure/machine-learning/service/how-to-configure-auto-train#primary-metric)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "automl_settings = {\n", + " \"n_cross_validations\": 3,\n", + " \"primary_metric\": 'average_precision_score_weighted',\n", + " \"enable_early_stopping\": True,\n", + " \"experiment_timeout_hours\": 0.3, #for real scenarios we recommend a timeout of at least one hour \n", + " \"verbosity\": logging.INFO,\n", + "}\n", + "\n", + "automl_config = AutoMLConfig(task = 'classification',\n", + " debug_log = 'automl_errors.log',\n", + " compute_target = LocalTarget(),\n", + " enable_local_managed = True,\n", + " training_data = training_data,\n", + " label_column_name = label_column_name,\n", + " **automl_settings\n", + " )" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Call the `submit` method on the experiment object and pass the run configuration. Depending on the data and the number of iterations this can run for a while. Validation errors and current status will be shown when setting `show_output=True` and the execution will be synchronous." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "parent_run = experiment.submit(automl_config, show_output = True)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# If you need to retrieve a run that already started, use the following code\n", + "#from azureml.train.automl.run import AutoMLRun\n", + "#parent_run = AutoMLRun(experiment = experiment, run_id = '')" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "parent_run" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Results" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### Explain model\n", + "\n", + "Automated ML models can be explained and visualized using the SDK Explainability library. " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Analyze results\n", + "\n", + "### Retrieve the Best Child Run\n", + "\n", + "Below we select the best pipeline from our iterations. The `get_best_child` method returns the best run. Overloads on `get_best_child` allow you to retrieve the best run for *any* logged metric." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "best_run = parent_run.get_best_child()\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Test the fitted model\n", + "\n", + "Now that the model is trained, split the data in the same way the data was split for training (The difference here is the data is being split locally) and then run the test data through the trained model to get the predicted values." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "X_test_df = validation_data.drop_columns(columns=[label_column_name])\n", + "y_test_df = validation_data.keep_columns(columns=[label_column_name], validate=True)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### Creating ModelProxy for submitting prediction runs to the training environment.\n", + "We will create a ModelProxy for the best child run, which will allow us to submit a run that does the prediction in the training environment. Unlike the local client, which can have different versions of some libraries, the training environment will have all the compatible libraries for the model already." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "from azureml.train.automl.model_proxy import ModelProxy\n", + "best_model_proxy = ModelProxy(best_run)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# call the predict functions on the model proxy\n", + "y_pred = best_model_proxy.predict(X_test_df).to_pandas_dataframe()\n", + "y_pred" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Acknowledgements" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "This Credit Card fraud Detection dataset is made available under the Open Database License: http://opendatacommons.org/licenses/odbl/1.0/. Any rights in individual contents of the database are licensed under the Database Contents License: http://opendatacommons.org/licenses/dbcl/1.0/ and is available at: https://www.kaggle.com/mlg-ulb/creditcardfraud\n", + "\n", + "\n", + "The dataset has been collected and analysed during a research collaboration of Worldline and the Machine Learning Group (http://mlg.ulb.ac.be) of ULB (Universit\u00c3\u0192\u00c2\u00a9 Libre de Bruxelles) on big data mining and fraud detection. More details on current and past projects on related topics are available on https://www.researchgate.net/project/Fraud-detection-5 and the page of the DefeatFraud project\n", + "Please cite the following works: \n", + "\u00c3\u00a2\u00e2\u201a\u00ac\u00c2\u00a2\tAndrea Dal Pozzolo, Olivier Caelen, Reid A. Johnson and Gianluca Bontempi. Calibrating Probability with Undersampling for Unbalanced Classification. In Symposium on Computational Intelligence and Data Mining (CIDM), IEEE, 2015\n", + "\u00c3\u00a2\u00e2\u201a\u00ac\u00c2\u00a2\tDal Pozzolo, Andrea; Caelen, Olivier; Le Borgne, Yann-Ael; Waterschoot, Serge; Bontempi, Gianluca. Learned lessons in credit card fraud detection from a practitioner perspective, Expert systems with applications,41,10,4915-4928,2014, Pergamon\n", + "\u00c3\u00a2\u00e2\u201a\u00ac\u00c2\u00a2\tDal Pozzolo, Andrea; Boracchi, Giacomo; Caelen, Olivier; Alippi, Cesare; Bontempi, Gianluca. Credit card fraud detection: a realistic modeling and a novel learning strategy, IEEE transactions on neural networks and learning systems,29,8,3784-3797,2018,IEEE\n", + "o\tDal Pozzolo, Andrea Adaptive Machine learning for credit card fraud detection ULB MLG PhD thesis (supervised by G. Bontempi)\n", + "\u00c3\u00a2\u00e2\u201a\u00ac\u00c2\u00a2\tCarcillo, Fabrizio; Dal Pozzolo, Andrea; Le Borgne, Yann-A\u00c3\u0192\u00c2\u00abl; Caelen, Olivier; Mazzer, Yannis; Bontempi, Gianluca. Scarff: a scalable framework for streaming credit card fraud detection with Spark, Information fusion,41, 182-194,2018,Elsevier\n", + "\u00c3\u00a2\u00e2\u201a\u00ac\u00c2\u00a2\tCarcillo, Fabrizio; Le Borgne, Yann-A\u00c3\u0192\u00c2\u00abl; Caelen, Olivier; Bontempi, Gianluca. Streaming active learning strategies for real-life credit card fraud detection: assessment and visualization, International Journal of Data Science and Analytics, 5,4,285-300,2018,Springer International Publishing" + ] + } + ], + "metadata": { + "authors": [ + { + "name": "sekrupa" + } + ], + "category": "tutorial", + "compute": [ + "AML Compute" + ], + "datasets": [ + "Creditcard" + ], + "deployment": [ + "None" + ], + "exclude_from_index": false, + "file_extension": ".py", + "framework": [ + "None" + ], + "friendly_name": "Classification of credit card fraudulent transactions using Automated ML", + "index_order": 5, + "kernelspec": { + "display_name": "Python 3.6", + "language": "python", + "name": "python36" + }, + "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.6.7" + }, + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "tags": [ + "AutomatedML" + ], + "task": "Classification", + "version": "3.6.7" + }, + "nbformat": 4, + "nbformat_minor": 2 +} \ No newline at end of file diff --git a/how-to-use-azureml/automated-machine-learning/experimental/classification-credit-card-fraud-local-managed/auto-ml-classification-credit-card-fraud-local-managed.yml b/how-to-use-azureml/automated-machine-learning/experimental/classification-credit-card-fraud-local-managed/auto-ml-classification-credit-card-fraud-local-managed.yml new file mode 100644 index 000000000..1f2ef5b45 --- /dev/null +++ b/how-to-use-azureml/automated-machine-learning/experimental/classification-credit-card-fraud-local-managed/auto-ml-classification-credit-card-fraud-local-managed.yml @@ -0,0 +1,4 @@ +name: auto-ml-classification-credit-card-fraud-local-managed +dependencies: +- pip: + - azureml-sdk diff --git a/how-to-use-azureml/automated-machine-learning/experimental/regression-model-proxy/auto-ml-regression-model-proxy.ipynb b/how-to-use-azureml/automated-machine-learning/experimental/regression-model-proxy/auto-ml-regression-model-proxy.ipynb index 7307cbdb2..8df8c1fcc 100644 --- a/how-to-use-azureml/automated-machine-learning/experimental/regression-model-proxy/auto-ml-regression-model-proxy.ipynb +++ b/how-to-use-azureml/automated-machine-learning/experimental/regression-model-proxy/auto-ml-regression-model-proxy.ipynb @@ -91,7 +91,7 @@ "metadata": {}, "outputs": [], "source": [ - "print(\"This notebook was created using version 1.28.0 of the Azure ML SDK\")\n", + "print(\"This notebook was created using version 1.29.0 of the Azure ML SDK\")\n", "print(\"You are currently using version\", azureml.core.VERSION, \"of the Azure ML SDK\")" ] }, diff --git a/how-to-use-azureml/automated-machine-learning/forecasting-beer-remote/auto-ml-forecasting-beer-remote.ipynb b/how-to-use-azureml/automated-machine-learning/forecasting-beer-remote/auto-ml-forecasting-beer-remote.ipynb index e88666496..7795085cf 100644 --- a/how-to-use-azureml/automated-machine-learning/forecasting-beer-remote/auto-ml-forecasting-beer-remote.ipynb +++ b/how-to-use-azureml/automated-machine-learning/forecasting-beer-remote/auto-ml-forecasting-beer-remote.ipynb @@ -113,7 +113,7 @@ "metadata": {}, "outputs": [], "source": [ - "print(\"This notebook was created using version 1.28.0 of the Azure ML SDK\")\n", + "print(\"This notebook was created using version 1.29.0 of the Azure ML SDK\")\n", "print(\"You are currently using version\", azureml.core.VERSION, \"of the Azure ML SDK\")" ] }, diff --git a/how-to-use-azureml/automated-machine-learning/forecasting-bike-share/auto-ml-forecasting-bike-share.ipynb b/how-to-use-azureml/automated-machine-learning/forecasting-bike-share/auto-ml-forecasting-bike-share.ipynb index e62322d37..bc8eba15f 100644 --- a/how-to-use-azureml/automated-machine-learning/forecasting-bike-share/auto-ml-forecasting-bike-share.ipynb +++ b/how-to-use-azureml/automated-machine-learning/forecasting-bike-share/auto-ml-forecasting-bike-share.ipynb @@ -87,7 +87,7 @@ "metadata": {}, "outputs": [], "source": [ - "print(\"This notebook was created using version 1.28.0 of the Azure ML SDK\")\n", + "print(\"This notebook was created using version 1.29.0 of the Azure ML SDK\")\n", "print(\"You are currently using version\", azureml.core.VERSION, \"of the Azure ML SDK\")" ] }, diff --git a/how-to-use-azureml/automated-machine-learning/forecasting-energy-demand/auto-ml-forecasting-energy-demand.ipynb b/how-to-use-azureml/automated-machine-learning/forecasting-energy-demand/auto-ml-forecasting-energy-demand.ipynb index db233f14b..633fdc047 100644 --- a/how-to-use-azureml/automated-machine-learning/forecasting-energy-demand/auto-ml-forecasting-energy-demand.ipynb +++ b/how-to-use-azureml/automated-machine-learning/forecasting-energy-demand/auto-ml-forecasting-energy-demand.ipynb @@ -97,7 +97,7 @@ "metadata": {}, "outputs": [], "source": [ - "print(\"This notebook was created using version 1.28.0 of the Azure ML SDK\")\n", + "print(\"This notebook was created using version 1.29.0 of the Azure ML SDK\")\n", "print(\"You are currently using version\", azureml.core.VERSION, \"of the Azure ML SDK\")" ] }, diff --git a/how-to-use-azureml/automated-machine-learning/forecasting-forecast-function/auto-ml-forecasting-function.ipynb b/how-to-use-azureml/automated-machine-learning/forecasting-forecast-function/auto-ml-forecasting-function.ipynb index b71604506..1d77b16f4 100644 --- a/how-to-use-azureml/automated-machine-learning/forecasting-forecast-function/auto-ml-forecasting-function.ipynb +++ b/how-to-use-azureml/automated-machine-learning/forecasting-forecast-function/auto-ml-forecasting-function.ipynb @@ -94,7 +94,7 @@ "metadata": {}, "outputs": [], "source": [ - "print(\"This notebook was created using version 1.28.0 of the Azure ML SDK\")\n", + "print(\"This notebook was created using version 1.29.0 of the Azure ML SDK\")\n", "print(\"You are currently using version\", azureml.core.VERSION, \"of the Azure ML SDK\")" ] }, diff --git a/how-to-use-azureml/automated-machine-learning/forecasting-orange-juice-sales/auto-ml-forecasting-orange-juice-sales.ipynb b/how-to-use-azureml/automated-machine-learning/forecasting-orange-juice-sales/auto-ml-forecasting-orange-juice-sales.ipynb index 2575cec90..8027e2f87 100644 --- a/how-to-use-azureml/automated-machine-learning/forecasting-orange-juice-sales/auto-ml-forecasting-orange-juice-sales.ipynb +++ b/how-to-use-azureml/automated-machine-learning/forecasting-orange-juice-sales/auto-ml-forecasting-orange-juice-sales.ipynb @@ -82,7 +82,7 @@ "metadata": {}, "outputs": [], "source": [ - "print(\"This notebook was created using version 1.28.0 of the Azure ML SDK\")\n", + "print(\"This notebook was created using version 1.29.0 of the Azure ML SDK\")\n", "print(\"You are currently using version\", azureml.core.VERSION, \"of the Azure ML SDK\")" ] }, diff --git a/how-to-use-azureml/automated-machine-learning/local-run-classification-credit-card-fraud/auto-ml-classification-credit-card-fraud-local.ipynb b/how-to-use-azureml/automated-machine-learning/local-run-classification-credit-card-fraud/auto-ml-classification-credit-card-fraud-local.ipynb index 76f036e7a..751ec06f7 100644 --- a/how-to-use-azureml/automated-machine-learning/local-run-classification-credit-card-fraud/auto-ml-classification-credit-card-fraud-local.ipynb +++ b/how-to-use-azureml/automated-machine-learning/local-run-classification-credit-card-fraud/auto-ml-classification-credit-card-fraud-local.ipynb @@ -96,7 +96,7 @@ "metadata": {}, "outputs": [], "source": [ - "print(\"This notebook was created using version 1.28.0 of the Azure ML SDK\")\n", + "print(\"This notebook was created using version 1.29.0 of the Azure ML SDK\")\n", "print(\"You are currently using version\", azureml.core.VERSION, \"of the Azure ML SDK\")" ] }, diff --git a/how-to-use-azureml/automated-machine-learning/regression-explanation-featurization/auto-ml-regression-explanation-featurization.ipynb b/how-to-use-azureml/automated-machine-learning/regression-explanation-featurization/auto-ml-regression-explanation-featurization.ipynb index 222a647d2..2c7fbd0fb 100644 --- a/how-to-use-azureml/automated-machine-learning/regression-explanation-featurization/auto-ml-regression-explanation-featurization.ipynb +++ b/how-to-use-azureml/automated-machine-learning/regression-explanation-featurization/auto-ml-regression-explanation-featurization.ipynb @@ -96,7 +96,7 @@ "metadata": {}, "outputs": [], "source": [ - "print(\"This notebook was created using version 1.28.0 of the Azure ML SDK\")\n", + "print(\"This notebook was created using version 1.29.0 of the Azure ML SDK\")\n", "print(\"You are currently using version\", azureml.core.VERSION, \"of the Azure ML SDK\")" ] }, diff --git a/how-to-use-azureml/automated-machine-learning/regression/auto-ml-regression.ipynb b/how-to-use-azureml/automated-machine-learning/regression/auto-ml-regression.ipynb index aab12933f..f9fe5f58d 100644 --- a/how-to-use-azureml/automated-machine-learning/regression/auto-ml-regression.ipynb +++ b/how-to-use-azureml/automated-machine-learning/regression/auto-ml-regression.ipynb @@ -92,7 +92,7 @@ "metadata": {}, "outputs": [], "source": [ - "print(\"This notebook was created using version 1.28.0 of the Azure ML SDK\")\n", + "print(\"This notebook was created using version 1.29.0 of the Azure ML SDK\")\n", "print(\"You are currently using version\", azureml.core.VERSION, \"of the Azure ML SDK\")" ] }, diff --git a/how-to-use-azureml/explain-model/azure-integration/remote-explanation/explain-model-on-amlcompute.ipynb b/how-to-use-azureml/explain-model/azure-integration/remote-explanation/explain-model-on-amlcompute.ipynb index 02504b731..24ca8882e 100644 --- a/how-to-use-azureml/explain-model/azure-integration/remote-explanation/explain-model-on-amlcompute.ipynb +++ b/how-to-use-azureml/explain-model/azure-integration/remote-explanation/explain-model-on-amlcompute.ipynb @@ -217,7 +217,6 @@ "metadata": {}, "outputs": [], "source": [ - "from azureml.core.compute import ComputeTarget, AmlCompute\n", "from azureml.core.compute_target import ComputeTargetException\n", "\n", "# Choose a name for your CPU cluster\n", @@ -267,7 +266,7 @@ "available_packages = pkg_resources.working_set\n", "sklearn_ver = None\n", "pandas_ver = None\n", - "for dist in available_packages:\n", + "for dist in list(available_packages):\n", " if dist.key == 'scikit-learn':\n", " sklearn_ver = dist.version\n", " elif dist.key == 'pandas':\n", @@ -286,7 +285,6 @@ "azureml_pip_packages.extend([sklearn_dep, pandas_dep])\n", "run_config.environment.python.conda_dependencies = CondaDependencies.create(pip_packages=azureml_pip_packages)\n", "\n", - "from azureml.core import Run\n", "from azureml.core import ScriptRunConfig\n", "\n", "src = ScriptRunConfig(source_directory=project_folder, \n", @@ -416,7 +414,6 @@ "outputs": [], "source": [ "# Retrieve x_test for visualization\n", - "import joblib\n", "x_test_path = './x_test_boston_housing.pkl'\n", "run.download_file('x_test_boston_housing.pkl', output_file_path=x_test_path)" ] @@ -444,7 +441,7 @@ "metadata": {}, "outputs": [], "source": [ - "from interpret_community.widget import ExplanationDashboard" + "from raiwidgets import ExplanationDashboard" ] }, { @@ -453,7 +450,7 @@ "metadata": {}, "outputs": [], "source": [ - "ExplanationDashboard(global_explanation, original_model, datasetX=x_test)" + "ExplanationDashboard(global_explanation, original_model, dataset=x_test)" ] }, { diff --git a/how-to-use-azureml/explain-model/azure-integration/remote-explanation/explain-model-on-amlcompute.yml b/how-to-use-azureml/explain-model/azure-integration/remote-explanation/explain-model-on-amlcompute.yml index dd29d1924..5f7fab563 100644 --- a/how-to-use-azureml/explain-model/azure-integration/remote-explanation/explain-model-on-amlcompute.yml +++ b/how-to-use-azureml/explain-model/azure-integration/remote-explanation/explain-model-on-amlcompute.yml @@ -11,3 +11,4 @@ dependencies: - matplotlib - azureml-dataset-runtime - ipywidgets + - raiwidgets==0.4.0 diff --git a/how-to-use-azureml/explain-model/azure-integration/run-history/save-retrieve-explanations-run-history.ipynb b/how-to-use-azureml/explain-model/azure-integration/run-history/save-retrieve-explanations-run-history.ipynb index 70c82da48..b9cb9cb2e 100644 --- a/how-to-use-azureml/explain-model/azure-integration/run-history/save-retrieve-explanations-run-history.ipynb +++ b/how-to-use-azureml/explain-model/azure-integration/run-history/save-retrieve-explanations-run-history.ipynb @@ -87,7 +87,6 @@ "from sklearn.preprocessing import StandardScaler, OneHotEncoder\n", "from sklearn.svm import SVC\n", "import pandas as pd\n", - "import numpy as np\n", "\n", "# Explainers:\n", "# 1. SHAP Tabular Explainer\n", @@ -533,7 +532,7 @@ "metadata": {}, "outputs": [], "source": [ - "from interpret_community.widget import ExplanationDashboard" + "from raiwidgets import ExplanationDashboard" ] }, { @@ -542,7 +541,7 @@ "metadata": {}, "outputs": [], "source": [ - "ExplanationDashboard(downloaded_global_explanation, model, datasetX=x_test)" + "ExplanationDashboard(downloaded_global_explanation, model, dataset=x_test)" ] }, { diff --git a/how-to-use-azureml/explain-model/azure-integration/run-history/save-retrieve-explanations-run-history.yml b/how-to-use-azureml/explain-model/azure-integration/run-history/save-retrieve-explanations-run-history.yml index 11ef34b73..38a642802 100644 --- a/how-to-use-azureml/explain-model/azure-integration/run-history/save-retrieve-explanations-run-history.yml +++ b/how-to-use-azureml/explain-model/azure-integration/run-history/save-retrieve-explanations-run-history.yml @@ -10,3 +10,4 @@ dependencies: - ipython - matplotlib - ipywidgets + - raiwidgets==0.4.0 diff --git a/how-to-use-azureml/explain-model/azure-integration/scoring-time/train-explain-model-locally-and-deploy.ipynb b/how-to-use-azureml/explain-model/azure-integration/scoring-time/train-explain-model-locally-and-deploy.ipynb index cee7df82a..3ffa00307 100644 --- a/how-to-use-azureml/explain-model/azure-integration/scoring-time/train-explain-model-locally-and-deploy.ipynb +++ b/how-to-use-azureml/explain-model/azure-integration/scoring-time/train-explain-model-locally-and-deploy.ipynb @@ -170,7 +170,6 @@ "from sklearn.preprocessing import StandardScaler, OneHotEncoder\n", "from sklearn.impute import SimpleImputer\n", "from sklearn.pipeline import Pipeline\n", - "from sklearn.linear_model import LogisticRegression\n", "from sklearn.ensemble import RandomForestClassifier\n", "\n", "from interpret.ext.blackbox import TabularExplainer\n", @@ -221,7 +220,6 @@ " ('classifier', RandomForestClassifier())])\n", "\n", "# Split data into train and test\n", - "from sklearn.model_selection import train_test_split\n", "x_train, x_test, y_train, y_test = train_test_split(attritionXData,\n", " target,\n", " test_size=0.2,\n", @@ -296,7 +294,7 @@ "metadata": {}, "outputs": [], "source": [ - "from interpret_community.widget import ExplanationDashboard" + "from raiwidgets import ExplanationDashboard" ] }, { @@ -305,7 +303,7 @@ "metadata": {}, "outputs": [], "source": [ - "ExplanationDashboard(global_explanation, clf, datasetX=x_test)" + "ExplanationDashboard(global_explanation, clf, dataset=x_test)" ] }, { @@ -383,10 +381,8 @@ "metadata": {}, "outputs": [], "source": [ - "from azureml.core.webservice import Webservice\n", "from azureml.core.model import InferenceConfig\n", "from azureml.core.webservice import AciWebservice\n", - "from azureml.core.model import Model\n", "from azureml.core.environment import Environment\n", "from azureml.exceptions import WebserviceException\n", "\n", @@ -403,7 +399,7 @@ "# Use configs and models generated above\n", "service = Model.deploy(ws, 'model-scoring-deploy-local', [scoring_explainer_model, original_model], inference_config, aciconfig)\n", "try:\n", - " service.wait_for_deployment(show_output=True)\n", + " service.wait_for_deployment(show_output=True, timeout_sec=10*60)\n", "except WebserviceException as e:\n", " print(e.message)\n", " print(service.get_logs())\n", diff --git a/how-to-use-azureml/explain-model/azure-integration/scoring-time/train-explain-model-locally-and-deploy.yml b/how-to-use-azureml/explain-model/azure-integration/scoring-time/train-explain-model-locally-and-deploy.yml index 334cf2b1b..e9a708ca6 100644 --- a/how-to-use-azureml/explain-model/azure-integration/scoring-time/train-explain-model-locally-and-deploy.yml +++ b/how-to-use-azureml/explain-model/azure-integration/scoring-time/train-explain-model-locally-and-deploy.yml @@ -10,3 +10,4 @@ dependencies: - ipython - matplotlib - ipywidgets + - raiwidgets==0.4.0 diff --git a/how-to-use-azureml/explain-model/azure-integration/scoring-time/train-explain-model-on-amlcompute-and-deploy.ipynb b/how-to-use-azureml/explain-model/azure-integration/scoring-time/train-explain-model-on-amlcompute-and-deploy.ipynb index cb73cc494..49413b432 100644 --- a/how-to-use-azureml/explain-model/azure-integration/scoring-time/train-explain-model-on-amlcompute-and-deploy.ipynb +++ b/how-to-use-azureml/explain-model/azure-integration/scoring-time/train-explain-model-on-amlcompute-and-deploy.ipynb @@ -218,7 +218,6 @@ "metadata": {}, "outputs": [], "source": [ - "from azureml.core.compute import ComputeTarget, AmlCompute\n", "from azureml.core.compute_target import ComputeTargetException\n", "\n", "# Choose a name for your CPU cluster\n", @@ -380,7 +379,6 @@ "outputs": [], "source": [ "# Retrieve x_test for visualization\n", - "import joblib\n", "x_test_path = './x_test.pkl'\n", "run.download_file('x_test_ibm.pkl', output_file_path=x_test_path)\n", "x_test = joblib.load(x_test_path)" @@ -400,7 +398,7 @@ "metadata": {}, "outputs": [], "source": [ - "from interpret_community.widget import ExplanationDashboard" + "from raiwidgets import ExplanationDashboard" ] }, { @@ -409,7 +407,7 @@ "metadata": {}, "outputs": [], "source": [ - "ExplanationDashboard(global_explanation, original_svm_model, datasetX=x_test)" + "ExplanationDashboard(global_explanation, original_svm_model, dataset=x_test)" ] }, { @@ -426,8 +424,6 @@ "metadata": {}, "outputs": [], "source": [ - "from azureml.core.conda_dependencies import CondaDependencies \n", - "\n", "# WARNING: to install this, g++ needs to be available on the Docker image and is not by default (look at the next cell)\n", "azureml_pip_packages = [\n", " 'azureml-defaults', 'azureml-core', 'azureml-telemetry',\n", @@ -437,7 +433,6 @@ "\n", "# Note: this is to pin the scikit-learn and pandas versions to be same as notebook.\n", "# In production scenario user would choose their dependencies\n", - "import pkg_resources\n", "available_packages = pkg_resources.working_set\n", "sklearn_ver = None\n", "pandas_ver = None\n", @@ -483,10 +478,8 @@ "metadata": {}, "outputs": [], "source": [ - "from azureml.core.webservice import Webservice\n", "from azureml.core.model import InferenceConfig\n", "from azureml.core.webservice import AciWebservice\n", - "from azureml.core.model import Model\n", "from azureml.core.environment import Environment\n", "from azureml.exceptions import WebserviceException\n", "\n", @@ -503,7 +496,7 @@ "# Use configs and models generated above\n", "service = Model.deploy(ws, 'model-scoring-service', [scoring_explainer_model, original_model], inference_config, aciconfig)\n", "try:\n", - " service.wait_for_deployment(show_output=True)\n", + " service.wait_for_deployment(show_output=True, timeout_sec=10*60)\n", "except WebserviceException as e:\n", " print(e.message)\n", " print(service.get_logs())\n", diff --git a/how-to-use-azureml/explain-model/azure-integration/scoring-time/train-explain-model-on-amlcompute-and-deploy.yml b/how-to-use-azureml/explain-model/azure-integration/scoring-time/train-explain-model-on-amlcompute-and-deploy.yml index 42c0a8865..1770bedf2 100644 --- a/how-to-use-azureml/explain-model/azure-integration/scoring-time/train-explain-model-on-amlcompute-and-deploy.yml +++ b/how-to-use-azureml/explain-model/azure-integration/scoring-time/train-explain-model-on-amlcompute-and-deploy.yml @@ -12,3 +12,4 @@ dependencies: - azureml-dataset-runtime - azureml-core - ipywidgets + - raiwidgets==0.4.0 diff --git a/how-to-use-azureml/ml-frameworks/using-mlflow/train-and-deploy-keras-auto-logging/train-and-deploy-keras-auto-logging.ipynb b/how-to-use-azureml/ml-frameworks/using-mlflow/train-and-deploy-keras-auto-logging/train-and-deploy-keras-auto-logging.ipynb index d486be38a..7d75d8fd1 100644 --- a/how-to-use-azureml/ml-frameworks/using-mlflow/train-and-deploy-keras-auto-logging/train-and-deploy-keras-auto-logging.ipynb +++ b/how-to-use-azureml/ml-frameworks/using-mlflow/train-and-deploy-keras-auto-logging/train-and-deploy-keras-auto-logging.ipynb @@ -250,7 +250,7 @@ "source": [ "### Deploy model as web service\n", "\n", - "The ```mlflow.azureml.deploy``` function registers the logged Keras+Tensorflow model and deploys the model in a framework-aware manner. It automatically creates the Tensorflow-specific inferencing wrapper code and specifies package dependencies for you. See [this doc](https://mlflow.org/docs/latest/models.html#id34) for more information on deploying models on Azure ML using MLflow.\n", + "The ```client.create_deployment``` function registers the logged Keras+Tensorflow model and deploys the model in a framework-aware manner. It automatically creates the Tensorflow-specific inferencing wrapper code and specifies package dependencies for you. See [this doc](https://mlflow.org/docs/latest/models.html#id34) for more information on deploying models on Azure ML using MLflow.\n", "\n", "In this example, we deploy the Docker image to Azure Container Instance: a serverless compute capable of running a single container. You can tag and add descriptions to help keep track of your web service. \n", "\n", @@ -260,33 +260,11 @@ ] }, { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], "source": [ - "from azureml.core.webservice import AciWebservice, Webservice\n", - "\n", - "model_path = \"model\"\n", - "\n", - "aci_config = AciWebservice.deploy_configuration(cpu_cores=2, \n", - " memory_gb=5, \n", - " tags={\"data\": \"MNIST\", \"method\" : \"keras\"}, \n", - " description=\"Predict using webservice\")\n", - "\n", - "webservice, azure_model = mlflow.azureml.deploy(model_uri='runs:/{}/{}'.format(run.id, model_path),\n", - " workspace=ws,\n", - " deployment_config=aci_config,\n", - " service_name=\"keras-mnist-1\",\n", - " model_name=\"keras_mnist\")" - ] - }, - { + "First define your deployment target and customize parameters in the deployment config. Refer to [this documentation](https://docs.microsoft.com/azure/machine-learning/reference-azure-machine-learning-cli#azure-container-instance-deployment-configuration-schema) for more information. " + ], "cell_type": "markdown", - "metadata": {}, - "source": [ - "Once the deployment has completed you can check the scoring URI of the web service." - ] + "metadata": {} }, { "cell_type": "code", @@ -294,54 +272,18 @@ "metadata": {}, "outputs": [], "source": [ - "print(\"Scoring URI is: {}\".format(webservice.scoring_uri))" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "In case of a service creation issue, you can use ```webservice.get_logs()``` to get logs to debug." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Make predictions using a web service\n", - "\n", - "To make the web service, create a test data set as normalized NumPy array. \n", - "\n", - "Then, let's define a utility function that takes a random image and converts it into a format and shape suitable for input to the Keras inferencing end-point. The conversion is done by: \n", - "\n", - " 1. Select a random (image, label) tuple\n", - " 2. Take the image and converting to to NumPy array \n", - " 3. Reshape array into 1 x 1 x N array\n", - " * 1 image in batch, 1 color channel, N = 784 pixels for MNIST images\n", - " * Note also ```x = x.view(-1, 1, 28, 28)``` in net definition in ```train.py``` program to shape incoming scoring requests.\n", - " 4. Convert the NumPy array to list to make it into a built-in type.\n", - " 5. Create a dictionary {\"data\", <list>} that can be converted to JSON string for web service requests." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "import keras\n", - "import random\n", - "import numpy as np\n", - "\n", - "# the data, split between train and test sets\n", - "(x_train, y_train), (x_test, y_test) = keras.datasets.mnist.load_data()\n", - "\n", - "# Scale images to the [0, 1] range\n", - "x_test = x_test.astype(\"float32\") / 255\n", - "x_test = x_test.reshape(len(x_test), -1)\n", - "\n", - "# convert class vectors to binary class matrices\n", - "y_test = keras.utils.to_categorical(y_test, 10)" + "import json\n", + " \n", + "# Data to be written\n", + "deploy_config ={\n", + " \"computeType\": \"aci\"\n", + "}\n", + "# Serializing json \n", + "json_object = json.dumps(deploy_config)\n", + " \n", + "# Writing to sample.json\n", + "with open(\"deployment_config.json\", \"w\") as outfile:\n", + " outfile.write(json_object)" ] }, { @@ -350,40 +292,30 @@ "metadata": {}, "outputs": [], "source": [ - "%matplotlib inline\n", - "\n", - "import json\n", - "import matplotlib.pyplot as plt\n", + "from mlflow.deployments import get_deploy_client\n", "\n", - "# send a random row from the test set to score\n", - "random_index = np.random.randint(0, len(x_test)-1)\n", - "input_data = \"{\\\"data\\\": [\" + str(list(x_test[random_index])) + \"]}\"\n", + "# set the tracking uri as the deployment client\n", + "client = get_deploy_client(mlflow.get_tracking_uri())\n", "\n", - "response = webservice.run(input_data)\n", + "# set the model path \n", + "model_path = \"model\"\n", "\n", - "response = sorted(response[0].items(), key = lambda x: x[1], reverse = True)\n", + "# set the deployment config\n", + "deployment_config_path = \"deployment_config.json\"\n", + "test_config = {'deploy-config-file': deployment_config_path}\n", "\n", - "print(\"Predicted label:\", response[0][0])\n", - "plt.imshow(x_test[random_index].reshape(28,28), cmap = \"gray\")" + "# define the model path and the name is the service name\n", + "# the model gets registered automatically and a name is autogenerated using the \"name\" parameter below \n", + "client.create_deployment(model_uri='runs:/{}/{}'.format(run.id, model_path),\n", + " config=test_config,\n", + " name=\"keras-aci-deployment\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "You can also call the web service using a raw POST method against the web service" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "import requests\n", - "\n", - "response = requests.post(url=webservice.scoring_uri, data=input_data,headers={\"Content-type\": \"application/json\"})\n", - "print(response.text)" + "Once the deployment has completed you can check the scoring URI of the web service in AzureML studio UI in the endpoints tab. Refer [mlflow predict](https://mlflow.org/docs/latest/python_api/mlflow.deployments.html#mlflow.deployments.BaseDeploymentClient.predict) on how to test your deployment. " ] }, { @@ -400,7 +332,7 @@ "metadata": {}, "outputs": [], "source": [ - "webservice.delete()" + "client.delete(\"keras-aci-deployment\")" ] } ], diff --git a/how-to-use-azureml/ml-frameworks/using-mlflow/train-and-deploy-pytorch/train-and-deploy-pytorch.ipynb b/how-to-use-azureml/ml-frameworks/using-mlflow/train-and-deploy-pytorch/train-and-deploy-pytorch.ipynb index 680a0dd7a..4d91702c2 100644 --- a/how-to-use-azureml/ml-frameworks/using-mlflow/train-and-deploy-pytorch/train-and-deploy-pytorch.ipynb +++ b/how-to-use-azureml/ml-frameworks/using-mlflow/train-and-deploy-pytorch/train-and-deploy-pytorch.ipynb @@ -249,7 +249,7 @@ "source": [ "## Deploy model as web service\n", "\n", - "The ```mlflow.azureml.deploy``` function registers the logged PyTorch model and deploys the model in a framework-aware manner. It automatically creates the PyTorch-specific inferencing wrapper code and specifies package dependencies for you. See [this doc](https://mlflow.org/docs/latest/models.html#id34) for more information on deploying models on Azure ML using MLflow.\n", + "The ```client.create_deployment``` function registers the logged PyTorch model and deploys the model in a framework-aware manner. It automatically creates the PyTorch-specific inferencing wrapper code and specifies package dependencies for you. See [this doc](https://mlflow.org/docs/latest/models.html#id34) for more information on deploying models on Azure ML using MLflow.\n", "\n", "In this example, we deploy the Docker image to Azure Container Instance: a serverless compute capable of running a single container. You can tag and add descriptions to help keep track of your web service. \n", "\n", @@ -259,68 +259,11 @@ ] }, { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "from azureml.core.webservice import AciWebservice, Webservice\n", - "\n", - "model_path = \"model\"\n", - "\n", - "aci_config = AciWebservice.deploy_configuration(cpu_cores=2, \n", - " memory_gb=5, \n", - " tags={\"data\": \"MNIST\", \"method\" : \"pytorch\"}, \n", - " description=\"Predict using webservice\")\n", - "\n", - "webservice, azure_model = mlflow.azureml.deploy(model_uri='runs:/{}/{}'.format(run.id, model_path),\n", - " workspace=ws,\n", - " deployment_config=aci_config,\n", - " service_name=\"pytorch-mnist-1\",\n", - " model_name=\"pytorch_mnist\")" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Once the deployment has completed you can check the scoring URI of the web service." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], "source": [ - "print(\"Scoring URI is: {}\".format(webservice.scoring_uri))" - ] - }, - { + "First define your deployment target and customize parameters in the deployment config. Refer to [this documentation](https://docs.microsoft.com/azure/machine-learning/reference-azure-machine-learning-cli#azure-container-instance-deployment-configuration-schema) for more information. " + ], "cell_type": "markdown", - "metadata": {}, - "source": [ - "In case of a service creation issue, you can use ```webservice.get_logs()``` to get logs to debug." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Make predictions using a web service\n", - "\n", - "To make the web service, create a test data set as normalized PyTorch tensors. \n", - "\n", - "Then, let's define a utility function that takes a random image and converts it into a format and shape suitable for input to the PyTorch inferencing end-point. The conversion is done by: \n", - "\n", - " 1. Select a random (image, label) tuple\n", - " 2. Take the image and converting the tensor to NumPy array \n", - " 3. Reshape array into 1 x 1 x N array\n", - " * 1 image in batch, 1 color channel, N = 784 pixels for MNIST images\n", - " * Note also ```x = x.view(-1, 1, 28, 28)``` in net definition in ```train.py``` program to shape incoming scoring requests.\n", - " 4. Convert the NumPy array to list to make it into a built-in type.\n", - " 5. Create a dictionary {\"data\", <list>} that can be converted to JSON string for web service requests." - ] + "metadata": {} }, { "cell_type": "code", @@ -328,40 +271,18 @@ "metadata": {}, "outputs": [], "source": [ - "from torchvision import datasets, transforms\n", - "import random\n", - "import numpy as np\n", - "\n", - "# Use Azure Open Datasets for MNIST dataset\n", - "datasets.MNIST.resources = [\n", - " (\"https://azureopendatastorage.azurefd.net/mnist/train-images-idx3-ubyte.gz\",\n", - " \"f68b3c2dcbeaaa9fbdd348bbdeb94873\"),\n", - " (\"https://azureopendatastorage.azurefd.net/mnist/train-labels-idx1-ubyte.gz\",\n", - " \"d53e105ee54ea40749a09fcbcd1e9432\"),\n", - " (\"https://azureopendatastorage.azurefd.net/mnist/t10k-images-idx3-ubyte.gz\",\n", - " \"9fb629c4189551a2d022fa330f9573f3\"),\n", - " (\"https://azureopendatastorage.azurefd.net/mnist/t10k-labels-idx1-ubyte.gz\",\n", - " \"ec29112dd5afa0611ce80d1b7f02629c\")\n", - "]\n", - "\n", - "test_data = datasets.MNIST('../data', train=False, transform=transforms.Compose([\n", - " transforms.ToTensor(),\n", - " transforms.Normalize((0.1307,), (0.3081,))]))\n", - "\n", - "\n", - "def get_random_image():\n", - " image_idx = random.randint(0,len(test_data))\n", - " image_as_tensor = test_data[image_idx][0]\n", - " return {\"data\": elem for elem in image_as_tensor.numpy().reshape(1,1,-1).tolist()}" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Then, invoke the web service using a random test image. Convert the dictionary containing the image to JSON string before passing it to web service.\n", - "\n", - "The response contains the raw scores for each label, with greater value indicating higher probability. Sort the labels and select the one with greatest score to get the prediction. Let's also plot the image sent to web service for comparison purposes." + "import json\n", + " \n", + "# Data to be written\n", + "deploy_config ={\n", + " \"computeType\": \"aci\"\n", + "}\n", + "# Serializing json \n", + "json_object = json.dumps(deploy_config)\n", + " \n", + "# Writing to sample.json\n", + "with open(\"deployment_config.json\", \"w\") as outfile:\n", + " outfile.write(json_object)" ] }, { @@ -370,47 +291,30 @@ "metadata": {}, "outputs": [], "source": [ - "%matplotlib inline\n", - "\n", - "import json\n", - "import matplotlib.pyplot as plt\n", + "from mlflow.deployments import get_deploy_client\n", "\n", - "test_image = get_random_image()\n", - "\n", - "response = webservice.run(json.dumps(test_image))\n", - "\n", - "response = sorted(response[0].items(), key = lambda x: x[1], reverse = True)\n", + "# set the tracking uri as the deployment client\n", + "client = get_deploy_client(mlflow.get_tracking_uri())\n", "\n", + "# set the model path \n", + "model_path = \"model\"\n", "\n", - "print(\"Predicted label:\", response[0][0])\n", - "plt.imshow(np.array(test_image[\"data\"]).reshape(28,28), cmap = \"gray\")" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "You can also call the web service using a raw POST method against the web service" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "import requests\n", + "# set the deployment config\n", + "deployment_config_path = \"deployment_config.json\"\n", + "test_config = {'deploy-config-file': deployment_config_path}\n", "\n", - "response = requests.post(url=webservice.scoring_uri, data=json.dumps(test_image),headers={\"Content-type\": \"application/json\"})\n", - "print(response.text)" + "# define the model path and the name is the service name\n", + "# the model gets registered automatically and a name is autogenerated using the \"name\" parameter below \n", + "client.create_deployment(model_uri='runs:/{}/{}'.format(run.id, model_path),\n", + " config=test_config,\n", + " name=\"keras-aci-deployment\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "## Clean up\n", - "You can delete the ACI deployment with a delete API call." + "Once the deployment has completed you can check the scoring URI of the web service in AzureML studio UI in the endpoints tab. Refer [mlflow predict](https://mlflow.org/docs/latest/python_api/mlflow.deployments.html#mlflow.deployments.BaseDeploymentClient.predict) on how to test your deployment. " ] }, { @@ -419,7 +323,7 @@ "metadata": {}, "outputs": [], "source": [ - "webservice.delete()" + "client.delete(\"keras-aci-deployment\")" ] } ], diff --git a/how-to-use-azureml/responsible-ai/visualize-upload-loan-decision/rai-loan-decision.ipynb b/how-to-use-azureml/responsible-ai/visualize-upload-loan-decision/rai-loan-decision.ipynb index 223e4ef89..97cdb366e 100644 --- a/how-to-use-azureml/responsible-ai/visualize-upload-loan-decision/rai-loan-decision.ipynb +++ b/how-to-use-azureml/responsible-ai/visualize-upload-loan-decision/rai-loan-decision.ipynb @@ -35,7 +35,7 @@ "source": [ "## Install required packages\n", "\n", - "This notebook works with Fairlearn v0.4.6, and not later versions. If needed, please uncomment and run the following cell:" + "This notebook works with Fairlearn v0.6.1, but not with versions pre-v0.5.0. If needed, please uncomment and run the following cell:" ] }, { @@ -44,7 +44,7 @@ "metadata": {}, "outputs": [], "source": [ - "# %pip install --upgrade fairlearn==0.4.6" + "# %pip install --upgrade fairlearn>=0.6.2" ] }, { @@ -70,21 +70,18 @@ "outputs": [], "source": [ "from fairlearn.reductions import GridSearch\n", - "from fairlearn.reductions import DemographicParity, ErrorRate\n", + "from fairlearn.reductions import DemographicParity\n", "\n", "from sklearn.compose import ColumnTransformer, make_column_selector\n", - "from sklearn.preprocessing import LabelEncoder,StandardScaler\n", + "from sklearn.preprocessing import LabelEncoder, StandardScaler, OneHotEncoder\n", "from sklearn.linear_model import LogisticRegression\n", "from sklearn.pipeline import Pipeline\n", "from sklearn.impute import SimpleImputer\n", - "from sklearn.preprocessing import StandardScaler, OneHotEncoder\n", - "from sklearn.svm import SVC\n", "from sklearn.metrics import accuracy_score\n", "\n", "import pandas as pd\n", "\n", "# SHAP Tabular Explainer\n", - "from interpret.ext.blackbox import KernelExplainer\n", "from interpret.ext.blackbox import MimicExplainer\n", "from interpret.ext.glassbox import LGBMExplainableModel" ] @@ -340,13 +337,13 @@ "metadata": {}, "outputs": [], "source": [ - "from fairlearn.widget import FairlearnDashboard\n", + "from raiwidgets import FairnessDashboard\n", "\n", "y_pred = model.predict(X_test)\n", "\n", - "FairlearnDashboard(sensitive_features=sensitive_features_test,\n", - " y_true=y_test,\n", - " y_pred=y_pred)" + "FairnessDashboard(sensitive_features=sensitive_features_test,\n", + " y_true=y_test,\n", + " y_pred=y_pred)" ] }, { @@ -402,7 +399,7 @@ "sweep.fit(X_train_prep, y_train,\n", " sensitive_features=sensitive_features_train.sex)\n", "\n", - "predictors = sweep._predictors" + "predictors = sweep.predictors_" ] }, { @@ -468,7 +465,7 @@ "for name, predictor in dominant_models_dict.items():\n", " dominant_all[name] = predictor.predict(X_test_prep)\n", "\n", - "FairlearnDashboard(sensitive_features=sensitive_features_test, \n", + "FairnessDashboard(sensitive_features=sensitive_features_test, \n", " y_true=y_test,\n", " y_pred=dominant_all)" ] @@ -563,7 +560,7 @@ "source": [ "import joblib\n", "import os\n", - "from azureml.core import Model, Experiment, Run\n", + "from azureml.core import Model, Experiment\n", "\n", "os.makedirs('models', exist_ok=True)\n", "def register_model(name, model):\n", diff --git a/how-to-use-azureml/responsible-ai/visualize-upload-loan-decision/rai-loan-decision.yml b/how-to-use-azureml/responsible-ai/visualize-upload-loan-decision/rai-loan-decision.yml index d602f6b69..21708d83a 100644 --- a/how-to-use-azureml/responsible-ai/visualize-upload-loan-decision/rai-loan-decision.yml +++ b/how-to-use-azureml/responsible-ai/visualize-upload-loan-decision/rai-loan-decision.yml @@ -4,9 +4,9 @@ dependencies: - azureml-sdk - azureml-interpret - azureml-contrib-fairness - - fairlearn==0.4.6 + - fairlearn>=0.6.2 - matplotlib - azureml-dataset-runtime - ipywidgets - - raiwidgets + - raiwidgets==0.4.0 - liac-arff diff --git a/how-to-use-azureml/responsible-ai/visualize-upload-loan-decision/utilities.py b/how-to-use-azureml/responsible-ai/visualize-upload-loan-decision/utilities.py index c2d60e54d..5eaa0a3f5 100644 --- a/how-to-use-azureml/responsible-ai/visualize-upload-loan-decision/utilities.py +++ b/how-to-use-azureml/responsible-ai/visualize-upload-loan-decision/utilities.py @@ -10,6 +10,7 @@ import gzip import pandas as pd from sklearn.utils import Bunch +from time import sleep def _is_gzip_encoded(_fsrc): @@ -29,7 +30,7 @@ def _is_gzip_encoded(_fsrc): def fetch_census_dataset(): - """Fetch the Adult Census Dataset + """Fetch the Adult Census Dataset. This uses a particular URL for the Adult Census dataset. The code is a simplified version of fetch_openml() in sklearn. @@ -45,21 +46,38 @@ def fetch_census_dataset(): filename = "1595261.gz" data_url = "https://rainotebookscdn.blob.core.windows.net/datasets/" - urlretrieve(data_url + filename, filename) - http_stream = gzip.GzipFile(filename=filename, mode='rb') - - with closing(http_stream): - def _stream_generator(response): - for line in response: - yield line.decode('utf-8') - - stream = _stream_generator(http_stream) - data = arff.load(stream) + remaining_attempts = 5 + sleep_duration = 10 + while remaining_attempts > 0: + try: + urlretrieve(data_url + filename, filename) + + http_stream = gzip.GzipFile(filename=filename, mode='rb') + + with closing(http_stream): + def _stream_generator(response): + for line in response: + yield line.decode('utf-8') + + stream = _stream_generator(http_stream) + data = arff.load(stream) + except Exception as exc: # noqa: B902 + remaining_attempts -= 1 + print("Error downloading dataset from {} ({} attempt(s) remaining)" + .format(data_url, remaining_attempts)) + print(exc) + sleep(sleep_duration) + sleep_duration *= 2 + continue + else: + # dataset successfully downloaded + break + else: + raise Exception("Could not retrieve dataset from {}.".format(data_url)) attributes = OrderedDict(data['attributes']) arff_columns = list(attributes) - raw_df = pd.DataFrame(data=data['data'], columns=arff_columns) target_column_name = 'class' diff --git a/how-to-use-azureml/track-and-monitor-experiments/logging-api/logging-api.ipynb b/how-to-use-azureml/track-and-monitor-experiments/logging-api/logging-api.ipynb index adb4184da..0204c0d9c 100644 --- a/how-to-use-azureml/track-and-monitor-experiments/logging-api/logging-api.ipynb +++ b/how-to-use-azureml/track-and-monitor-experiments/logging-api/logging-api.ipynb @@ -100,7 +100,7 @@ "\n", "# Check core SDK version number\n", "\n", - "print(\"This notebook was created using SDK version 1.28.0, you are currently running version\", azureml.core.VERSION)" + "print(\"This notebook was created using SDK version 1.29.0, you are currently running version\", azureml.core.VERSION)" ] }, { diff --git a/index.md b/index.md index 5bd4ddf36..d4fad6e44 100644 --- a/index.md +++ b/index.md @@ -25,6 +25,7 @@ Machine Learning notebook samples and encourage efficient retrieval of topics an | [Forecasting away from training data](https://github.com/Azure/MachineLearningNotebooks/blob/master//how-to-use-azureml/automated-machine-learning/forecasting-forecast-function/auto-ml-forecasting-function.ipynb) | Forecasting | None | Remote | None | Azure ML AutoML | Forecasting, Confidence Intervals | | [Automated ML run with basic edition features.](https://github.com/Azure/MachineLearningNotebooks/blob/master//how-to-use-azureml/automated-machine-learning/classification-bank-marketing-all-features/auto-ml-classification-bank-marketing-all-features.ipynb) | Classification | Bankmarketing | AML | ACI | None | featurization, explainability, remote_run, AutomatedML | | [Classification of credit card fraudulent transactions using Automated ML](https://github.com/Azure/MachineLearningNotebooks/blob/master//how-to-use-azureml/automated-machine-learning/classification-credit-card-fraud/auto-ml-classification-credit-card-fraud.ipynb) | Classification | Creditcard | AML Compute | None | None | remote_run, AutomatedML | +| [Classification of credit card fraudulent transactions using Automated ML](https://github.com/Azure/MachineLearningNotebooks/blob/master//how-to-use-azureml/automated-machine-learning/experimental/classification-credit-card-fraud-local-managed/auto-ml-classification-credit-card-fraud-local-managed.ipynb) | Classification | Creditcard | AML Compute | None | None | AutomatedML | | [Automated ML run with featurization and model explainability.](https://github.com/Azure/MachineLearningNotebooks/blob/master//how-to-use-azureml/automated-machine-learning/regression-explanation-featurization/auto-ml-regression-explanation-featurization.ipynb) | Regression | MachineData | AML | ACI | None | featurization, explainability, remote_run, AutomatedML | | :star:[Azure Machine Learning Pipeline with DataTranferStep](https://github.com/Azure/MachineLearningNotebooks/blob/master//how-to-use-azureml/machine-learning-pipelines/intro-to-pipelines/aml-pipelines-data-transfer.ipynb) | Demonstrates the use of DataTranferStep | Custom | ADF | None | Azure ML | None | | [Getting Started with Azure Machine Learning Pipelines](https://github.com/Azure/MachineLearningNotebooks/blob/master//how-to-use-azureml/machine-learning-pipelines/intro-to-pipelines/aml-pipelines-getting-started.ipynb) | Getting Started notebook for ANML Pipelines | Custom | AML Compute | None | Azure ML | None | diff --git a/setup-environment/configuration.ipynb b/setup-environment/configuration.ipynb index d6de070f5..295f85148 100644 --- a/setup-environment/configuration.ipynb +++ b/setup-environment/configuration.ipynb @@ -102,7 +102,7 @@ "source": [ "import azureml.core\n", "\n", - "print(\"This notebook was created using version 1.28.0 of the Azure ML SDK\")\n", + "print(\"This notebook was created using version 1.29.0 of the Azure ML SDK\")\n", "print(\"You are currently using version\", azureml.core.VERSION, \"of the Azure ML SDK\")" ] },