質問編集履歴
1
コードを再度掲載いたしました
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,3 +1,43 @@
|
|
1
|
+
```
|
2
|
+
|
3
|
+
from sklearn.ensemble import RandomForestClassifier
|
4
|
+
|
5
|
+
from sklearn.datasets import make_moons
|
6
|
+
|
7
|
+
|
8
|
+
|
9
|
+
X, y = make_moons(n_samples=100, noise=0.25, random_state=3)
|
10
|
+
|
11
|
+
X_train, X_test, y_train, y_test = train_test_split(X, y, stratify=y, random_state=42)
|
12
|
+
|
13
|
+
|
14
|
+
|
15
|
+
forest = RandomForestClassifier(n_estimators=5, random_state=2)
|
16
|
+
|
17
|
+
forest.fit(X_train, y_train)
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
fig, axes = plt.subplots(2, 3, figsize=(20, 10))
|
22
|
+
|
23
|
+
for i, (ax, tree) in enumerate(zip(axes.ravel(), forest.estimators_)):
|
24
|
+
|
25
|
+
ax.set_title("Tree {}".format(i))
|
26
|
+
|
27
|
+
mglearn.plots.plot_tree_partition(X_train, y_train, tree, ax=ax)
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
mglearn.plots.plot_2d_separator(forest, X_train, fill=True, ax=axes[-1, -1], alpha=.4)
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
axes[-1, -1].set_title("Random Forest")
|
36
|
+
|
37
|
+
mglearn.discrete_scatter(X_train[:, 0], X_train[:, 1], y_train)```
|
38
|
+
|
39
|
+
|
40
|
+
|
1
41
|
Pythonではじめる機械学習で勉強しています。
|
2
42
|
|
3
43
|
ランダムフォレストのところでエラーがでて先に進みません。どうすれば良いのでしょうか?Runtimeエラーでoutput shape not correctと出ています。教えていただければ幸いです。
|
@@ -18,43 +58,7 @@
|
|
18
58
|
|
19
59
|
|
20
60
|
|
21
|
-
from sklearn.ensemble import RandomForestClassifier
|
22
61
|
|
23
|
-
from sklearn.datasets import make_moons
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
X, y = make_moons(n_samples=100, noise=0.25, random_state=3)
|
28
|
-
|
29
|
-
X_train, X_test, y_train, y_test = train_test_split(X, y, stratify=y, random_state=42)
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
forest = RandomForestClassifier(n_estimators=5, random_state=2)
|
34
|
-
|
35
|
-
forest.fit(X_train, y_train)
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
fig, axes = plt.subplots(2, 3, figsize=(20, 10))
|
42
|
-
|
43
|
-
for i, (ax, tree) in enumerate(zip(axes.ravel(), forest.estimators_)):
|
44
|
-
|
45
|
-
ax.set_title("Tree {}".format(i))
|
46
|
-
|
47
|
-
mglearn.plots.plot_tree_partition(X_train, y_train, tree, ax=ax)
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
mgleran.plots.plot_2d_separator(forest, X_train_, fill=True, ax=axes[-1, -1],
|
52
|
-
|
53
|
-
alpha=.4)
|
54
|
-
|
55
|
-
axes[-1, -1].set_title("Random Forest")
|
56
|
-
|
57
|
-
mglearn.discrete_scatter(X_train[:, 0], X_train[:, 1], y_train)
|
58
62
|
|
59
63
|
|
60
64
|
|