aeon-toolkit / aeon

A toolkit for machine learning from time series
https://aeon-toolkit.org/
BSD 3-Clause "New" or "Revised" License
1.02k stars 125 forks source link

[ENH] Add PyODAdapter-implementation for IsolationForest #2108

Closed SebastianSchmidl closed 1 month ago

SebastianSchmidl commented 1 month ago

Describe the feature or idea you want to propose

The PyODAdapter in aeon allows us to use any outlier detector from PyOD, which were originally proposed for relational data, also for time series anomaly detection (TSAD). Not all detectors are equally well suited for TSAD, however. We want to represent the frequently used and competitive outlier detection techniques within the anomaly_detection module of aeon directly.

Implement the IsolationForest method using the PyODAdapter.

Describe your proposed solution


Example for IsolationForest:

class IsolationForest(PyODAdapter):
    """documentation ..."""
    def __init__(n_estimators: int = 100, max_samples: int | str = "auto", ..., window_size: int, stride: int):
        model = IForest(n_estimators, max_samples, ...
        super().__init__(model, window_size, stride)

    @classmethod
    def get_test_params(cls, parameter_set="default"):
        """..."""
        return {"n_estimators": 10, ...}

Describe alternatives you've considered, if relevant

No response

Additional context

No response

notaryanramani commented 1 month ago

Just wanted to get a feedback on how I plan to solve this problem:

  1. Create IsolationForest class inherited from PyODAdapter
  2. Create instance of IForest from pyod, then call super constructor.
  3. Define fit, predict and fit_predict methods to call _fit, _predict and _fit_predict from parent class respectively.
  4. Override the get_test_params method.
  5. Document everything.
  6. Write test cases.

Is there anything else you would like me to be aware about?

SebastianSchmidl commented 1 month ago

I am convinced that step 3 is not necessary. The PyODAdapter should already contain the logic required (anyway, please never override fit, predict and fit_predict methods; estimators are just allowed to overwrite the _fit, _predict, and _fit_predict methods).

No, just give it a shot, and we'll take a look at the PR afterward 👍🏼

notaryanramani commented 1 month ago

Okay! Can you assign this issue to me?

SebastianSchmidl commented 1 month ago

@aeon-actions-bot assign notaryanramani


EXIT: hm, the bot seems to be broken 🤔