TDD在机器学习中的优势 [英] Benefits of TDD in machine learning

查看:117
本文介绍了TDD在机器学习中的优势的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据我所知,TDD的典型工作流程基于黑盒测试. 首先,我们定义接口,然后编写一个或一组测试,然后实现通过所有测试的代码. 因此,请看下面的示例:

As far as I know typical workflow of TDD is based on black box testing. First we define interface then write one or set of test and then we implement code that pass all tests. So look at the example below:

from abc import ABCMeta


class InterfaceCalculator:
    __metaclass__ = ABCMeta

    @abstractmethod
    def calculate_mean(self):
        pass

示例性测试用例

from unittest import TestCase


class TestInterfaceCalculator(TestCase):

    def test_should_correctly_calcluate_mean(self):
        X=[1,1]
        expected_mean = 1
        calcluator =Calculator()
        self.assertAlmostEqual(calculator.calculate_mean(X), expected_mean) 

我跳过了类Calculator(InterfaceCalculator)的实现,因为它是微不足道的.

I skip implementation of the class Calculator(InterfaceCalculator) because it is trivial.

以下想法很容易理解.机器学习怎么样? 让我们考虑以下示例.我们想实现猫,狗的照片分类器.从界面开始.

The following idea is pretty easy to understand. How about Machine Learning? Let consider the following example. We would like to implement cat, dog photo classifier. Start from the interface.

from abc import ABCMeta


class InterfaceClassifier:
    __metaclass__ = ABCMeta

    @abstractmethod
    def train_model(self, data):
        pass

    @abstractmethod
    def predict(self, data):
        pass

我准备了很多单元测试

from unittest import TestCase


class TestInterfaceCalculator(TestCase):
    def __init__(self):
        self.model = CatDogClassifier()

    def test_should_correctly_train_model(self, data):
        """
        How can be implemented?
        """
        self.model.train_model(data)

    def test_should_correctly_calcluate_mean(self):
        input ="cat.jpg"
        expected_result = "cat"
        calcluator =.assertAlmostEqual(self.model.preditct(input), expected_result)

这是使用TDD帮助研究机器学习模型的方法吗?或在这种情况下,TDD是无用的.它只能帮助我们验证输入数据的正确性,并为训练后的模型添加非常高级的测试吗?如何创建良好的自动测试?

Is it the way to use TDD to help work on machine learning model? Or In this case TDD is useless. It, only can help us to verify correctness of input data and add very high level test of the trained model? How can I create good automatic tests?

推荐答案

使用TDD,您可以以测试的形式描述预期的行为,然后创建满足测试要求的代码.尽管这对于您的机器学习模型的某些组件可以很好地工作,但是对于机器学习模型的高级行为,通常却不能很好地工作,因为事先无法确切知道预期的行为.开发机器学习模型的过程通常涉及尝试不同的方法,以查看哪种方法最有效.该行为很可能用百分比来衡量,例如,识别的准确度是95%,而不是绝对的.

With TDD, you describe the expected behavior in the form of a test and then create the code to satisfy the test. While this can work well for some components of your machine learning model, it usually doesn't work well for the high-level behavior of a machine learning model, because the expected behavior is not precisely known in advance. The process of developing a machine learning model often involves trying different approaches to see which one is most effective. The behavior is likely to be measured in terms of percentages, e,g, recognition is 95% accurate, rather than absolutes.

这篇关于TDD在机器学习中的优势的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆