未验证 提交 f505c1b5 编写于 作者: Y Yu Wang 提交者: GitHub

修改 7.集成学习和随机森林.md 中的一些代码和文字排版问题

上级 2252c70a
......@@ -38,7 +38,8 @@
>>> log_clf = LogisticRegression()
>>> rnd_clf = RandomForestClassifier()
>>> svm_clf = SVC()
>>> voting_clf = VotingClassifier(estimators=[('lr', log_clf), ('rf', rnd_clf), >>> ('svc', svm_clf)],voting='hard')
>>> voting_clf = VotingClassifier(estimators=[('lr', log_clf), ('rf', rnd_clf),
>>> ('svc', svm_clf)],voting='hard')
>>> voting_clf.fit(X_train, y_train)
```
......@@ -61,8 +62,6 @@ VotingClassifier 0.896
## Bagging 和 Pasting
换句话说,Bagging 和 Pasting 都允许在多个分类器间对训练集进行多次采样,但只有 Bagging
就像之前讲到的,可以通过使用不同的训练算法去得到一些不同的分类器。另一种方法就是对每一个分类器都使用相同的训练算法,但是在不同的训练集上去训练它们。有放回采样被称为装袋(*Bagging*,是 *bootstrap aggregating* 的缩写)。无放回采样称为粘贴(*pasting*)。
换句话说,Bagging 和 Pasting 都允许在多个分类器上对训练集进行多次采样,但只有 Bagging 允许对同一种分类器上对训练集进行进行多次采样。采样和训练过程如图7-4所示。
......@@ -80,7 +79,8 @@ sklearn 为 Bagging 和 Pasting 提供了一个简单的API:`BaggingClassifier
```python
>>>from sklearn.ensemble import BaggingClassifier
>>>from sklearn.tree import DecisionTreeClassifier
>>>bag_clf = BaggingClassifier(DecisionTreeClassifier(), n_estimators=500, >>>max_samples=100, bootstrap=True, n_jobs=-1)
>>>bag_clf = BaggingClassifier(DecisionTreeClassifier(), n_estimators=500,
>>> max_samples=100, bootstrap=True, n_jobs=-1)
>>>bag_clf.fit(X_train, y_train)
>>>y_pred = bag_clf.predict(X_test)
```
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册