Scikit-learn参数oob_score,oob_score_,oob_prediction_

Cle*_*son 5 python-2.7 random-forest scikit-learn

我有在找出什么是很难oob_score_在scikit学习随机森林回归手段.在文档上说:

oob_score_: float使用袋外估计获得的训练数据集的分数.

起初我以为它会在out-of-bag实例的集合上返回每个实例的分数.但这是由属性给出的:

oob_prediction_: shape of array = [n_samples]使用训练集上的袋外估计计算的预测.

返回一个包含每个实例预测的数组.然后分析文档中的其他参数,我意识到方法得分(X,y,sample_weight = None)返回确定系数R².

考虑到调用属性oob_score_返回一个浮点值,它代表什么?如果可能的话,我想知道它是如何计算的.

文档的链接是RandomForestRegressor.

lej*_*lot 2

它返回的内容与文档中所述完全相同

\n\n
\n

oob_score_ :使用袋外估计获得的训练数据集的 float 分数。

\n
\n\n

得分在哪里

\n\n
\n

Score(X, y, Sample_weight=None) 返回确定系数 R\xc2\xb2。

\n
\n\n

袋外估计是由于装袋过程而未用于训练的样本。

\n\n

只需查看源代码,第 727-740 行

\n\n
    predictions /= n_predictions\n    self.oob_prediction_ = predictions\n\n    if self.n_outputs_ == 1:\n        self.oob_prediction_ = \\\n            self.oob_prediction_.reshape((n_samples, ))\n\n    self.oob_score_ = 0.0\n\n    for k in range(self.n_outputs_):\n        self.oob_score_ += r2_score(y[:, k],\n                                    predictions[:, k])\n\n    self.oob_score_ /= self.n_outputs_\n
Run Code Online (Sandbox Code Playgroud)\n\n

换句话说,它只是 R2 分数oob_prediction_

\n