質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.49%
機械学習

機械学習は、データからパターンを自動的に発見し、そこから知能的な判断を下すためのコンピューターアルゴリズムを指します。人工知能における課題のひとつです。

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

Q&A

1回答

909閲覧

Mglearnのエラー

退会済みユーザー

退会済みユーザー

総合スコア0

機械学習

機械学習は、データからパターンを自動的に発見し、そこから知能的な判断を下すためのコンピューターアルゴリズムを指します。人工知能における課題のひとつです。

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

0グッド

0クリップ

投稿2021/05/29 07:06

編集2021/05/29 09:00
from sklearn.ensemble import RandomForestClassifier from sklearn.datasets import make_moons X, y = make_moons(n_samples=100, noise=0.25, random_state=3) X_train, X_test, y_train, y_test = train_test_split(X, y, stratify=y, random_state=42) forest = RandomForestClassifier(n_estimators=5, random_state=2) forest.fit(X_train, y_train) fig, axes = plt.subplots(2, 3, figsize=(20, 10)) for i, (ax, tree) in enumerate(zip(axes.ravel(), forest.estimators_)): ax.set_title("Tree {}".format(i)) mglearn.plots.plot_tree_partition(X_train, y_train, tree, ax=ax) mglearn.plots.plot_2d_separator(forest, X_train, fill=True, ax=axes[-1, -1], alpha=.4) axes[-1, -1].set_title("Random Forest") mglearn.discrete_scatter(X_train[:, 0], X_train[:, 1], y_train)``` Pythonではじめる機械学習で勉強しています。 ランダムフォレストのところでエラーがでて先に進みません。どうすれば良いのでしょうか?Runtimeエラーでoutput shape not correctと出ています。教えていただければ幸いです。 環境は Mac Anaconda Jupyter notebook 6.0.1 mglearnはインポート済みです。 --------------------------------------------------------------------------- RuntimeError Traceback (most recent call last) <ipython-input-108-a394de2652b3> in <module> 12 for i, (ax, tree) in enumerate(zip(axes.ravel(), forest.estimators_)): 13 ax.set_title("Tree {}".format(i)) ---> 14 mglearn.plots.plot_tree_partition(X_train, y_train, tree, ax=ax) 15 16 mgleran.plots.plot_2d_separator(forest, X_train_, fill=True, ax=axes[-1, -1], ~/opt/anaconda3/lib/python3.7/site-packages/mglearn/plot_interactive_tree.py in plot_tree_partition(X, y, tree, ax) 77 faces = tree.apply(X_grid) 78 faces = faces.reshape(X1.shape) ---> 79 border = ndimage.laplace(faces) != 0 80 ax.contourf(X1, X2, Z, alpha=.4, cmap=cm2, levels=[0, .5, 1]) 81 ax.scatter(X1[border], X2[border], marker='.', s=1) ~/opt/anaconda3/lib/python3.7/site-packages/scipy/ndimage/filters.py in laplace(input, output, mode, cval) 447 def derivative2(input, axis, output, mode, cval): 448 return correlate1d(input, [1, -2, 1], axis, output, mode, cval, 0) --> 449 return generic_laplace(input, derivative2, output, mode, cval) 450 451 ~/opt/anaconda3/lib/python3.7/site-packages/scipy/ndimage/filters.py in generic_laplace(input, derivative2, output, mode, cval, extra_arguments, extra_keywords) 413 for ii in range(1, len(axes)): 414 tmp = derivative2(input, axes[ii], output.dtype, modes[ii], cval, --> 415 *extra_arguments, **extra_keywords) 416 output += tmp 417 else: ~/opt/anaconda3/lib/python3.7/site-packages/scipy/ndimage/filters.py in derivative2(input, axis, output, mode, cval) 446 """ 447 def derivative2(input, axis, output, mode, cval): --> 448 return correlate1d(input, [1, -2, 1], axis, output, mode, cval, 0) 449 return generic_laplace(input, derivative2, output, mode, cval) 450 ~/opt/anaconda3/lib/python3.7/site-packages/scipy/ndimage/filters.py in correlate1d(input, weights, axis, output, mode, cval, origin) 80 if numpy.iscomplexobj(input): 81 raise TypeError('Complex type not supported') ---> 82 output = _ni_support._get_output(output, input) 83 weights = numpy.asarray(weights, dtype=numpy.float64) 84 if weights.ndim != 1 or weights.shape[0] < 1: ~/opt/anaconda3/lib/python3.7/site-packages/scipy/ndimage/_ni_support.py in _get_output(output, input, shape) 80 output = numpy.zeros(shape, dtype=output) 81 elif output.shape != shape: ---> 82 raise RuntimeError("output shape not correct") 83 return output 84 RuntimeError: output shape not correct

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

K_3578

2021/05/29 07:18

エラーが出て先に進みません。 エラーメッセージはどこで不具合が発生しているかを明確に教えてくれている。 意味不明!と言って逃げても先には進まない。 英文ならGoogle翻訳でもなんでも使って1行ずつ読んでいけば良い。
guest

回答1

0

mgleran.plots.plot_2d_separator
X_train_,

間違いだらけです。

投稿2021/05/29 08:49

technocore

総合スコア7200

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

退会済みユーザー

退会済みユーザー

2021/05/29 08:55

from sklearn.ensemble import RandomForestClassifier from sklearn.datasets import make_moons X, y = make_moons(n_samples=100, noise=0.25, random_state=3) X_train, X_test, y_train, y_test = train_test_split(X, y, stratify=y, random_state=42) forest = RandomForestClassifier(n_estimators=5, random_state=2) forest.fit(X_train, y_train) fig, axes = plt.subplots(2, 3, figsize=(20, 10)) for i, (ax, tree) in enumerate(zip(axes.ravel(), forest.estimators_)): ax.set_title("Tree {}".format(i)) mglearn.plots.plot_tree_partition(X_train, y_train, tree, ax=ax) mglearn.plots.plot_2d_separator(forest, X_train, fill=True, ax=axes[-1, -1], alpha=.4) axes[-1, -1].set_title("Random Forest") mglearn.discrete_scatter(X_train[:, 0], X_train[:, 1], y_train)
退会済みユーザー

退会済みユーザー

2021/05/29 08:56

RuntimeError: output shape not correct
technocore

2021/05/29 09:02

他にも誤字脱字がないか探してください。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだベストアンサーが選ばれていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.49%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問