Skip to content

Commit

Permalink
feat: Add docstrings to the getter methods for hyperparameters in Reg…
Browse files Browse the repository at this point in the history
…ression and Classification models (#371)

Closes #313

### Summary of Changes

* feat: Added docstrings in all getter methods of Hyperparameters for
classification and regression models.
* feat: Added docstrings in all methods of class Kernel in
SupportVectorMachine for classification and regression models.

---------

Co-authored-by: megalinter-bot <129584137+megalinter-bot@users.noreply.github.com>
  • Loading branch information
jxnior01 and megalinter-bot committed Jun 23, 2023
1 parent 7f07f29 commit 9073f04
Show file tree
Hide file tree
Showing 13 changed files with 266 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/safeds/ml/classical/classification/_ada_boost.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,38 @@ def __init__(

@property
def learner(self) -> Classifier | None:
"""
Get the base learner used for training the ensemble.
Returns
-------
result: Classifier | None
The base learner.
"""
return self._learner

@property
def maximum_number_of_learners(self) -> int:
"""
Get the maximum number of learners in the ensemble.
Returns
-------
result: int
The maximum number of learners.
"""
return self._maximum_number_of_learners

@property
def learning_rate(self) -> float:
"""
Get the learning rate.
Returns
-------
result: float
The learning rate.
"""
return self._learning_rate

def fit(self, training_set: TaggedTable) -> AdaBoost:
Expand Down
16 changes: 16 additions & 0 deletions src/safeds/ml/classical/classification/_gradient_boosting.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,26 @@ def __init__(self, *, number_of_trees: int = 100, learning_rate: float = 0.1) ->

@property
def number_of_trees(self) -> int:
"""
Get the number of trees (estimators) in the ensemble.
Returns
-------
result: int
The number of trees.
"""
return self._number_of_trees

@property
def learning_rate(self) -> float:
"""
Get the learning rate.
Returns
-------
result: float
The learning rate.
"""
return self._learning_rate

def fit(self, training_set: TaggedTable) -> GradientBoosting:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ def __init__(self, number_of_neighbors: int) -> None:

@property
def number_of_neighbors(self) -> int:
"""
Get the number of neighbors used for interpolation.
Returns
-------
result: int
The number of neighbors.
"""
return self._number_of_neighbors

def fit(self, training_set: TaggedTable) -> KNearestNeighbors:
Expand Down
8 changes: 8 additions & 0 deletions src/safeds/ml/classical/classification/_random_forest.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ def __init__(self, *, number_of_trees: int = 100) -> None:

@property
def number_of_trees(self) -> int:
"""
Get the number of trees used in the random forest.
Returns
-------
result: int
The number of trees.
"""
return self._number_of_trees

def fit(self, training_set: TaggedTable) -> RandomForest:
Expand Down
61 changes: 61 additions & 0 deletions src/safeds/ml/classical/classification/_support_vector_machine.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,39 @@ def __init__(self, *, c: float = 1.0, kernel: SupportVectorMachineKernel | None

@property
def c(self) -> float:
"""
Get the regularization strength.
Returns
-------
result: float
The regularization strength.
"""
return self._c

@property
def kernel(self) -> SupportVectorMachineKernel | None:
"""
Get the type of kernel used.
Returns
-------
result: SupportVectorMachineKernel | None
The type of kernel used.
"""
return self._kernel

class Kernel:
class Linear(SupportVectorMachineKernel):
def get_sklearn_kernel(self) -> str:
"""
Get the name of the linear kernel.
Returns
-------
result: str
The name of the linear kernel.
"""
return "linear"

class Polynomial(SupportVectorMachineKernel):
Expand All @@ -77,17 +101,54 @@ def __init__(self, degree: int):
self._degree = degree

def get_sklearn_kernel(self) -> str:
"""
Get the name of the polynomial kernel.
Returns
-------
result: str
The name of the polynomial kernel.
"""
return "poly"

class Sigmoid(SupportVectorMachineKernel):
def get_sklearn_kernel(self) -> str:
"""
Get the name of the sigmoid kernel.
Returns
-------
result: str
The name of the sigmoid kernel.
"""
return "sigmoid"

class RadialBasisFunction(SupportVectorMachineKernel):
def get_sklearn_kernel(self) -> str:
"""
Get the name of the radial basis function (RBF) kernel.
Returns
-------
result: str
The name of the RBF kernel.
"""
return "rbf"

def _get_kernel_name(self) -> str:
"""
Get the name of the kernel.
Returns
-------
result: str
The name of the kernel.
Raises
------
TypeError
If the kernel type is invalid.
"""
if isinstance(self.kernel, SupportVectorMachine.Kernel.Linear):
return "linear"
elif isinstance(self.kernel, SupportVectorMachine.Kernel.Polynomial):
Expand Down
24 changes: 24 additions & 0 deletions src/safeds/ml/classical/regression/_ada_boost.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,38 @@ def __init__(

@property
def learner(self) -> Regressor | None:
"""
Get the base learner used for training the ensemble.
Returns
-------
result: Classifier | None
The base learner.
"""
return self._learner

@property
def maximum_number_of_learners(self) -> int:
"""
Get the maximum number of learners in the ensemble.
Returns
-------
result: int
The maximum number of learners.
"""
return self._maximum_number_of_learners

@property
def learning_rate(self) -> float:
"""
Get the learning rate.
Returns
-------
result: float
The learning rate.
"""
return self._learning_rate

def fit(self, training_set: TaggedTable) -> AdaBoost:
Expand Down
16 changes: 16 additions & 0 deletions src/safeds/ml/classical/regression/_elastic_net_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,26 @@ def __init__(self, *, alpha: float = 1.0, lasso_ratio: float = 0.5) -> None:

@property
def alpha(self) -> float:
"""
Get the regularization of the model.
Returns
-------
result: float
The regularization of the model.
"""
return self._alpha

@property
def lasso_ratio(self) -> float:
"""
Get the ratio between Lasso and Ridge regularization.
Returns
-------
result: float
The ratio between Lasso and Ridge regularization.
"""
return self._lasso_ratio

def fit(self, training_set: TaggedTable) -> ElasticNetRegression:
Expand Down
16 changes: 16 additions & 0 deletions src/safeds/ml/classical/regression/_gradient_boosting.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,26 @@ def __init__(self, *, number_of_trees: int = 100, learning_rate: float = 0.1) ->

@property
def number_of_trees(self) -> int:
"""
Get the number of trees (estimators) in the ensemble.
Returns
-------
result: int
The number of trees.
"""
return self._number_of_trees

@property
def learning_rate(self) -> float:
"""
Get the learning rate.
Returns
-------
result: float
The learning rate.
"""
return self._learning_rate

def fit(self, training_set: TaggedTable) -> GradientBoosting:
Expand Down
8 changes: 8 additions & 0 deletions src/safeds/ml/classical/regression/_k_nearest_neighbors.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ def __init__(self, number_of_neighbors: int) -> None:

@property
def number_of_neighbors(self) -> int:
"""
Get the number of neighbors used for interpolation.
Returns
-------
result: int
The number of neighbors.
"""
return self._number_of_neighbors

def fit(self, training_set: TaggedTable) -> KNearestNeighbors:
Expand Down
8 changes: 8 additions & 0 deletions src/safeds/ml/classical/regression/_lasso_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ def __init__(self, *, alpha: float = 1.0) -> None:

@property
def alpha(self) -> float:
"""
Get the regularization of the model.
Returns
-------
result: float
The regularization of the model.
"""
return self._alpha

def fit(self, training_set: TaggedTable) -> LassoRegression:
Expand Down
8 changes: 8 additions & 0 deletions src/safeds/ml/classical/regression/_random_forest.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ def __init__(self, *, number_of_trees: int = 100) -> None:

@property
def number_of_trees(self) -> int:
"""
Get the number of trees used in the random forest.
Returns
-------
result: int
The number of trees.
"""
return self._number_of_trees

def fit(self, training_set: TaggedTable) -> RandomForest:
Expand Down
8 changes: 8 additions & 0 deletions src/safeds/ml/classical/regression/_ridge_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ def __init__(self, *, alpha: float = 1.0) -> None:

@property
def alpha(self) -> float:
"""
Get the regularization of the model.
Returns
-------
result: float
The regularization of the model.
"""
return self._alpha

def fit(self, training_set: TaggedTable) -> RidgeRegression:
Expand Down

0 comments on commit 9073f04

Please sign in to comment.