繁体   English   中英

如何在 Python Sklearn RandomForestRegressor 中显示 model 参数

[英]How to display model parameter in Python Sklearn RandomForestRegressor

我正在比较不同的集成模型,包括:

from sklearn.tree import DecisionTreeRegressor
from sklearn.linear_model import Lasso
from sklearn.ensemble import RandomForestRegressor
from sklearn.ensemble import AdaBoostRegressor
from sklearn.ensemble import GradientBoostingRegressor
from xgboost import XGBRegressor

对于 XGBRegressor(),我可以通过以下方式检查 model 参数:

xgb_model = XGBRegressor()
xgb_model.fit(X_train, y_train)
xgb_model

结果是:

xgb_model
XGBRegressor(base_score=0.5, booster='gbtree', colsample_bylevel=1,
             colsample_bynode=1, colsample_bytree=1, enable_categorical=False,
             gamma=0, gpu_id=-1, importance_type=None,
             interaction_constraints='', learning_rate=0.300000012,
             max_delta_step=0, max_depth=6, min_child_weight=1, missing=nan,
             monotone_constraints='()', n_estimators=100, n_jobs=52,
             num_parallel_tree=1, predictor='auto', random_state=0, reg_alpha=0,
             reg_lambda=1, scale_pos_weight=1, subsample=1, tree_method='exact',
             validate_parameters=1, verbosity=None)

但是对于其他回归器,我无法检查 model 参数,括号中没有任何内容。 这也发生在 Adaboost 和 GradientBoost 中:

RF_model = RandomForestRegressor()
RF_model.fit(X_train, y_train)
RF_model

RF_model
RandomForestRegressor()

我的问题是如何检查 model 参数?

嗨,您必须在这些算法上使用get_params()方法:

RF_model = RandomForestRegressor()
RF_model.get_params()

此方法将像这样的 dict 中的所有参数返回给您:

  {'bootstrap': True,
   'ccp_alpha': 0.0,
   'class_weight': None,
   'criterion': 'gini',
   'max_depth': None,
   'max_features': 'sqrt',
   'max_leaf_nodes': None,
   'max_samples': None,
   'min_impurity_decrease': 0.0,
   'min_samples_leaf': 1,
   'min_samples_split': 2,
   'min_weight_fraction_leaf': 0.0,
   'n_estimators': 100,
   'n_jobs': None,
   'oob_score': False,
   'random_state': None,
   'verbose': 0,
   'warm_start': False}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM