使用 sklearn Pipeline 和 MultiOutputRegressor 访问属性
Access attributes with sklearn Pipeline and MultiOutputRegressor
假设一个机器学习模型,例如 LightGBM 的 LGBMRegressor
,有一个属性 best_iteration_
。在调用 fit
方法后如何访问此属性,其中利用了 sklearn 的 Pipeline
和 MultiOutputRegressor
?
对于 Pipeline
我试过了 named_steps
:
foo.named_steps['reg']
哪个returns以下对象sklearn.multioutput.MultiOutputRegressor.
那么,我试过了.estimators_
:
foo.named_steps['reg'].estimators_
其中returns一个列表。但是,该列表包含提供给模型的初始参数。
有人可以解释访问模型属性的理想方式吗?
我假设 foo
是一个 sklearn 管道对象,如果是这样,你可以这样做:
for e in foo.named_steps['reg'].estimators_:
print(e.best_iteration_)
foo.named_steps['reg'].estimators_
returns 估算器列表
在 MultiOutputRegressor 内部。
e
是您使用的 LGBMRegressor
在你的 MultiOutputRegressor 里面。
您可以将 best_iteration_
替换为您想要访问的模型的任何属性。
假设一个机器学习模型,例如 LightGBM 的 LGBMRegressor
,有一个属性 best_iteration_
。在调用 fit
方法后如何访问此属性,其中利用了 sklearn 的 Pipeline
和 MultiOutputRegressor
?
对于 Pipeline
我试过了 named_steps
:
foo.named_steps['reg']
哪个returns以下对象sklearn.multioutput.MultiOutputRegressor.
那么,我试过了.estimators_
:
foo.named_steps['reg'].estimators_
其中returns一个列表。但是,该列表包含提供给模型的初始参数。
有人可以解释访问模型属性的理想方式吗?
我假设 foo
是一个 sklearn 管道对象,如果是这样,你可以这样做:
for e in foo.named_steps['reg'].estimators_:
print(e.best_iteration_)
foo.named_steps['reg'].estimators_
returns 估算器列表 在 MultiOutputRegressor 内部。e
是您使用的 LGBMRegressor 在你的 MultiOutputRegressor 里面。
您可以将 best_iteration_
替换为您想要访问的模型的任何属性。