Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions numpy_ml/tests/test_naive_bayes.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ def test_GaussianNB(N=10):

np.testing.assert_almost_equal(jointi, jointi_mine)

n_jk = -0.5 * np.sum(np.log(2.0 * np.pi * sklearn_NB.sigma_[j, :] + eps))
n_jk = -0.5 * np.sum(np.log(2.0 * np.pi * sklearn_NB.var_[j, :] + eps))
n_jk_mine = -0.5 * np.sum(np.log(2.0 * np.pi * P["sigma"][j] + eps))

np.testing.assert_almost_equal(n_jk_mine, n_jk)

n_jk2 = n_jk - 0.5 * np.sum(
((X_test - sklearn_NB.theta_[j, :]) ** 2) / (sklearn_NB.sigma_[j, :]), 1
((X_test - sklearn_NB.theta_[j, :]) ** 2) / (sklearn_NB.var_[j, :]), 1
)

n_jk2_mine = n_jk_mine - 0.5 * np.sum(
Expand All @@ -63,7 +63,7 @@ def test_GaussianNB(N=10):

np.testing.assert_almost_equal(P["prior"], sklearn_NB.class_prior_)
np.testing.assert_almost_equal(P["mean"], sklearn_NB.theta_)
np.testing.assert_almost_equal(P["sigma"], sklearn_NB.sigma_)
np.testing.assert_almost_equal(P["sigma"], sklearn_NB.var_)
np.testing.assert_almost_equal(
sklearn_NB._joint_log_likelihood(X_test),
NB._log_posterior(X_test),
Expand Down
2 changes: 1 addition & 1 deletion numpy_ml/utils/data_structures.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import heapq
from copy import copy
from collections import Hashable
from collections.abc import Hashable

import numpy as np

Expand Down