为什么随机森林会随着训练示例的数量而增加?

时间:2019-01-04 22:39:13

标签: python machine-learning memory scikit-learn random-forest

在过去的几个月中,我一直在定期培训sklearn随机森林。我注意到,当使用joblib将模型导出到文件时,文件大小已急剧增加-从2.5 GB到11GB。所有参数均保持不变,并且训练功能的数量保持固定。唯一的区别是训练数据中的示例数量增加了。

鉴于参数保持不变,并指定了估计数和每棵树的深度,为什么增加示例数会增加随机森林的大小?

以下是模型的参数:

RandomForestClassifier(bootstrap=True, class_weight=None, criterion='gini',
        max_depth=None, max_features='sqrt', max_leaf_nodes=None,
        min_impurity_decrease=0.0, min_impurity_split=None,
        min_samples_leaf=20, min_samples_split=2,
        min_weight_fraction_leaf=0.0, n_estimators=1000, n_jobs=-1,
        oob_score=False, random_state=123, verbose=0, warm_start=False)

1 个答案:

答案 0 :(得分:1)

我会将min_samples_leaf设置为浮点数,那么它就是训练数据集中的百分比。例如,min_samples_leaf=0.01在每个叶子中至少有1%的样本。

要优化模型的大小,可以在min_samples_leafn_estimators上使用GridSearchCV。除非您有大量的类和功能,否则可以将模型大小减小几个数量级。

相关问题