Predicting Bayesion NN does not work with variational api

I am trying to replicate Thomas Wiecki’s post : Bayesian Deep Learning Part II: Bridging PyMC3 and Lasagne to build a Hierarchical Neural Network
Because the pymc3 package changed I had to modify the notebook.
Changes were made for minibathes, sample_ppc to sample_posterior_predict, etc.
The accuracy I about 10% ( not better than random selection).

neural_network = build_ann(GaussWeights())

with neural_network:


 mean_field =, method=inference, score=True, more_replacements={input_var: input_var_mb, target_var:target_var_mb})

trace = mean_field.sample(500)

input_var.set_value(X_test[:5000, …].astype(np.float64))
target_var.set_value(y_test[:5000, …].astype(np.float64))

with neural_network:
ppc = pm.sample_posterior_predictive(trace, samples=15000)

y_pred = mode(ppc[‘out’], axis=0).mode[0, :]

And use y_pred and y_test[:5000] to get the confusion matrix and accuracy
Am I doing something wrong?
Or is pymc3 just not suitable for prediting?

Regards Hans

The notebook can be found here: