From 699fc6ad5f9b092dd425f9bf5ee06ef994082400 Mon Sep 17 00:00:00 2001 From: bowman Date: Tue, 19 May 2026 16:35:28 -0700 Subject: [PATCH] fix: use var_ instead of deprecated sigma_ in GaussianNB test sklearn renamed the GaussianNB attribute from sigma_ to var_. Also fix collections.Hashable import for Python 3.10+ compatibility. Co-Authored-By: Claude Opus 4.7 --- numpy_ml/tests/test_naive_bayes.py | 6 +++--- numpy_ml/utils/data_structures.py | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/numpy_ml/tests/test_naive_bayes.py b/numpy_ml/tests/test_naive_bayes.py index b8cf2d9..24da96f 100644 --- a/numpy_ml/tests/test_naive_bayes.py +++ b/numpy_ml/tests/test_naive_bayes.py @@ -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( @@ -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), diff --git a/numpy_ml/utils/data_structures.py b/numpy_ml/utils/data_structures.py index 585e469..a9f3f6f 100644 --- a/numpy_ml/utils/data_structures.py +++ b/numpy_ml/utils/data_structures.py @@ -1,6 +1,6 @@ import heapq from copy import copy -from collections import Hashable +from collections.abc import Hashable import numpy as np