-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* FEAT Extract core points * Fix versioning
- Loading branch information
Showing
4 changed files
with
82 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1 @@ | ||
from .copac import COPAC, copac | ||
|
||
__all__ = [ | ||
'COPAC', | ||
'copac', | ||
'__version__', | ||
] | ||
__version__ = "0.3.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,40 @@ | ||
""" | ||
Testing for Clustering methods | ||
""" | ||
import unittest | ||
import pytest | ||
|
||
import numpy as np | ||
|
||
from sklearn.metrics.cluster import v_measure_score | ||
from sklearn.utils.testing import assert_equal, assert_array_equal | ||
from sklearn.datasets.samples_generator import make_blobs | ||
from sklearn.datasets import make_blobs | ||
|
||
from ..copac import COPAC | ||
|
||
|
||
class TestCopac(unittest.TestCase): | ||
|
||
def setUp(self): | ||
""" Set up very simple data set """ | ||
self.n_clusters = 2 | ||
self.centers = np.array([[3, 3], [-3, -3]]) + 10 | ||
self.X, self.y = make_blobs(n_samples=60, n_features=2, | ||
centers=self.centers, cluster_std=0.4, | ||
shuffle=True, random_state=0) | ||
self.v = v_measure_score(self.y, self.y) | ||
|
||
def tearDown(self): | ||
del self.n_clusters, self.centers, self.X | ||
|
||
def test_copac(self): | ||
""" Minimal test that COPAC runs at all. """ | ||
k = 40 | ||
mu = 10 | ||
eps = 2 | ||
alpha = 0.85 | ||
copac = COPAC(k=k, mu=mu, eps=eps, alpha=alpha) | ||
y_pred = copac.fit_predict(self.X) | ||
v = v_measure_score(self.y, y_pred) | ||
# Must score perfectly on very simple data | ||
assert_equal(self.v, v) | ||
# Check correct labels_ attribute | ||
copac = COPAC(k=k, mu=mu, eps=eps, alpha=alpha) | ||
copac.fit(self.X) | ||
assert_array_equal(copac.labels_, y_pred) | ||
|
||
if __name__ == "__main__": | ||
unittest.main() | ||
@pytest.mark.parametrize("return_core_pts", [True, False]) | ||
def test_copac(return_core_pts): | ||
""" Minimal test that COPAC runs at all. """ | ||
# Set up very simple data set | ||
n_clusters = 2 | ||
centers = np.array([[3, 3], [-3, -3]]) + 10 | ||
X, y = make_blobs(n_samples=60, n_features=2, | ||
centers=centers, cluster_std=0.4, | ||
shuffle=True, random_state=0) | ||
v_true = v_measure_score(y, y) | ||
|
||
k = 40 | ||
mu = 10 | ||
eps = 2 | ||
alpha = 0.85 | ||
|
||
copac = COPAC(k=k, mu=mu, eps=eps, alpha=alpha) | ||
y_pred = copac.fit_predict(X, return_core_pts=return_core_pts) | ||
if return_core_pts: | ||
y_pred, core_pts_ind = y_pred | ||
assert isinstance(core_pts_ind, dict) | ||
v_pred = v_measure_score(y, y_pred) | ||
# Must score perfectly on very simple data | ||
np.testing.assert_equal(v_true, v_pred) | ||
# Check correct labels_ attribute | ||
copac = COPAC(k=k, mu=mu, eps=eps, alpha=alpha) | ||
copac.fit(X) | ||
np.testing.assert_array_equal(copac.labels_, y_pred) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters