Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] statistics.utils: Fix stats for sparse when last column missing #1432

Merged
merged 1 commit into from
Jul 15, 2016
Merged
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
2 changes: 1 addition & 1 deletion Orange/statistics/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ def stats(X, weights=None, compute_variance=False):
if compute_variance:
raise NotImplementedError

non_zero = np.bincount(X.nonzero()[1])
non_zero = np.bincount(X.nonzero()[1], minlength=X.shape[1])
X = X.tocsc()
return np.column_stack((
X.min(axis=0).toarray().ravel(),
Expand Down
8 changes: 8 additions & 0 deletions Orange/tests/test_statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,11 @@ def test_stats_sparse(self):
[0, 1, .2, 0, 4, 1],
[0, 1, .2, 0, 4, 1],
[0, 1, .2, 0, 4, 1]])

# 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]])