Skip to content

Commit

Permalink
Modify KNNClassificationVoter to default k=None and internally calcul…
Browse files Browse the repository at this point in the history
…ate k

To address issue #112
  • Loading branch information
levinwil authored Sep 10, 2020
1 parent 5c91c1b commit b42424b
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions proglearn/voters.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def _finite_sample_correction(posteriors, num_points_in_partition, num_classes):


class KNNClassificationVoter(BaseVoter):
def __init__(self, k, kwargs={}):
def __init__(self, k=None, kwargs={}):
"""
Doc strings here.
"""
Expand All @@ -110,7 +110,8 @@ def fit(self, X, y):
Doc strings here.
"""
X, y = check_X_y(X, y)
self.knn = KNeighborsClassifier(self.k, **self.kwargs)
k = int(np.log2(len(X))) if self.k == None else self.k
self.knn = KNeighborsClassifier(k, **self.kwargs)
self.knn.fit(X, y)
self._is_fitted = True

Expand Down

0 comments on commit b42424b

Please sign in to comment.