Pymc3を使って深いベイジアンニューラルネットワークを構築しました。私はモデルを訓練し、必要なサンプルを取得しました。今度は、この適合モデルをディスクに保存するための検索を行っています テストデータセットのサイズを変更すると、このエラーが発生します。 def save_model(trace、network、ann_input、num): print( "in")バフとして( 'my_model.pkl'、 'WB')オープンと : pickle.dump({ 'モデル':ネットワーク、 'トレース':トレース}、バフ)simmpling後にPymc3モデルをディスクに保存
f = open ('ann_input'+str(num)+'.pckl', 'wb')
pickle.dump (ann_input, f)
f.close()
デフload_model(NUM) データ= pickle.load(バフ)
network, trace = data[ 'model' ], data[ 'trace' ]
f = open ('ann_input'+str(num)+'.pckl', 'rb')
ann_input = pickle.load (f)
f.close()
return trace, network, ann_input
:バフとしてオープン( 'my_model.pkl'、 'RB')と
は、私はこのエラーに
print(accuracy_score(y_pred,y_test))
ファイルを取得する "D:\ Users \ユーザーwissam \のAppData \ローカル\プログラム\ Pythonの\ Python36 \ libには\サイト - パッケージ\ sklearn \メトリック\ classification.py"、行172、 Python \ Python \ lib \ site-packages \ sklearn \ metrics \ classification.py "というファイル名を使用しています。このファイルは、ディレクトリ181、行72、_check_targets check_consistent_length(y_true、y_pred) ファイル "D:¥Users¥wissam¥AppData¥Local¥Programs¥Python¥Python36¥lib¥site-packages¥sklearn¥utils¥validation.py" in check_consistent_length "samples:%r" lenのlに対する%[int(l)] gths]) とValueError:サンプルの一貫性のない数で見入力変数:[174、169]
iは、次のコード
with neural_network:
step = pm.Metropolis()
print("start simpling")
db = pm.backends.Text ('test')
trace = pm.sample (10000,step, trace=db)
print ("end simpling")
from pymc3 import summary
summary(trace, varnames=['p'])
を使用してバックエンドを使用することも試み、私は次のエラーを取得
Traceback (most recent call last):
File "D:\Users\wissam\AppData\Roaming\Python\Python36\site-
packages\pymc3\model.py", line 121, in get_context
return cls.get_contexts()[-1]
IndexError: list index out of range
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File
"D:/Users/wissam/PycharmProjects/git_repo/projetenovap/Training/
trainModel.py",
line 301, in <module>
trace = pm.backends.text.load('test')
File "D:\Users\wissam\AppData\Roaming\Python\Python36\site-
packages\pymc3\backends\text.py", line 171, in load
strace = Text(name, model=model)
File "D:\Users\wissam\AppData\Roaming\Python\Python36\site-
packages\pymc3\backends\text.py", line 44, in __init__
super(Text, self).__init__(name, model, vars)
File "D:\Users\wissam\AppData\Roaming\Python\Python36\site-
packages\pymc3\backends\base.py", line 31, in __init__
model = modelcontext(model)
File "D:\Users\wissam\AppData\Roaming\Python\Python36\site-
packages\pymc3\model.py", line 131, in modelcontext
return Model.get_context()
File "D:\Users\wissam\AppData\Roaming\Python\Python36\site-
packages\pymc3\model.py", line 123, in get_context
raise TypeError("No context on context stack")
TypeError: No context on context stack
このモデルの保存についてのご意見はありますか?
私の問題は解決しました。私たちはトレース(サンプリングされたデータ)と新しいニューラルネットワークを作成するたびに(すべてのニューラルネットワークではなくウェイトだけを保存する) – user2856587