#!/usr/bin/env python # coding: utf-8 # # Getting Started # ## Installation # Use the following `pip` commands to install the Responsible AI Toolbox. # In[ ]: get_ipython().system('pip install raiwidgets') # ## Dependencies # In[ ]: get_ipython().system('pip install --upgrade pandas') # ## Overview & Setup # 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. # In[ ]: 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. # In[ ]: 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: # In[ ]: 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. # In[ ]: 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. # In[ ]: 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. # In[ ]: rai_insights.counterfactual.add(total_CFs=20, desired_range=[10, 20], continuous_features=['f1', 'f2', 'f3']) # ## Computing and Visualizing Insights # After loading the components into the RAIInsights object, it is necessary to calculate values relevant to them, such as model metrics and counterfactuals. # In[ ]: rai_insights.compute() # Once the values for each component have been computed, they can be displayed by loading the RAIInsights object into a ResponsibleAIDashboard. # In[ ]: ResponsibleAIDashboard(rai_insights) # ## Learn More # Visit the [GitHub](https://github.com/microsoft/responsible-ai-widgets) of Responsible AI Toolbox for more details, and take this [dashboard tour](./tour.ipynb) for an explanation of the different parts of each component.