-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Added capymoa wrapper for OUAE algorithm #184
Open
DwayneAcosta
wants to merge
3
commits into
adaptive-machine-learning:main
Choose a base branch
from
DwayneAcosta:OnlineAccuracyUpdatedEnsemble
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+89
−2
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
src/capymoa/classifier/_online_accuracy_updated_ensemble.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
from capymoa.base import MOAClassifier | ||
from moa.classifiers.meta import OnlineAccuracyUpdatedEnsemble as _MOA_OnlineAccuracyUpdatedEnsemble | ||
from capymoa.stream import Schema | ||
from capymoa._utils import build_cli_str_from_mapping_and_locals | ||
|
||
|
||
class OnlineAccuracyUpdatedEnsemble(MOAClassifier): | ||
"""OnlineAccuracyUpdatedEnsemble | ||
|
||
The online version of the Accuracy Updated Ensemble as proposed by | ||
Brzezinski and Stefanowski in "Combining block-based and online methods | ||
in learning ensembles from concept drifting data streams", Information Sciences, 2014. | ||
|
||
Reference: | ||
|
||
`Combining block-based and online methods in learning ensembles from concept drifting data streams. | ||
Daruisz Brzezinski, Jerzy Stefanowski | ||
IS, 2014. | ||
<https://doi.org/10.1016/j.ins.2013.12.011>`_ | ||
|
||
Example usages: | ||
|
||
>>> from capymoa.datasets import ElectricityTiny | ||
>>> from capymoa.classifier import OnlineAccuracyUpdatedEnsemble | ||
>>> from capymoa.evaluation import prequential_evaluation | ||
>>> stream = ElectricityTiny() | ||
>>> schema = stream.get_schema() | ||
>>> learner = OnlineAccuracyUpdatedEnsemble(schema) | ||
>>> results = prequential_evaluation(stream, learner, max_instances=1000) | ||
>>> results["cumulative"].accuracy() | ||
87.5 | ||
""" | ||
|
||
|
||
def __init__( | ||
self, | ||
schema: Schema, | ||
random_seed: int = 1, | ||
learner_option= 'trees.HoeffdingTree -e 2000000 -g 100 -c 0.01', | ||
member_count_option: int = 5, | ||
window_size_option: float = 50.0, | ||
max_byte_size_option: int = 33554432, | ||
verbose_option: bool = False, | ||
linear_option: bool = False, | ||
): | ||
|
||
|
||
""" Online Accuracy Updated Ensemble Classifier | ||
|
||
:param schema: The schema of the stream. | ||
:param learner_option: Classifier to train. | ||
:param member_count_option: The maximum number of classifiers in an ensemble. | ||
:param window_size_option: The window size used for classifier creation and evaluation. | ||
:param max_byte_size_option: Maximum memory consumed by ensemble. | ||
:param verbose_option: When checked the algorithm outputs additional information about component classifier weights. | ||
:param linear_option: When checked the algorithm uses a linear weighting function. | ||
""" | ||
|
||
|
||
mapping = { | ||
"learner_option": "-l", | ||
"member_count_option": "-n", | ||
"window_size_option": "-w", | ||
"max_byte_size_option": "-m", | ||
"verbose_option": "-v", | ||
"linear_option": "-f", | ||
} | ||
|
||
|
||
assert (type(learner_option) == str | ||
), "Only MOA CLI strings are supported for SGBT base_learner, at the moment." | ||
|
||
|
||
config_str = build_cli_str_from_mapping_and_locals(mapping, locals()) | ||
self.moa_learner = _MOA_OnlineAccuracyUpdatedEnsemble() | ||
super(OnlineAccuracyUpdatedEnsemble, self).__init__( | ||
schema=schema, | ||
random_seed=random_seed, | ||
CLI=config_str, | ||
moa_learner=self.moa_learner, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please change SGBT to OnlineAccuracyUpdatedEnsemble