随机森林是若干决策树组成的集成模型,训练速度较快,性能也较好。
在此不加调优的指定随机森林的相关超参数防止过拟合:
n_estimators
:指定随机森林中决策树的数量为100;max_depth
:指定决策树的最大深度为5;min_samples_leaf
:指定决策树的叶子节点至少要包含100个样本。clf = RandomForestClassifier(n_estimators = 100, max_depth = 5, min_samples_leaf = 100)
clf.fit(X_train, y_train)
RandomForestClassifier(bootstrap=True, class_weight=None, criterion='gini',
max_depth=5, max_features='auto', max_leaf_nodes=None,
min_impurity_decrease=0.0, min_impurity_split=None,
min_samples_leaf=100, 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)
报错:
Traceback (most recent call last):
File "E:\python\hotal\2.py", line 194, in
RandomForestClassifier(bootstrap=True, class_weight=None, criterion='gini',
TypeError: __init__() got an unexpected keyword argument 'min_impurity_split'
类型错误:__init__()获得了意外的关键字参数“min_impurity_split”
解决方法:
参考了:__init__() got an unexpected keyword argument 'min_impurity_split - CSDN文库
直接删除了 min_impurity_split
代码正常运行