diff --git a/src/capymoa/base.py b/src/capymoa/base.py index a5a1e9ed..7b1495e5 100644 --- a/src/capymoa/base.py +++ b/src/capymoa/base.py @@ -69,7 +69,7 @@ def _extract_moa_learner_CLI(learner): A string representing the CLI command for creating the MOA learner. """ - # Check if the base_learner is a MOAClassifie or a MOARegressor + # Check if the base_learner is a MOAClassifier or a MOARegressor if isinstance(learner, MOAClassifier) or isinstance(learner, MOARegressor): learner = _get_moa_creation_CLI(learner.moa_learner) @@ -214,6 +214,8 @@ class SKClassifier(Classifier): A word of caution: even compatible scikit-learn classifiers are not necessarily designed for online learning and might require some tweaking to work well in an online setting. + + See also :class:`capymoa.base.SKRegressor` for scikit-learn regressors. """ sklearner: _SKClassifierMixin @@ -224,7 +226,7 @@ def __init__(self, sklearner: _SKClassifierMixin, schema: Schema = None, random_ :param sklearner: A scikit-learn classifier object to wrap that must implements ``partial_fit`` and ``predict``. - :param schema: Descibes the structure of the datastream. + :param schema: Describes the structure of the datastream. :param random_seed: Random seed for reproducibility. :raises ValueError: If the scikit-learn algorithm does not implement ``partial_fit`` or ``predict``. @@ -346,21 +348,20 @@ def predict(self, instance): class SKRegressor(Regressor): - """A wrapper class for using scikit-learn classifiers in CapyMOA. + """A wrapper class for using scikit-learn regressors in CapyMOA. - Some of scikit-learn's classifiers that are compatible with online learning + Some of scikit-learn's regressors that are compatible with online learning have been wrapped and tested already in CapyMOA (See :mod:`capymoa.regressor`). - However, if you want to use a scikit-learn classifier that has not been + However, if you want to use a scikit-learn regressor that has not been wrapped yet, you can use this class to wrap it yourself. This requires - that the scikit-learn classifier implements the ``partial_fit`` and + that the scikit-learn regressor implements the ``partial_fit`` and ``predict`` methods. For example, the following code demonstrates how to use a scikit-learn - classifier in CapyMOA: + regressor in CapyMOA: >>> from sklearn.linear_model import SGDRegressor - >>> from capymoa.base import SKClassifier >>> from capymoa.datasets import Fried >>> stream = Fried() >>> sklearner = SGDRegressor(random_state=1) @@ -381,9 +382,11 @@ class SKRegressor(Regressor): y_value: 18.566, y_prediction: 3.8024999398093753 y_value: 12.107, y_prediction: 3.8708584184864403 - A word of caution: even compatible scikit-learn classifiers are not + A word of caution: even compatible scikit-learn regressors are not necessarily designed for online learning and might require some tweaking to work well in an online setting. + + See also :class:`capymoa.base.SKClassifier` for scikit-learn classifiers. """ sklearner: _SKRegressorMixin @@ -394,7 +397,7 @@ def __init__(self, sklearner: _SKRegressorMixin, schema: Schema = None, random_s :param sklearner: A scikit-learn classifier object to wrap that must implements ``partial_fit`` and ``predict``. - :param schema: Descibes the structure of the datastream. + :param schema: Describes the structure of the datastream. :param random_seed: Random seed for reproducibility. :raises ValueError: If the scikit-learn algorithm does not implement ``partial_fit`` or ``predict``. diff --git a/src/capymoa/classifier/_passive_aggressive_classifier.py b/src/capymoa/classifier/_passive_aggressive_classifier.py index e83d1f43..8d09ce33 100644 --- a/src/capymoa/classifier/_passive_aggressive_classifier.py +++ b/src/capymoa/classifier/_passive_aggressive_classifier.py @@ -1,7 +1,7 @@ from typing import Optional, Dict, Union, Literal from capymoa.base import SKClassifier from sklearn.linear_model import ( - PassiveAggressiveClassifier as skPassiveAggressiveClassifier, + PassiveAggressiveClassifier as _SKPassiveAggressiveClassifier, ) from capymoa.stream._stream import Schema @@ -28,7 +28,7 @@ class PassiveAggressiveClassifier(SKClassifier): 84.3 """ - sklearner: skPassiveAggressiveClassifier + sklearner: _SKPassiveAggressiveClassifier """The underlying scikit-learn object. See: :sklearn:`linear_model.PassiveAggressiveClassifier`""" def __init__( @@ -70,7 +70,7 @@ def __init__( """ super().__init__( - skPassiveAggressiveClassifier( + _SKPassiveAggressiveClassifier( C=max_step_size, fit_intercept=fit_intercept, early_stopping=False, diff --git a/src/capymoa/classifier/_sgd_classifier.py b/src/capymoa/classifier/_sgd_classifier.py index 5f114fc2..7d9225bc 100644 --- a/src/capymoa/classifier/_sgd_classifier.py +++ b/src/capymoa/classifier/_sgd_classifier.py @@ -1,7 +1,7 @@ from typing import Optional, Literal from capymoa.base import SKClassifier from sklearn.linear_model import ( - SGDClassifier as skSGDClassifier, + SGDClassifier as _SKSGDClassifier, ) from capymoa.stream._stream import Schema @@ -25,7 +25,7 @@ class SGDClassifier(SKClassifier): 84.2 """ - sklearner: skSGDClassifier + sklearner: _SKSGDClassifier """The underlying scikit-learn object""" def __init__( @@ -86,7 +86,7 @@ def __init__( """ super().__init__( - skSGDClassifier( + _SKSGDClassifier( loss=loss, penalty=penalty, alpha=alpha, diff --git a/src/capymoa/regressor/_passive_aggressive_regressor.py b/src/capymoa/regressor/_passive_aggressive_regressor.py index cde1c095..f95c00c1 100644 --- a/src/capymoa/regressor/_passive_aggressive_regressor.py +++ b/src/capymoa/regressor/_passive_aggressive_regressor.py @@ -1,6 +1,6 @@ from capymoa.base import SKRegressor from sklearn.linear_model import ( - PassiveAggressiveRegressor as skPassiveAggressiveRegressor, + PassiveAggressiveRegressor as _SKPassiveAggressiveRegressor, ) from capymoa.stream._stream import Schema @@ -27,7 +27,7 @@ class PassiveAggressiveRegressor(SKRegressor): 3.7... """ - sklearner: skPassiveAggressiveRegressor + sklearner: _SKPassiveAggressiveRegressor """The underlying scikit-learn object. See: :sklearn:`linear_model.PassiveAggressiveRegressor`""" def __init__( @@ -60,7 +60,7 @@ def __init__( """ super().__init__( - skPassiveAggressiveRegressor( + _SKPassiveAggressiveRegressor( C=max_step_size, fit_intercept=fit_intercept, early_stopping=False,