前提・実現したいこと
module名とディレクトリ名を異なるようにしたのに、has no attributeがでてきた。
発生している問題・エラーメッセージ
module 'layers.noisemaker' has no attribute 'gate'
該当のソースコード
python
1#module名はnoisemakerです。その後別のmoduleでgateを呼び出しました。 2#%% 3import matplotlib.pyplot as plt 4import numpy as np 5 6def gate(a): 7 np.random.seed(a) 8 x_xor=np.random.randn(200,2) 9 y_xor=np.logical_xor(x_xor[:,0]>0,x_xor[:,1]>0) 10 y_xor=np.where(y_xor,1,-1) 11 12 plt.scatter(x_xor[y_xor==1,0],x_xor[y_xor==1,1],c='b',marker='x',label='1') 13 14 plt.scatter(x_xor[y_xor==-1,0],x_xor[y_xor==-1,1],c='r',marker='s',label='-1') 15 16 plt.xlim([-3,3]) 17 plt.ylim([-3,3]) 18 plt.legend(loc='best') 19 plt.tight_layout() 20 plt.show() 21 22 return x_xor 23 return y_xor 24 25↑layers内にこのmoduleを入れています。その後SVM_in_sklearnを開いて実行しました。以下がそのmoduleです。↓ 26 27#%% 28from sklearn import datasets 29import numpy as np 30import matplotlib.pyplot as plt 31import layers 32from layers import decisionregionplotfunction as drp 33from layers import noisemaker as noise 34from sklearn.svm import SVC 35 36 37#%% 38#カーネルトリック 39svm=SVC(kernel='rbf',random_state=1,gamma=0.1,C=10.0) 40X,Y=noise.gate(a=1).x_xor,noise.gate(a=1).y_xor 41svm.fit(X,Y) 42drp.plot_decision_regions(X,Y,classifier=svm) 43plt.tight_layout() 44plt.show()
試したこと
moduleの名前とgateの名前を色々変えてみましたがだめでした。
補足情報(FW/ツールのバージョンなど)
ここにより詳細な情報を記載してください。
回答1件
あなたの回答
tips
プレビュー