auc¶
- paddle.static. 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:
ROC: Receiver operating characteristic;
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 numpy as np import paddle import paddle.static as static import paddle.nn.functional as F paddle.enable_static() data = static.data(name="input", shape=[-1, 32,32], dtype="float32") label = static.data(name="label", shape=[-1], dtype="int") fc_out = static.nn.fc(x=data, size=2) predict = F.softmax(x=fc_out) result = static.auc(input=predict, label=label) place = paddle.CPUPlace() exe = static.Executor(place) exe.run(static.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.])]