# 模型评估¶

## 常用指标¶

AUC(Area Under Cure)指标则常被用在分类任务(classification)上

```import paddle.fluid as fluid
import numpy as np

metric = fluid.metrics.Precision()

# generate the preds and labels

preds = [[0.1], [0.7], [0.8], [0.9], [0.2],
[0.2], [0.3], [0.5], [0.8], [0.6]]

labels = [[0], [1], [1], [1], [1],
[0], [0], [0], [0], [0]]

preds = np.array(preds)
labels = np.array(labels)

metric.update(preds=preds, labels=labels)
numpy_precision = metric.eval()

print("expect precision: %.2f and got %.2f" % (3.0 / 5.0, numpy_precision))
```

## 自定义指标¶

Fluid支持自定义指标，可灵活支持各类计算任务。下面是一个自定义的简单计数器评价函数示例:

```class MyMetric(MetricBase):
def __init__(self, name=None):
super(MyMetric, self).__init__(name)
self.counter = 0  # simple counter

def reset(self):
self.counter = 0

def update(self, preds, labels):
if not _is_numpy_(preds):
raise ValueError("The 'preds' must be a numpy ndarray.")
if not _is_numpy_(labels):
raise ValueError("The 'labels' must be a numpy ndarray.")
self.counter += sum(preds == labels)

def eval(self):
return self.counter
```