# 1.7 什么时候该改变开发/测试集和指标？（When to change dev/test sets and metrics）

算法模型的评价标准有时候需要根据实际情况进行动态调整，目的是让算法模型在实际应用中有更好的效果

## **example1**

假设有两个猫的图片的分类器：

* 评估指标：分类错误率
* 算法A：3%错误率
* 算法B：5%错误率

初始的评价标准是错误率，A更好一些。实际使用时发现算法A会通过一些色情图片，但是B没有。从用户的角度来说，更倾向选择B模型，虽然B的错误率高一些。这时候需要改变之前只使用错误率作为评价标准，考虑新的情况进行改变。如增加色情图片的权重，增加其代价

假设开始的评估指标如下：

$$
Error = \dfrac{1}{m\_{dev}}\sum\limits\_{i=1}^{m\_{dev}}I{y^{(i)}\_{pred}\neq y^{(i)}}
$$

该评估指标对色情图片和非色情图片一视同仁

修改的方法，在其中加入权重$$w^{(i)}$$：

$$
Error = \dfrac{1}{\sum w^{(i)}}\sum\limits\_{i=1}^{m\_{dev}} w^{(i)}I{y^{(i)}\_{pred}\neq y^{(i)}}
$$

$$
w^{(i)}=\begin{cases}
1, & x^{(i)}\ is\ non-porn\\
10 \ or\ 100, & x^{(i)}\ is\ porn
\end{cases}
$$

通过设置权重，当算法将色情图片分类为猫时，误差项会快速变大

概括来说，机器学习可分为两个过程：

* **Define a metric to evaluate classifiers**
* **How to do well on this metric**

第一步是找靶心，第二步是通过训练，射中靶心。但是在训练的过程中可能会根据实际情况改变算法模型的评价标准，进行动态调整,如果评估指标无法正确评估算法的排名，则需要重新定义一个新的评估指标

## **example2**

对example1中的两个不同的猫图片的分类器A和B：

![](/files/-Le0cXjhwCZPjNO70hkI)

实际情况是一直使用网上下载的高质量的图片进行训练；当部署到手机上时，由于图片的清晰度及拍照水平的原因，当实际测试算法时，会发现算法B的表现其实更好

如果在训练开发测试的过程中得到的模型效果比较好，但是在实际应用中所真正关心的问题效果却不好的时候，就需要改变开发、测试集或者评估指标

**Guideline：**

1. 定义正确的评估指标来更好的给分类器的好坏进行排序
2. 优化评估指标

![](/files/-Le0cXjjgWs9L_zkLLlw)![](/files/-Le0cXjl-Pw7ajFMj3tO)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://baozoulin.gitbook.io/neural-networks-and-deep-learning/di-san-men-ke-jie-gou-hua-ji-qi-xue-xi-xiang-mu-structuring-machine-learning-projects/di-san-men-ke-structuring-machine-learning-projects/di-yi-zhou-ml-strategy/17-shi-yao-shi-hou-gai-gai-bian-kai-53d1-ce-shi-ji-he-zhi-biao-ff1f-ff08-when-to-change-dev-test-set.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
