Skip to content

Commit

Permalink
feat: rename n_neighbors to number_of_neighbors (#162)
Browse files Browse the repository at this point in the history
### Summary of Changes

Rename the `n_neighbors` parameter of `KNearestNeighbors` to
`number_of_neighbors` for the sake of consistency.
  • Loading branch information
lars-reimann committed Apr 4, 2023
1 parent ed7ae34 commit 526b96e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
10 changes: 5 additions & 5 deletions src/safeds/ml/classification/_k_nearest_neighbors.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ class KNearestNeighbors(Classifier):
Parameters
----------
n_neighbors : int
number_of_neighbors : int
The number of neighbors to be interpolated with. Has to be less than or equal to the sample size.
"""

def __init__(self, n_neighbors: int) -> None:
self._n_neighbors = n_neighbors
def __init__(self, number_of_neighbors: int) -> None:
self._number_of_neighbors = number_of_neighbors

self._wrapped_classifier: sk_KNeighborsClassifier | None = None
self._feature_names: list[str] | None = None
Expand All @@ -50,10 +50,10 @@ def fit(self, training_set: TaggedTable) -> KNearestNeighbors:
LearningError
If the training data contains invalid values or if the training failed.
"""
wrapped_classifier = sk_KNeighborsClassifier(self._n_neighbors, n_jobs=-1)
wrapped_classifier = sk_KNeighborsClassifier(self._number_of_neighbors, n_jobs=-1)
fit(wrapped_classifier, training_set)

result = KNearestNeighbors(self._n_neighbors)
result = KNearestNeighbors(self._number_of_neighbors)
result._wrapped_classifier = wrapped_classifier
result._feature_names = training_set.features.get_column_names()
result._target_name = training_set.target.name
Expand Down
10 changes: 5 additions & 5 deletions src/safeds/ml/regression/_k_nearest_neighbors.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ class KNearestNeighbors(Regressor):
Parameters
----------
n_neighbors : int
number_of_neighbors : int
The number of neighbors to be interpolated with. Has to be less than or equal than the sample size.
"""

def __init__(self, n_neighbors: int) -> None:
self._n_neighbors = n_neighbors
def __init__(self, number_of_neighbors: int) -> None:
self._number_of_neighbors = number_of_neighbors

self._wrapped_regressor: sk_KNeighborsRegressor | None = None
self._feature_names: list[str] | None = None
Expand All @@ -50,10 +50,10 @@ def fit(self, training_set: TaggedTable) -> KNearestNeighbors:
LearningError
If the training data contains invalid values or if the training failed.
"""
wrapped_regressor = sk_KNeighborsRegressor(self._n_neighbors, n_jobs=-1)
wrapped_regressor = sk_KNeighborsRegressor(self._number_of_neighbors, n_jobs=-1)
fit(wrapped_regressor, training_set)

result = KNearestNeighbors(self._n_neighbors)
result = KNearestNeighbors(self._number_of_neighbors)
result._wrapped_regressor = wrapped_regressor
result._feature_names = training_set.features.get_column_names()
result._target_name = training_set.target.name
Expand Down

0 comments on commit 526b96e

Please sign in to comment.