From 60d8870d1db82cc5c65bb6f2f4b0ad5559e58805 Mon Sep 17 00:00:00 2001 From: tongy-msft <91754176+tongyu-microsoft@users.noreply.github.com> Date: Tue, 17 Jan 2023 16:35:35 -0800 Subject: [PATCH] Update some sample notebooks to include dropped_features (#1911) * update some notebooks to include dropped_features * update some notebooks to include dropped_features * update some notebooks to include dropped_features * remove unused changes * remove unused changes * address comments * address comment --- .../getting-started.ipynb | 11 ++++++-- ...aidashboard-diabetes-decision-making.ipynb | 27 ++++++++++++++++--- 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/notebooks/responsibleaidashboard/getting-started.ipynb b/notebooks/responsibleaidashboard/getting-started.ipynb index c48cedb4fe..6da4edebac 100644 --- a/notebooks/responsibleaidashboard/getting-started.ipynb +++ b/notebooks/responsibleaidashboard/getting-started.ipynb @@ -110,7 +110,9 @@ "source": [ "It is necessary to initialize a RAIInsights object upon which the different components can be loaded. `task_type` holds the string `'regression'` or `'classification'` depending on the developer's purpose.\n", "\n", - "Users can also specify categorical features via the `categorical_features` parameter." + "Users can also specify categorical features via the `categorical_features` parameter.\n", + "\n", + "Using the `FeatureMetadata` container, you can declare an `identity_feature`, and specify features to withhold from the model via the `dropped_features` parameter. The `FeatureMetadata` serves as an input argument for `RAIInsights`." ] }, { @@ -119,8 +121,13 @@ "metadata": {}, "source": [ "```Python\n", + "from responsibleai.feature_metadata import FeatureMetadata\n", + "# Add 's1' as an identity feature, set 'age' as a dropped feature\n", + "feature_metadata = FeatureMetadata(identity_feature_name='s1', dropped_features=['age'])\n", + "\n", "task_type = 'regression'\n", - "rai_insights = RAIInsights(model, train_data, test_data, target_feature, task_type)\n", + "\n", + "rai_insights = RAIInsights(model, train_data, test_data, target_feature, task_type, categorical_features=[], feature_metadata=feature_metadata)\n", "```" ] }, diff --git a/notebooks/responsibleaidashboard/responsibleaidashboard-diabetes-decision-making.ipynb b/notebooks/responsibleaidashboard/responsibleaidashboard-diabetes-decision-making.ipynb index 52ca030b82..61d6f9e482 100644 --- a/notebooks/responsibleaidashboard/responsibleaidashboard-diabetes-decision-making.ipynb +++ b/notebooks/responsibleaidashboard/responsibleaidashboard-diabetes-decision-making.ipynb @@ -114,6 +114,25 @@ "data.feature_names" ] }, + { + "cell_type": "markdown", + "id": "46119282", + "metadata": {}, + "source": [ + "You may define `features_to_drop` and drop any features from `X_train`. The model will be trained without `features_to_drop`. If `features_to_drop` is not set, `X_train_after_drop` will be the same as `X_train`." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "3db1ef3b", + "metadata": {}, + "outputs": [], + "source": [ + "features_to_drop = []\n", + "X_train_after_drop = X_train.drop(features_to_drop, axis=1)" + ] + }, { "cell_type": "markdown", "id": "59853607", @@ -130,7 +149,7 @@ "outputs": [], "source": [ "model = RandomForestRegressor(random_state=0)\n", - "model.fit(X_train, y_train)" + "model.fit(X_train_after_drop, y_train)" ] }, { @@ -161,7 +180,7 @@ "\n", "RAIInsights accepts the model, the train dataset, the test dataset, the target feature string, the task type string, and a list of strings of categorical feature names as its arguments.\n", "\n", - "You may also create the `FeatureMetadata` container and identify any feature of your choice as the `identity_feature`. The `FeatureMetadata` may also be passed into the `RAIInsights`." + "You may also create the `FeatureMetadata` container, identify any feature of your choice as the `identity_feature`, and specify dropped features via the `dropped_features` parameter. The `FeatureMetadata` may also be passed into the `RAIInsights`." ] }, { @@ -172,8 +191,8 @@ "outputs": [], "source": [ "from responsibleai.feature_metadata import FeatureMetadata\n", - "# Add 's1' as an identity feature\n", - "feature_metadata = FeatureMetadata(identity_feature_name='s1')\n", + "# Add 's1' as an identity feature, set features_to_drop as dropped features\n", + "feature_metadata = FeatureMetadata(identity_feature_name='s1', dropped_features=features_to_drop)\n", "rai_insights = RAIInsights(model, train_data, test_data, target_feature, 'regression',\n", " categorical_features=[], feature_metadata=feature_metadata)" ]