-
-
Notifications
You must be signed in to change notification settings - Fork 26k
[MRG+2] faster way of computing means across each group #10020
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
Changes from all commits
9807ef0
dfcd422
b36422c
534f757
f37287a
593c8ed
94ad19a
3defcd6
7b5de28
5818abf
ef786c6
fba7691
2f9846c
72caa77
a35000b
9684ebe
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
""" | ||
Tests for sklearn.cluster._feature_agglomeration | ||
""" | ||
# Authors: Sergul Aydore 2017 | ||
import numpy as np | ||
from sklearn.cluster import FeatureAgglomeration | ||
from sklearn.utils.testing import assert_true | ||
from sklearn.utils.testing import assert_array_almost_equal | ||
|
||
|
||
def test_feature_agglomeration(): | ||
n_clusters = 1 | ||
X = np.array([0, 0, 1]).reshape(1, 3) # (n_samples, n_features) | ||
|
||
agglo_mean = FeatureAgglomeration(n_clusters=n_clusters, | ||
pooling_func=np.mean) | ||
agglo_median = FeatureAgglomeration(n_clusters=n_clusters, | ||
pooling_func=np.median) | ||
agglo_mean.fit(X) | ||
agglo_median.fit(X) | ||
assert_true(np.size(np.unique(agglo_mean.labels_)) == n_clusters) | ||
assert_true(np.size(np.unique(agglo_median.labels_)) == n_clusters) | ||
assert_true(np.size(agglo_mean.labels_) == X.shape[1]) | ||
assert_true(np.size(agglo_median.labels_) == X.shape[1]) | ||
|
||
# Test transform | ||
Xt_mean = agglo_mean.transform(X) | ||
Xt_median = agglo_median.transform(X) | ||
assert_true(Xt_mean.shape[1] == n_clusters) | ||
assert_true(Xt_median.shape[1] == n_clusters) | ||
assert_true(Xt_mean == np.array([1 / 3.])) | ||
assert_true(Xt_median == np.array([0.])) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. did we stop using assert_equal with the switch towards pytest? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I used |
||
|
||
# Test inverse transform | ||
X_full_mean = agglo_mean.inverse_transform(Xt_mean) | ||
X_full_median = agglo_median.inverse_transform(Xt_median) | ||
assert_true(np.unique(X_full_mean[0]).size == n_clusters) | ||
assert_true(np.unique(X_full_median[0]).size == n_clusters) | ||
|
||
assert_array_almost_equal(agglo_mean.transform(X_full_mean), | ||
Xt_mean) | ||
assert_array_almost_equal(agglo_median.transform(X_full_median), | ||
Xt_median) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should test the size of labels_ too