code: def test_EnsembleSklearn(self):
      # Need to input an EnsembleSklearn model
      with pytest.raises(ValueError):
          EnsembleSklearnAggregator(
              model=MovingAverageFilter(window=10)
          )
  
      # simple case
      # series has 3 components, and real_anomalies_3w is equal to
      # - component 1 when component 3 is 1
      # - component 2 when component 3 is 0
      # must have a high accuracy (here 0.92)
      aggregator = EnsembleSklearnAggregator(
          model=GradientBoostingClassifier(
              n_estimators=50, learning_rate=1.0, max_depth=1
          )
      )
      aggregator.fit(self.real_anomalies_3w, self.mts_anomalies3)
  
      assert (
          abs(
              aggregator.eval_accuracy(
                  self.real_anomalies_3w,
                  self.mts_anomalies3,
                  metric="accuracy",
              )
              - 0.92
          )
          < 1e-05
      )
  
      np.testing.assert_array_almost_equal(
          np.array(
              aggregator.eval_accuracy(
                  [self.real_anomalies_3w, self.real_anomalies_3w],
                  [self.mts_anomalies3, self.mts_anomalies3],
                  metric="accuracy",
              )
          ),
          np.array([0.92, 0.92]),
          decimal=1,
      )
  
      # single series case (random example)
      aggregator = EnsembleSklearnAggregator(
          model=GradientBoostingClassifier(
              n_estimators=50, learning_rate=1.0, max_depth=1
          )
      )
      aggregator.fit(self.real_anomalies, self.mts_anomalies1)
  
      # aggregator must found 100 anomalies in the input mts_anomalies1
      assert (
          aggregator.predict(self.mts_anomalies1)
          .sum(axis=0)
          .all_values()
          .flatten()[0]
          == 100
      )
  
      # aggregator must have an accuracy of 0.51 for the input mts_anomalies1
      assert (
          abs(
              aggregator.eval_accuracy(
                  self.real_anomalies,
                  self.mts_anomalies1,
                  metric="accuracy",
              )
              - 0.51
          )
          < 1e-05
      )
      # aggregator must have an recall 1.0 for the input mts_anomalies1
      assert (
          abs(
              aggregator.eval_accuracy(
                  self.real_anomalies,
                  self.mts_anomalies1,
                  metric="recall",
              )
              - 1.0
          )
          < 1e-05
      )
      # aggregator must have an f1 of 0.67549 for the input mts_anomalies1
      assert (
          abs(
              aggregator.eval_accuracy(
                  self.real_anomalies, self.mts_anomalies1, metric="f1"
              )
              - 0.67549
          )
          < 1e-05
      )
      # aggregator must have an precision of 0.51 for the input mts_anomalies1
      assert (
          abs(
              aggregator.eval_accuracy(
                  self.real_anomalies,
                  self.mts_anomalies1,
                  metric="precision",
              )
              - 0.51
          )
          < 1e-05
      )
  
      # multiple series case (random example)
      # aggregator must found [100,100] anomalies in the input [mts_anomalies1, mts_anomalies2]
      values = aggregator.predict(
          [self.mts_anomalies1, self.mts_anomalies2]
      )
      np.testing.assert_array_almost_equal(
          [v.sum(axis=0).all_values().flatten()[0] for v in values],
          [100, 100.0],
          decimal=1,
      )
  
      # aggregator must have an accuracy of [0.51, 0.51] for the input [mts_anomalies1, mts_anomalies2]
      np.testing.assert_array_almost_equal(
          np.array(
              aggregator.eval_accuracy(
                  [self.real_anomalies, self.real_anomalies],
                  [self.mts_anomalies1, self.mts_anomalies2],
                  metric="accuracy",
              )
          ),
          np.array([0.51, 0.51]),
          decimal=1,
      )
      # aggregator must have an recall of [1,1] for the input [mts_anomalies1, mts_anomalies2]
      np.testing.assert_array_almost_equal(
          np.array(
              aggregator.eval_accuracy(
                  [self.real_anomalies, self.real_anomalies],
                  [self.mts_anomalies1, self.mts_anomalies2],
                  metric="recall",
              )
          ),
          np.array([1, 1]),
          decimal=1,
      )
      # aggregator must have an f1 of [0.675497, 0.675497] for the input [mts_anomalies1, mts_anomalies2]
      np.testing.assert_array_almost_equal(
          np.array(
              aggregator.eval_accuracy(
                  [self.real_anomalies, self.real_anomalies],
                  [self.mts_anomalies1, self.mts_anomalies2],
                  metric="f1",
              )
          ),
          np.array([0.675497, 0.675497]),
          decimal=1,
      )
      # aggregator must have an precision of [0.51, 0.51] for the input [mts_anomalies1, mts_anomalies2]
      np.testing.assert_array_almost_equal(
          np.array(
              aggregator.eval_accuracy(
                  [self.real_anomalies, self.real_anomalies],
                  [self.mts_anomalies1, self.mts_anomalies2],
                  metric="precision",
              )
          ),
          np.array([0.51, 0.51]),
          decimal=1,
      )
  
file_path: darts/darts/tests/ad/test_aggregators.py
imports: from typing import Sequence
  import numpy
  import pytest
  from sklearn.ensemble import GradientBoostingClassifier
  from darts import TimeSeries
  from darts.ad.aggregators.and_aggregator import AndAggregator
  from darts.ad.aggregators.ensemble_sklearn_aggregator import EnsembleSklearnAggregator
  from darts.ad.aggregators.or_aggregator import OrAggregator
  from darts.models import MovingAverageFilter
label_desc: Use image node_id 8 for calling the TestADAggregators obj's underlying member method code with example usage: obj.test_EnsembleSklearn() without return types