获取随机森林管道内的OOB分数



我想知道一个机器学习项目:是否有可能在管道内实现RandomForestRegressor?

具体来说,我需要从RandomForestRegressor中确定OOB分数。但是我的数据需要大量的预处理。

我尝试了几种方法,这是目前为止最接近的:

# Creation of the pipeline 
rand_piped = Pipeline([
('preprocessor', preprocessor),
('model', RandomForestRegressor(max_depth=3, random_state=0, oob_score=True))
])
# Fitting our model
rand_piped.fit(df_X_train,df_Y_train.values.ravel())
# Getting our metrics and predictions 
oob_score = rand_piped.oob_score_

目前我认为我的问题是我对这个方法仍然有一个不清楚的想法。所以请随意纠正我。它返回以下错误:

Traceback (most recent call last):
File "/home/user/my_rf.py", line 15, in <module>
oob_score = rand_piped.oob_score_
AttributeError: 'Pipeline' object has no attribute 'oob_score_'

管道是可订阅的,因此您可以在model步骤中查找oob_score_:

>>> rand_piped["model"].oob_score_
0.9297212997034854

最新更新