This getting started notebook is an overview of the functionality in this repository. Note that this notebook is not runnable, it has a high-level overview of the APIs available and contains links to other notebooks in the repository.
Use the following pip
commands to install the Responsible AI Toolbox.
If running in jupyter, please make sure to restart the jupyter kernel after installing.
!pip install raiwidgets
Please make sure to have the latest version of pandas installed if you are planning to use the error analysis component.
!pip install --upgrade pandas
Responsible AI Toolbox is an interoperable, customizable tool that empowers machine learning practitioners to evaluate their models and data based on their place in the model lifecycle.
Users may select components whose functionality supports their current objectives. First, the RAIInsights and ResponsibleAIDashboard must be imported.
from raiwidgets import ResponsibleAIDashboard
from responsibleai import RAIInsights
Users will need to load a dataset, split it into train and test datasets, and train a model on the training dataset.
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.
Users can also specify categorical features via the categorical_features
parameter.
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
.
from responsibleai.feature_metadata import FeatureMetadata
# Add 's1' as an identity feature, set 'age' as a dropped feature
feature_metadata = FeatureMetadata(identity_feature_name='s1', dropped_features=['age'])
task_type = 'regression'
rai_insights = RAIInsights(model, train_data, test_data, target_feature, task_type, categorical_features=[], feature_metadata=feature_metadata)
The Interpretability and Error Analysis components can be added to the dashboard without any additional arguments.
For an example, please see the census classification model debugging notebook.
rai_insights.explainer.add()
rai_insights.error_analysis.add()
The Causal Inferencing component must be added with a specification of the feature that would be changed as a treatment.
For an example, please see the diabetes decision making notebook.
rai_insights.causal.add(treatment_features=['bmi', 'bp', 's2'])
The Counterfactuals component takes arguments specifying the number of counterfactuals to generate, the list of columns containing continuous values, and the desired label of the counterfactuals.
In a classification situation, desired_class
must specify the classification that the generated counterfactuals would fall into.
For an example, please see the housing classification model debugging notebook.
rai_insights.counterfactual.add(total_CFs=20, desired_class='opposite')
In a regression situation, desired_range
must specify the minimum and maximum label that the generated counterfactuals can have.
For an example, please see the diabetes regression model debugging notebook.
rai_insights.counterfactual.add(total_CFs=20, desired_range=[50, 120])
After loading the components into the RAIInsights object, it is necessary to calculate values relevant to them, such as model metrics and counterfactuals.
rai_insights.compute()
Once the values for each component have been computed, they can be displayed by loading the RAIInsights object into a ResponsibleAIDashboard.
ResponsibleAIDashboard(rai_insights)
Visit the GitHub of Responsible AI Toolbox for more details, and take this dashboard tour for an explanation of the different parts of each component.