假设我在处理一些分类问题。(欺诈检测和评论垃圾邮件是我目前正在处理的两个问题,但我对一般的分类任务很好奇。)

我如何知道我应该使用哪个分类器?

决策树 支持向量机 贝叶斯 神经网络 再邻居 q学习的 遗传算法 马尔可夫决策过程 卷积神经网络 线性回归或逻辑回归 提升,装袋,取样 随机爬坡或模拟退火 ...

在哪些情况下,其中一个是“自然的”第一选择,选择它的原则是什么?

我正在寻找的答案类型的例子(来自Manning等人的信息检索介绍书):

a.如果你的数据被标记了,但你只有有限的数量,你应该使用高偏差的分类器(例如,朴素贝叶斯)。

我猜这是因为高偏差分类器会有更低的方差,这是很好的,因为数据量小。

b.如果你有大量的数据,那么分类器真的不那么重要,所以你可能应该选择一个具有良好可扩展性的分类器。

其他指导方针是什么?甚至像“如果你必须向一些高层管理人员解释你的模型,那么也许你应该使用决策树,因为决策规则是相当透明的”这样的回答也是很好的。不过,我不太关心实现/库问题。 另外,对于一个有点独立的问题,除了标准的贝叶斯分类器,是否有“标准的最先进的”方法来检测评论垃圾邮件(而不是电子邮件垃圾邮件)?


我的看法是,你总是首先运行基本的分类器来了解你的数据。通常情况下(至少在我的经验中),他们已经足够好了。

所以,如果你有监督数据,训练朴素贝叶斯分类器。如果有无监督数据,可以尝试k-均值聚类。

另一个资源是斯坦福机器学习系列视频中的一个讲座视频,我之前看过。在视频4或5中,我认为,讲师讨论了训练分类器时的一些普遍接受的惯例,优点/权衡等。


使用交叉验证的模型选择可能是您所需要的。

交叉验证

你要做的就是简单地把你的数据集分成k个不重叠的子集(折叠),用k-1次折叠来训练一个模型,并用你遗漏的折叠来预测它的性能。对每一种可能的折叠组合都要这样做(首先保留第1次折叠,然后是第2次,……,然后是k,用剩下的折叠进行训练)。完成后,估计所有折叠的平均性能(也可能是性能的方差/标准偏差)。

如何选择参数k取决于你拥有的时间。k的通常值是3、5、10甚至N,其中N是数据的大小(这与省略一个交叉验证相同)。我更喜欢5到10个。

模型选择

假设你有5个方法(ANN, SVM, KNN等)和每个方法的10个参数组合(取决于方法)。您只需对每种方法和参数组合(5 * 10 = 50)进行交叉验证,并选择最佳模型、方法和参数。然后你用最好的方法和参数重新训练所有的数据,你就有了最终的模型。

我还有话要说。例如,如果您为每个方法和参数组合使用了许多方法和参数,则很可能会过度拟合。在这种情况下,必须使用嵌套交叉验证。

嵌套交叉验证

在嵌套交叉验证中,对模型选择算法执行交叉验证。

Again, you first split your data into k folds. After each step, you choose k-1 as your training data and the remaining one as your test data. Then you run model selection (the procedure I explained above) for each possible combination of those k folds. After finishing this, you will have k models, one for each combination of folds. After that, you test each model with the remaining test data and choose the best one. Again, after having the last model you train a new one with the same method and parameters on all the data you have. That's your final model.

当然,这些方法还有很多变体,还有其他我没有提到的东西。如果你需要更多关于这些的信息,找一些关于这些主题的出版物。


Sam Roweis曾经说过,你应该先尝试朴素贝叶斯,逻辑回归,k近邻和Fisher线性判别。


《OpenCV》这本书有两页在462-463页。在亚马逊预览版中搜索“有区别的”(可能也有谷歌本书),就能看到相关的页面。这两页是我在这本书中发现的最珍贵的宝石。

简而言之:

增强——当有大量可用的训练数据时通常是有效的。 随机树-通常非常有效,也可以执行回归。 k近邻-你能做的最简单的事情,通常有效但缓慢,需要大量内存。 神经网络——训练速度慢,但运行速度很快,仍然是字母识别的最佳表现。 SVM -在数据有限的情况下是最好的,但只有在大数据集可用时才会输给增强或随机树。


在选择使用哪种算法时,你可能会考虑的事情包括:

Do you need to train incrementally (as opposed to batched)? If you need to update your classifier with new data frequently (or you have tons of data), you'll probably want to use Bayesian. Neural nets and SVM need to work on the training data in one go. Is your data composed of categorical only, or numeric only, or both? I think Bayesian works best with categorical/binomial data. Decision trees can't predict numerical values. Does you or your audience need to understand how the classifier works? Use Bayesian or decision trees, since these can be easily explained to most people. Neural networks and SVM are "black boxes" in the sense that you can't really see how they are classifying data. How much classification speed do you need? SVM's are fast when it comes to classifying since they only need to determine which side of the "line" your data is on. Decision trees can be slow especially when they're complex (e.g. lots of branches). Complexity. Neural nets and SVMs can handle complex non-linear classification.


正如Andrew Ng教授经常说的那样:总是从实现一个粗糙的、肮脏的算法开始,然后迭代地完善它。

For classification, Naive Bayes is a good starter, as it has good performances, is highly scalable and can adapt to almost any kind of classification task. Also 1NN (K-Nearest Neighbours with only 1 neighbour) is a no-hassle best fit algorithm (because the data will be the model, and thus you don't have to care about the dimensionality fit of your decision boundary), the only issue is the computation cost (quadratic because you need to compute the distance matrix, so it may not be a good fit for high dimensional data).

Another good starter algorithm is the Random Forests (composed of decision trees), this is highly scalable to any number of dimensions and has generally quite acceptable performances. Then finally, there are genetic algorithms, which scale admirably well to any dimension and any data with minimal knowledge of the data itself, with the most minimal and simplest implementation being the microbial genetic algorithm (only one line of C code! by Inman Harvey in 1996), and one of the most complex being CMA-ES and MOGA/e-MOEA.

记住,通常情况下,在真正尝试算法之前,你无法真正知道什么对你的数据最有效。

作为一个边注,如果你想要一个理论框架来测试给定问题的假设和算法的理论性能,你可以使用PAC(可能大致正确)学习框架(注意:它非常抽象和复杂!),但总的来说,PAC学习的要点是你应该使用不太复杂,但足够复杂(复杂性是算法可以适合的最大维度)的算法来适合你的数据。换句话说,使用奥卡姆剃刀。


首先,你需要确定你的问题。这取决于您拥有的数据类型以及您想要的任务是什么。

如果你是预测类: 你有标签数据 您需要遵循分类方法及其算法 你没有标签数据 你需要使用集群方法 如果你在预测数量: 你需要使用回归方法 否则 你可以使用降维方法

上面提到的每种方法都有不同的算法。特定算法的选择取决于数据集的大小。

来源:http://scikit-learn.org/stable/tutorial/machine_learning_map/


您应该始终考虑推断与预测之间的权衡。

如果你想了解数据中发生的复杂关系,那么你应该使用丰富的推理算法(例如线性回归或套索)。另一方面,如果你只对结果感兴趣,你可以使用高维和更复杂(但更难以解释)的算法,比如神经网络。


算法的选择取决于场景和数据集的类型和大小。 还有很多其他因素。

这是一个简单的基础机器学习备忘单。