我知道你可以通过在RandomForestReturnsor函数中设置OOB_score=True来获得sklearn随机森林中的OOB分数。我不确定这是否可能,但有没有办法获得在计算OOB分数时使用的观察和预测?
这存储在属性oob_prediction_
下,通过对行或观测为OOB的所有树的预测进行平均来获得预测。
例如,前10次观测的前10次OOB预测:
from sklearn.ensemble import RandomForestRegressor
from sklearn.datasets import make_regression
X, y = make_regression(n_features=4, n_informative=2,
random_state=0, shuffle=False)
regr = RandomForestRegressor(max_depth=2, random_state=0,oob_score=True)
regr.fit(X, y)
regr.oob_prediction_[:10]