# Metrics

## True/False Positive/Negatives

The methods to compute True/False Positive/Negative values should be implemented by the students. To this end, they receive the actual values `y_true` and predicted values `y_pred`, both as a `numpy.array` that are `+1` for known values and `-1` for anomalous values.

`Assignment.``TP`(y_true, y_pred)

  Computes the number of True Positives for given y_true and y_pred.

  Parameters

    - y_true (array-like of shape=(n_samples,)) – True values corresponding to each prediction.

    - y_pred (array-like of shape=(n_samples,)) – Predicted values corresponding to each true value.

  Returns

    result – Number of True Positives.

  Return type

    int

`Assignment.``TN`(y_true, y_pred)

  Computes the number of True Negatives for given y_true and y_pred.

  Parameters

    - y_true (array-like of shape=(n_samples,)) – True values corresponding to each prediction.

    - y_pred (array-like of shape=(n_samples,)) – Predicted values corresponding to each true value.

  Returns

    result – Number of True Negatives.

  Return type

    int

`Assignment.``FP`(y_true, y_pred)

  Computes the number of False Positives for given y_true and y_pred.

  Parameters

    - y_true (array-like of shape=(n_samples,)) – True values corresponding to each prediction.

    - y_pred (array-like of shape=(n_samples,)) – Predicted values corresponding to each true value.

  Returns

    result – Number of False Positives.

  Return type

    int

`Assignment.``FN`(y_true, y_pred)

  Computes the number of False Negatives for given y_true and y_pred.

  Parameters

    - y_true (array-like of shape=(n_samples,)) – True values corresponding to each prediction.

    - y_pred (array-like of shape=(n_samples,)) – Predicted values corresponding to each true value.

  Returns

    result – Number of False Negatives.

  Return type

    int

## Test

To test the implementations of True/False Positive/Negative values, we provide test cases using the function `test_metrics()`.

`Assignment.``test_metrics`(verbose=False)

  Test whether the computed metrics are correct.

## Metric implementations

Based on the student impelmentations, we compute the following metrics:

`Assignment.``TPR`(y_true, y_pred)

  True positive rate.

`Assignment.``TNR`(y_true, y_pred)

  True negative rate.

`Assignment.``FPR`(y_true, y_pred)

  False positive rate.

`Assignment.``FNR`(y_true, y_pred)

  False negative rate.

`Assignment.``accuracy`(y_true, y_pred)

  Accuracy.

`Assignment.``precision`(y_true, y_pred)

  Precision.

`Assignment.``recall`(y_true, y_pred)

  Recall.

`Assignment.``f1_score`(y_true, y_pred)

  F1-score.

## Results

We provide functions to compute all metrics, and show them using `show_report()`.

`Assignment.``prediction_report`(y_true, y_pred)

  Computes prediction metrics and prints them.

  Parameters

    - y_true (array-like of shape=(n_samples,)) – True values corresponding to each prediction.

    - y_pred (array-like of shape=(n_samples,)) – Predicted values corresponding to each true value.

`Assignment.``show_report`(tpr, tnr, fpr, fnr, accuracy, precision, recall, f1_score)

  Prints prediction report.

  Parameters

    - tpr (float) – True Positive Rate to show.

    - tnr (float) – True Negative Rate to show.

    - fpr (float) – False Positive Rate to show.

    - fnr (float) – False Negative Rate to show.

    - accuracy (float) – Accuracy to show.

    - precision (float) – Precision to show.

    - recall (float) – Recall to show.

    - f1_score (float) – F1-score to show.