建立随机森林模型
随机森林是若干决策树组成的集成模型,训练速度较快,性能也较好。
在此不加调优的指定随机森林的相关超参数防止过拟合:
- 参数
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 r