分类结果取决于random_state?

Classification results depend on random_state?

我想使用 scikit-learn (sklearn) 实现 AdaBoost 模型。我的问题和 but it is not totally the same. As far as I understand, the random_state variable described in the documentation类似,就是按照之前的link随机拆分训练集和测试集。所以如果我理解正确的话,我的分类结果应该不依赖于种子,对吗?如果我的分类结果结果取决于 random_state 变量,我应该担心吗?

这很重要。当你的训练集不同时,你的训练状态也会改变。对于不同的数据子集,您最终得到的分类器与使用其他子集训练的分类器几乎没有什么不同。

因此,您应该使用常量种子,如 0 或其他整数,以便您的结果可重现。

您的分类分数将取决于 random_state。正如@Ujjwal 所说,它用于将数据拆分为训练和测试测试。不仅如此,scikit-learn 中的很多算法都使用 random_state 到 select 特征子集,样本子集,并确定初始权重等

例如。

  • 基于树的估计器将使用 random_state 随机 select 特征和样本(如 DecisionTreeClassifier, RandomForestClassifier)。

  • 在像 Kmeans 这样的聚类估计器中,random_state 用于初始化聚类中心。

  • SVM 使用它进行初始概率估计

  • 某些特征 selection 算法也将其用于初始 selection
  • 还有更多...

它在 documentation 中提到:

If your code relies on a random number generator, it should never use functions like numpy.random.random or numpy.random.normal. This approach can lead to repeatability issues in tests. Instead, a numpy.random.RandomState object should be used, which is built from a random_state argument passed to the class or function.

请阅读以下问题和答案以更好地理解:

  • Choosing random_state for sklearn algorithms