随机森林排序特征选择后结果feature_importances为0,normalized_importance的值都为nan,cumulative_importance的值都为nan

在做评分卡的工作,使用随机森林排序特征选择,目测有因素相关联大,但运行下面的代码,最后df_train_woe的结果为空,百思不得其解。

fs = FeatureSelector(data = df_train_woe[sel_var], labels = data_train_bin.target)
    ##一次性去除所有的不满足特征  
    fs.identify_all(selection_params = {'missing_threshold': 0.9,
                                         'correlation_threshold': 0.8,
                                         'task': 'classification',
                                         'eval_metric': 'binary_error',
                                         'max_depth':2,
                                         'cumulative_importance': 0.90})
 df_train_woe = fs.remove(methods = 'all')
    df_train_woe['target'] = data_train_bin.target

调试feature_selector.py的代码,发现identify_zero_importance方法中,feature_importances的值都为0,normalized_importance的值都为nan,cumulative_importance的值都为nan。

后来觉得代码反复验证是没问题,有可能是样本太少(才几十条),手头增加样本到几百条,果然运行后结果没问题了。这真是个坑,在这里先记录一下,有空时深入研究一下代码和原理。

关注公众号“大模型全栈程序员”回复“小程序”获取1000个小程序打包源码。更多免费资源在http://www.gitweixin.com/?p=2627

发表评论

邮箱地址不会被公开。 必填项已用*标注