Use the following pip
commands to install the Responsible AI Toolbox.
!pip install raiwidgets
!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, import the relevant objects.
from raiwidgets import ResponsibleAIDashboard
from responsibleai import RAIInsights
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.
rai_insights = RAIInsights(model, train_data, test_data, target_feature, task_type,
categorical_features=['f1', 'f2', 'f3'])
The Interpretability and Error Analysis components can be added to the dashboard without any additional arguments:
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.
rai_insights.causal.add(treatment_features=['f1', 'f2', 'f3'])
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.
rai_insights.counterfactual.add(total_CFs=20, desired_class='opposite', continuous_features=['f1', 'f2', 'f3'])
In a regression situation, desired_range
must specify the minimum and maximum label that the generated counterfactuals can have.
rai_insights.counterfactual.add(total_CFs=20, desired_range=[10, 20], continuous_features=['f1', 'f2', 'f3'])
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.