Analyze model fairness with Fairlearn

Analyze model fairness with Fairlearn

Fairlearn is a Python package that you can use to analyze models and evaluate the disparity between predictions and prediction performance for one or more sensitive features.

It works by calculating group metrics for the sensitive features you specify. The metrics themselves are based on standard scikit-learn model evaluation metrics, such as accuracyprecision, or recall for classification models.

The Fairlearn API is extensive, offering multiple ways to explore disparity in metrics across sensitive feature groupings. For a binary classification model, you might start by comparing the selection rate (the number of positive predictions for each group) by using the selection_rate function. This function returns the overall selection rate for the test dataset. You can also use standard sklearn.metrics functions (such as  accuracy_score, precision_score, or recall_score) to get an overall view of how the model performs.

Then, you can define one or more sensitive features in your dataset with which you want to group subsets of the population and compare selection rate and predictive performance. Fairlearn includes a MetricFrame function that enables you to create a dataframe of multiple metrics by the group.

For example, in a binary classification model for loan repayment prediction, where the sensitive feature Age consists of two possible categorical values (25-and-under and over-25), a MetricFrame for these groups might be similar to the following table:

No alt text provided for this image

Visualizing metrics in a dashboard

It's often easier to compare metrics visually, so Fairlearn provides an interactive dashboard widget that you can use in a notebook to display group metrics for a model. The widget enables you to choose a sensitive feature and performance metric to compare, and then calculates and visualizes the metrics and disparity, like this:

No alt text provided for this image
No alt text provided for this image

Integration with Azure Machine Learning

Fairlearn integrates with Azure Machine Learning by enabling you to run an experiment in which the dashboard metrics are uploaded to your Azure Machine Learning workspace. This enables you to share the dashboard in Azure Machine Learning studio so that your data science team can track and compare disparity metrics for models registered in the workspace.

Sources

Microsoft Learn

#modelling #datascience #machinelearning

Article By Devansh Mistry

LinkedIn                           GitHub                               Devansh Mistry

To view or add a comment, sign in

More articles by Devansh Vinodkumar Mistry

  • Building AI? Remember: "Friendly Robots Include People That Act Right"

    As software engineers and tech leaders, we aren't just building code; we are building trust. With AI integrating into…

  • Fail Fast, Learn Faster: The Power of Early Failure in Agile Projects

    In the fast-paced world of Agile, embracing failure might seem counterintuitive. However, the ability to fail early and…

  • Reinforcement Learning

    Reinforcement learning is a type of machine learning in which an artificial intelligence (AI) agent learns to make…

  • Activation Functions

    In machine learning, an "activation function" is a function that is applied to the output of a neuron in a neural…

  • ML Algorithms Explained in Less Than 1 Minute Each

    Linear Regression One of the simplest Machine learning algorithms out there, Linear Regression is used to make…

  • Core Roles in the World of Data

    Large data projects can be complex. The projects often involve hundreds of decisions.

  • Job Roles in the World of Data

    Over the last decade, the amount of data that systems and devices generate has increased significantly. Because of this…

  • What is Machine Learning?

    Machine learning is a technique that uses mathematics and statistics to create a model that can predict unknown values.…

Others also viewed

Explore content categories