<jupyter_start><jupyter_text>随机森林<jupyter_code>import numpy as np
import matplotlib.pyplot as plt
from sklearn import datasets

X, y = datasets.make_moons(n_samples=500, noise=0.3, random_state=666)
plt.scatter(X[y==0,0], X[y==0,1])
plt.scatter(X[y==1,0], X[y==1,1])
plt.show()<jupyter_output><empty_output><jupyter_text>随机森林<jupyter_code>from sklearn.ensemble import RandomForestClassifier

rf_clf = RandomForestClassifier(n_estimators=500, oob_score=True, random_state=666, n_jobs=-1)
rf_clf.fit(X, y)
rf_clf.oob_score_
rf_clf2 = RandomForestClassifier(n_estimators=500, max_leaf_nodes=16, oob_score=True, random_state=666, n_jobs=-1)
rf_clf2.fit(X, y)
rf_clf2.oob_score_<jupyter_output><empty_output><jupyter_text>随机森林拥有决策树和BaggingClassifier的所有参数：）  Extra-Trees<jupyter_code>from sklearn.ensemble import ExtraTreesClassifier

et_clf = ExtraTreesClassifier(n_estimators=500, bootstrap=True, oob_score=True, random_state=666, n_jobs=-1)
et_clf.fit(X, y)
et_clf.oob_score_<jupyter_output><empty_output><jupyter_text>集成学习解决回归问题<jupyter_code>from sklearn.ensemble import BaggingRegressor
from sklearn.ensemble import RandomForestRegressor
from sklearn.ensemble import ExtraTreesRegressor<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11275720164609053, 'fraction_numerical': 0.0345679012345679, 'mean_word_length': 11.8, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '263216', 'license': 'MulanPSL-1.0', 'n_tokens_mistral': 557, 'n_tokens_neox': 550, 'n_words': 66, 'path': 'Part5Improve/13-Ensemble-Learning-and-Random-Forest/05-Random-Forest-and-Extra-Trees/05-Random-Forest-and-Extra-Trees.ipynb', 'repo_name': '19920625lsg/itcast-python', 'size': '1215'}