Firstly, I’d like to mention that I am a beginner in Bayesian statistics and PyMC. Please excuse any misunderstandings.
While studying textbooks on Bayesian statistics and machine learning, I came across the MCMC method. As a challenge, I decided to use MCMC to classify the Iris dataset, a standard toy dataset in machine learning, though I’m aware it can also be approached with SVM or other algorithms. This choice was intentional for my future research
I successfully implemented binary classification, but I’m encountering difficulties with multi-class classification (three or more classes).
full source code (Google Colaboratory):
import pymc as pm
with pm.Model() as model:
# data
X_data = pm.Data('X_bias', X_train_bias, mutable=False)
y_data = pm.Data('y', y_train_cat, mutable=False)
# prior distribution of w
w = pm.Normal('w', mu=0, sigma=10, shape=(X_train_bias.shape[1], y_train_cat.shape[1]))
#
y = pm.math.dot(X_data, w)
pred = pm.math.softmax(y)
# likelihood
likelihood = pm.Categorical('likelihood', p=pred, observed=y_data)
# run sampling
trace = pm.sample()
# it occurs error, why?
I’ve been attempting to resolve the ‘Could not broadcast dimensions’ error, but despite various efforts, the issue remains unresolved.
This might not be a typical usage of PyMC, but any assistance would be greatly appreciated!