# Sensitivity

May 20, 2023

Sensitivity is a crucial concept in both AI and machine learning. It refers to how much a model’s output changes with small changes in its input. This is an important metric when evaluating the performance of an AI or machine learning model, as it can inform how robust and reliable the model is.

## Defining Sensitivity

Sensitivity is often defined as the derivative of a model’s output with respect to its input. In other words, it measures how much the output of a model changes as the input changes. Sensitivity can be positive or negative, depending on whether the output increases or decreases as the input changes.

## Importance of Sensitivity

Sensitivity is an important metric to consider when evaluating the accuracy and reliability of a model. A low sensitivity means that the model’s output is relatively stable, even with small changes in the input. This can be desirable in situations where the input is subject to noise or other sources of variability. A high sensitivity, on the other hand, means that the model’s output is highly sensitive to small changes in the input. This can lead to instability and errors in the model’s predictions.

## Sensitivity in Machine Learning

In machine learning, sensitivity is often used to evaluate the performance of a model. For example, in a classification problem, sensitivity measures how well the model correctly identifies positive instances of a particular class. This is also known as the true positive rate.

Consider a binary classification problem, where the model is trying to predict whether an email is spam or not. Sensitivity measures how well the model correctly identifies spam emails. A high sensitivity means that the model is good at correctly identifying spam emails, while a low sensitivity means that the model is more likely to miss spam emails and classify them as non-spam.

## Sensitivity in AI

In AI, sensitivity is often used to evaluate the robustness of a model to various types of input. For example, in computer vision, sensitivity can be used to measure how well a model can recognize objects in different lighting conditions or from different angles.

Consider an AI model that is designed to recognize faces. Sensitivity can be used to evaluate how well the model can recognize faces from different angles, or with changes in lighting or facial expressions. A high sensitivity means that the model is more robust and can recognize faces in a wide range of conditions, while a low sensitivity means that the model is more likely to make errors in recognizing faces under different conditions.

## Example Code

To get a better understanding of how sensitivity works, let’s consider a simple example using Python code. Suppose we have a model that takes a single input x and outputs a value y, given by the equation y = 2x. We can define this model in Python as follows:

```
def model(x):
return 2 * x
```

We can then calculate the sensitivity of this model by computing the derivative of its output with respect to its input:

```
def sensitivity(x):
h = 0.0001
return (model(x + h) - model(x)) / h
```

Here, we are using a numerical approximation to calculate the derivative, by computing the difference between the output of the model for a small change in the input.

We can test this code by evaluating the sensitivity of the model at a particular value of x, say x = 2:

```
>>> sensitivity(2)
2.000000000000002
```

This tells us that the output of the model changes by approximately 2 for every unit change in the input. This is what we would expect, given that the model is defined by the equation y = 2x.