diff --git a/how-to-use-azureml/explain-model/explain-tabular-data-raw-features/explain-sklearn-raw-features.ipynb b/how-to-use-azureml/explain-model/explain-tabular-data-raw-features/explain-sklearn-raw-features.ipynb index af44afb8..d5ff0a66 100644 --- a/how-to-use-azureml/explain-model/explain-tabular-data-raw-features/explain-sklearn-raw-features.ipynb +++ b/how-to-use-azureml/explain-model/explain-tabular-data-raw-features/explain-sklearn-raw-features.ipynb @@ -29,6 +29,22 @@ "4. Visualize the global and local explanations with the visualization dashboard." ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "This example needs sklearn-pandas. If it is not installed, uncomment and run the following line." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "#!pip install sklearn-pandas" + ] + }, { "cell_type": "code", "execution_count": null, @@ -39,7 +55,7 @@ "from sklearn.impute import SimpleImputer\n", "from sklearn.preprocessing import StandardScaler, OneHotEncoder\n", "from sklearn.linear_model import LogisticRegression\n", - "from azureml.contrib.explain.model.tabular_explainer import TabularExplainer\n", + "from azureml.explain.model.tabular_explainer import TabularExplainer\n", "from sklearn_pandas import DataFrameMapper\n", "import pandas as pd\n", "import numpy as np" @@ -101,16 +117,19 @@ "from sklearn.preprocessing import StandardScaler, OneHotEncoder\n", "from sklearn_pandas import DataFrameMapper\n", "\n", - "# Impute and standardize the numeric features\n", - "numeric_transformations = [([f], Pipeline(steps=[\n", - " ('imputer', SimpleImputer(strategy='median')),\n", - " ('scaler', StandardScaler())])) for f in numeric_features]\n", - " \n", - "# One hot encode the categorical features \n", - "categorical_transformations = [([f], OneHotEncoder(handle_unknown='ignore', sparse=False)) for f in categorical_features]\n", + "# Impute, standardize the numeric features and one-hot encode the categorical features. \n", "\n", + "transformations = [\n", + " ([\"age\", \"fare\"], Pipeline(steps=[\n", + " ('imputer', SimpleImputer(strategy='median')),\n", + " ('scaler', StandardScaler())\n", + " ])),\n", + " ([\"embarked\"], Pipeline(steps=[\n", + " (\"imputer\", SimpleImputer(strategy='constant', fill_value='missing')), \n", + " (\"encoder\", OneHotEncoder(sparse=False))])),\n", + " ([\"sex\", \"pclass\"], OneHotEncoder(sparse=False)) \n", + "]\n", "\n", - "transformations = numeric_transformations + categorical_transformations\n", "\n", "# Append classifier to preprocessing pipeline.\n", "# Now we have a full prediction pipeline.\n", @@ -231,13 +250,6 @@ "source": [ "ExplanationDashboard(global_explanation, model, x_test)" ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] } ], "metadata": {