1from sklearn.ensemble import RandomForestClassifier
2
3
4clf = RandomForestClassifier(max_depth=2, random_state=0)
5
6clf.fit(X, y)
7
8print(clf.predict([[0, 0, 0, 0]]))
1from sklearn.ensemble import RandomForestClassifier
2from sklearn.datasets import make_classification
3X, y = make_classification(n_samples=1000, n_features=4,
4 n_informative=2, n_redundant=0,
5 random_state=0, shuffle=False)
6clf = RandomForestClassifier(max_depth=2, random_state=0)
7clf.fit(X, y)
8
9print(clf.predict([[0, 0, 0, 0]]))
1from sklearn.ensemble import RandomForestClassifier
2from sklearn.datasets import make_classification
3
4
5X, y = make_classification(n_samples=1000, n_features=4,
6 n_informative=2, n_redundant=0,
7 random_state=0, shuffle=False)
8clf = RandomForestClassifier(max_depth=2, random_state=0)
9
10clf.fit(X, y)
11
12print(clf.predict([[0, 0, 0, 0]]))
1from sklearn.ensemble import BaggingClassifier
2from sklearn.neighbors import KNeighborsClassifier
3bagging = BaggingClassifier(KNeighborsClassifier(),
4 max_samples=0.5, max_features=0.5)