Skip to content

Commit

Permalink
Merge pull request #1659 from nikicc/sparse-fix-nans-counting
Browse files Browse the repository at this point in the history
[FIX] Statistics.util.stats: Fix negative #nans for sparse
  • Loading branch information
lanzagar authored Oct 17, 2016
2 parents 339d549 + 7b35830 commit 20e7e66
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Orange/statistics/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ def stats(X, weights=None, compute_variance=False):
X.max(axis=0).toarray().ravel(),
np.asarray(X.mean(axis=0)).ravel() if not weighted else weighted_mean,
np.zeros(X.shape[1]), # variance not supported
X.shape[1] - non_zero,
X.shape[0] - non_zero,
non_zero))
else:
nans = (~X.astype(bool)).sum(axis=0) if X.size else np.zeros(X.shape[1])
Expand Down
10 changes: 5 additions & 5 deletions Orange/tests/test_statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ def test_stats_sparse(self):

# assure last two columns have just zero elements
X = X[:3]
np.testing.assert_equal(stats(X), [[0, 1, 1/3, 0, 4, 1],
[0, 1, 1/3, 0, 4, 1],
[0, 1, 1/3, 0, 4, 1],
[0, 0, 0, 0, 5, 0],
[0, 0, 0, 0, 5, 0]])
np.testing.assert_equal(stats(X), [[0, 1, 1/3, 0, 2, 1],
[0, 1, 1/3, 0, 2, 1],
[0, 1, 1/3, 0, 2, 1],
[0, 0, 0, 0, 3, 0],
[0, 0, 0, 0, 3, 0]])

def test_stats_weights(self):
X = np.arange(4).reshape(2, 2).astype(float)
Expand Down

0 comments on commit 20e7e66

Please sign in to comment.