Skip to content

Commit 41253f6

Browse files
committed
Add class check when setting n_init
1 parent 2d06e3c commit 41253f6

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

kmodes/kmodes.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -102,16 +102,17 @@ def __init__(self, n_clusters=8, max_iter=100, cat_dissim=matching_dissim,
102102
self.max_iter = max_iter
103103
self.cat_dissim = cat_dissim
104104
self.init = init
105-
self.n_init = n_init
106105
self.verbose = verbose
107106
self.random_state = random_state
108107
self.n_jobs = n_jobs
109-
if ((isinstance(self.init, str) and self.init == 'Cao') or
110-
hasattr(self.init, '__array__')) and self.n_init > 1:
111-
if self.verbose:
112-
print("Initialization method and algorithm are deterministic. "
113-
"Setting n_init to 1.")
114-
self.n_init = 1
108+
if self.__class__ == KModes:
109+
self.n_init = n_init
110+
if ((isinstance(self.init, str) and self.init == 'Cao') or
111+
hasattr(self.init, '__array__')) and self.n_init > 1:
112+
if self.verbose:
113+
print("Initialization method and algorithm are deterministic. "
114+
"Setting n_init to 1.")
115+
self.n_init = 1
115116

116117
def fit(self, X, y=None, sample_weight=None, **kwargs):
117118
"""Compute k-modes clustering.

0 commit comments

Comments
 (0)