auc

paddle.fluid.layers.auc(input, label, curve='ROC', num_thresholds=4095, topk=1, slide_steps=1)[source]

Area Under the Curve (AUC) Layer

This implementation computes the AUC according to forward output and label. It is used very widely in binary classification evaluation.

Note: If input label contains values other than 0 and 1, it will be cast to bool. Find the relevant definitions here.

There are two types of possible curves:

  1. ROC: Receiver operating characteristic;

  2. PR: Precision Recall

Parameters
  • input (Variable) – A floating-point 2D Variable, values are in the range [0, 1]. Each row is sorted in descending order. This input should be the output of topk. Typically, this Variable indicates the probability of each label. A LoDTensor or Tensor with type float32,float64.

  • label (Variable) – A 2D int Variable indicating the label of the training data. The height is batch size and width is always 1. A LoDTensor or Tensor with type int32,int64.

  • curve (str) – Curve type, can be ‘ROC’ or ‘PR’. Default ‘ROC’.

  • num_thresholds (int) – The number of thresholds to use when discretizing the roc curve. Default 200.

  • topk (int) – only topk number of prediction output will be used for auc.

  • slide_steps – when calc batch auc, we can not only use step currently but the previous steps can be used. slide_steps=1 means use the current step, slide_steps=3 means use current step and the previous second steps, slide_steps=0 use all of the steps.

Returns

A tuple representing the current AUC. The return tuple is auc_out, batch_auc_out, [ batch_stat_pos, batch_stat_neg, stat_pos, stat_neg ] Data type is Tensor, supporting float32, float64.

Return type

Variable

Examples

import paddle.fluid as fluid
import numpy as np

data = fluid.data(name="input", shape=[-1, 32,32], dtype="float32")
label = fluid.data(name="label", shape=[-1], dtype="int")
fc_out = fluid.layers.fc(input=data, size=2)
predict = fluid.layers.softmax(input=fc_out)
result=fluid.layers.auc(input=predict, label=label)

place = fluid.CPUPlace()
exe = fluid.Executor(place)

exe.run(fluid.default_startup_program())
x = np.random.rand(3,32,32).astype("float32")
y = np.array([1,0,1])
output= exe.run(feed={"input": x,"label": y},
                 fetch_list=[result[0]])
print(output)
#[array([0.5])]