Skip to content

Commit

Permalink
Add OptimalK init config validation
Browse files Browse the repository at this point in the history
Also fix setup deps
  • Loading branch information
milesgranger committed May 19, 2019
1 parent bdb4af1 commit 7b71eb8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
5 changes: 5 additions & 0 deletions gap_statistic/optimalK.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ def __init__(
:param clusterer:
:param clusterer_kwargs:
"""
if clusterer is not None and parallel_backend == "rust":
raise ValueError(
"Cannot use 'rust' backend with a user defined clustering function, only KMeans"
" is supported on the rust implementation"
)
self.parallel_backend = (
parallel_backend
if parallel_backend in ["joblib", "multiprocessing", "rust"]
Expand Down
10 changes: 9 additions & 1 deletion tests/test_optimalK.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,19 @@

import numpy as np
from sklearn.datasets.samples_generator import make_blobs
from sklearn.cluster import SpectralClustering, KMeans, MeanShift
from sklearn.cluster import KMeans, MeanShift

from gap_statistic import OptimalK


def test_bad_init_config():
"""
Cannot define own clustering function and try to use Rust backend
"""
with pytest.raises(ValueError):
OptimalK(parallel_backend="rust", clusterer=lambda x, k: print("just testing"))


@pytest.mark.parametrize("ClusterModel", [KMeans, MeanShift])
def test_alternative_clusting_method(ClusterModel):
"""
Expand Down

0 comments on commit 7b71eb8

Please sign in to comment.