Skip to content

Commit

Permalink
Update some sample notebooks to include dropped_features (microsoft#1911
Browse files Browse the repository at this point in the history
)

* 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
  • Loading branch information
tongyu-microsoft authored Jan 18, 2023
1 parent 9d24ea2 commit 60d8870
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
11 changes: 9 additions & 2 deletions notebooks/responsibleaidashboard/getting-started.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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`."
]
},
{
Expand All @@ -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",
"```"
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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)"
]
},
{
Expand Down Expand Up @@ -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`."
]
},
{
Expand All @@ -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)"
]
Expand Down

0 comments on commit 60d8870

Please sign in to comment.