-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add nochange and majority class classifiers
- Loading branch information
1 parent
7c1507f
commit 0c822c1
Showing
4 changed files
with
109 additions
and
3 deletions.
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
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,48 @@ | ||
from __future__ import annotations | ||
from typing import Union | ||
|
||
from capymoa.base import ( | ||
MOAClassifier, | ||
) | ||
from capymoa.stream import Schema | ||
from capymoa._utils import build_cli_str_from_mapping_and_locals | ||
|
||
from moa.classifiers.functions import MajorityClass as _MOA_MajorityClass | ||
|
||
|
||
class MajorityClass(MOAClassifier): | ||
"""Majority class classifier. | ||
Always predicts the class that has been observed most frequently the in the training data. | ||
Example usages: | ||
>>> from capymoa.datasets import ElectricityTiny | ||
>>> from capymoa.classifier import MajorityClass | ||
>>> from capymoa.evaluation import prequential_evaluation | ||
>>> stream = ElectricityTiny() | ||
>>> schema = stream.get_schema() | ||
>>> learner = MajorityClass(schema) | ||
>>> results = prequential_evaluation(stream, learner, max_instances=1000) | ||
>>> results["cumulative"].accuracy() | ||
50.2 | ||
""" | ||
|
||
def __init__( | ||
self, | ||
schema: Schema | None = None, | ||
): | ||
"""Majority class classifier. | ||
:param schema: The schema of the stream. | ||
""" | ||
|
||
mapping = { | ||
} | ||
|
||
config_str = build_cli_str_from_mapping_and_locals(mapping, locals()) | ||
super(MajorityClass, self).__init__( | ||
moa_learner=_MOA_MajorityClass, | ||
schema=schema, | ||
CLI=config_str, | ||
) |
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,48 @@ | ||
from __future__ import annotations | ||
from typing import Union | ||
|
||
from capymoa.base import ( | ||
MOAClassifier, | ||
) | ||
from capymoa.stream import Schema | ||
from capymoa._utils import build_cli_str_from_mapping_and_locals | ||
|
||
from moa.classifiers.functions import NoChange as _MOA_NoChange | ||
|
||
|
||
class NoChange(MOAClassifier): | ||
"""NoChange classifier. | ||
Always predicts the last class seen. | ||
Example usages: | ||
>>> from capymoa.datasets import ElectricityTiny | ||
>>> from capymoa.classifier import NoChange | ||
>>> from capymoa.evaluation import prequential_evaluation | ||
>>> stream = ElectricityTiny() | ||
>>> schema = stream.get_schema() | ||
>>> learner = NoChange(schema) | ||
>>> results = prequential_evaluation(stream, learner, max_instances=1000) | ||
>>> results["cumulative"].accuracy() | ||
85.9 | ||
""" | ||
|
||
def __init__( | ||
self, | ||
schema: Schema | None = None, | ||
): | ||
"""NoChange class classifier. | ||
:param schema: The schema of the stream. | ||
""" | ||
|
||
mapping = { | ||
} | ||
|
||
config_str = build_cli_str_from_mapping_and_locals(mapping, locals()) | ||
super(NoChange, self).__init__( | ||
moa_learner=_MOA_NoChange, | ||
schema=schema, | ||
CLI=config_str, | ||
) |
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