I have a matrix which fails the singular test in which I am calculating for naive bayes classifier. I am handling the ln(det(sigma))
portion of the equation.
if np.linalg.cond(covarianceMatrix) < 1/sys.float_info.epsilon:
return np.log(np.linalg.det(covarianceMatrix))
else:
return a pseudo determinant
When the covariance matrix is singular, I must find the pseudo determinant. How can I do that?
eig_values = np.linalg.eig(covarianceMatrix)
pseudo_determinent = np.product(eig_values[eig_values > 1e-12])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With