From 526b96e3877299eb6bf6adea2882065fd29b52cf Mon Sep 17 00:00:00 2001 From: Lars Reimann Date: Tue, 4 Apr 2023 16:48:53 +0200 Subject: [PATCH] feat: rename `n_neighbors` to `number_of_neighbors` (#162) ### Summary of Changes Rename the `n_neighbors` parameter of `KNearestNeighbors` to `number_of_neighbors` for the sake of consistency. --- src/safeds/ml/classification/_k_nearest_neighbors.py | 10 +++++----- src/safeds/ml/regression/_k_nearest_neighbors.py | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/safeds/ml/classification/_k_nearest_neighbors.py b/src/safeds/ml/classification/_k_nearest_neighbors.py index 6cc7f44e3..fe23bb5f9 100644 --- a/src/safeds/ml/classification/_k_nearest_neighbors.py +++ b/src/safeds/ml/classification/_k_nearest_neighbors.py @@ -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 @@ -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 diff --git a/src/safeds/ml/regression/_k_nearest_neighbors.py b/src/safeds/ml/regression/_k_nearest_neighbors.py index 2cfe27a51..b5b527e2c 100644 --- a/src/safeds/ml/regression/_k_nearest_neighbors.py +++ b/src/safeds/ml/regression/_k_nearest_neighbors.py @@ -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 @@ -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