class_docstr: Leveraging Bagging ensemble classifier.
  
  Leveraging Bagging [^1] is an improvement over the Oza Bagging algorithm.
  The bagging performance is leveraged by increasing the re-sampling.
  It uses a poisson distribution to simulate the re-sampling process.
  To increase re-sampling it uses a higher `w` value of the Poisson
  distribution (agerage number of events), 6 by default, increasing the
  input space diversity, by attributing a different range of weights to the
  data samples.
  
  To deal with concept drift, Leveraging Bagging uses the ADWIN algorithm to
  monitor the performance of each member of the enemble If concept drift is
  detected, the worst member of the ensemble (based on the error estimation
  by ADWIN) is replaced by a new (empty) classifier.
  
  Parameters
  ----------
  model
      The classifier to bag.
  n_models
      The number of models in the ensemble.
  w
      Indicates the average number of events. This is the lambda parameter
      of the Poisson distribution used to compute the re-sampling weight.
  adwin_delta
      The delta parameter for the ADWIN change detector.
  bagging_method
      The bagging method to use. Can be one of the following:<br/>
      * 'bag' - Leveraging Bagging using ADWIN.<br/>
      * 'me' - Assigns $weight=1$ if sample is misclassified,
        otherwise $weight=error/(1-error)$.<br/>
      * 'half' - Use resampling without replacement for half of the instances.<br/>
      * 'wt' - Resample without taking out all instances.<br/>
      * 'subag' - Resampling without replacement.<br/>
  seed
      Random number generator seed for reproducibility.
  
  Examples
  --------
  
  >>> from river import datasets
  >>> from river import ensemble
  >>> from river import evaluate
  >>> from river import linear_model
  >>> from river import metrics
  >>> from river import optim
  >>> from river import preprocessing
  
  >>> dataset = datasets.Phishing()
  
  >>> model = ensemble.LeveragingBaggingClassifier(
  ...     model=(
  ...         preprocessing.StandardScaler() |
  ...         linear_model.LogisticRegression()
  ...     ),
  ...     n_models=3,
  ...     seed=42
  ... )
  
  >>> metric = metrics.F1()
  
  >>> evaluate.progressive_val_score(dataset, model, metric)
  F1: 88.55%
class_docstr_tok: ["Leveraging","Bagging","ensemble","classifier",".","Leveraging","Bagging","[","^1","]","is","an","improvement","over","the","Oza","Bagging","algorithm",".","The","bagging","performance","is","leveraged","by","increasing","the","re-sampling",".","It","uses","a","poisson","distribution","to","simulate","the","re-sampling","process",".","To","increase","re-sampling","it","uses","a","higher","`","w","`","value","of","the","Poisson","distribution","(","agerage","number","of","events",")",",","6","by","default",",","increasing","the","input","space","diversity",",","by","attributing","a","different","range","of","weights","to","the","data","samples",".","To","deal","with","concept","drift",",","Leveraging","Bagging","uses","the","ADWIN","algorithm","to","monitor","the","performance","of","each","member","of","the","enemble","If","concept","drift","is","detected",",","the","worst","member","of","the","ensemble","(","based","on","the","error","estimation","by","ADWIN",")","is","replaced","by","a","new","(","empty",")","classifier",".","Parameters","--","--","--","--","--","model","The","classifier","to","bag",".","n_models","The","number","of","models","in","the","ensemble",".","w","Indicates","the","average","number","of","events",".","This","is","the","lambda","parameter","of","the","Poisson","distribution","used","to","compute","the","re-sampling","weight",".","adwin_delta","The","delta","parameter","for","the","ADWIN","change","detector",".","bagging_method","The","bagging","method","to","use",".","Can","be","one","of","the","following",":","<","br\/",">","*","'bag","'","-","Leveraging","Bagging","using","ADWIN.","<","br\/",">","*","'me","'","-","Assigns","$","weight=1","$","if","sample","is","misclassified",",","otherwise","$","weight=error\/","(","1-error",")","$",".","<","br\/",">","*","'half","'","-","Use","resampling","without","replacement","for","half","of","the","instances.","<","br\/",">","*","'wt","'","-","Resample","without","taking","out","all","instances.","<","br\/",">","*","'subag","'","-","Resampling","without","replacement.","<","br\/",">","seed","Random","number","generator","seed","for","reproducibility",".","Examples","--","--","--","--",">",">",">","from","river","import","datasets",">",">",">","from","river","import","ensemble",">",">",">","from","river","import","evaluate",">",">",">","from","river","import","linear_model",">",">",">","from","river","import","metrics",">",">",">","from","river","import","optim",">",">",">","from","river","import","preprocessing",">",">",">","dataset","=","datasets.Phishing","(",")",">",">",">","model","=","ensemble.LeveragingBaggingClassifier","(","...","model=","(","...","preprocessing.StandardScaler","(",")","|","...","linear_model.LogisticRegression","(",")","...",")",",","...","n_models=3",",","...","seed=42","...",")",">",">",">","metric","=","metrics.F1","(",")",">",">",">","evaluate.progressive_val_score","(","dataset",",","model",",","metric",")","F1",":","88.55","%"]
code: def __init__(
      self,
      model: base.Classifier,
      n_models: int = 10,
      w: float = 6,
      adwin_delta: float = 0.002,
      bagging_method: str = "bag",
      seed: int | None = None,
  ):
      super().__init__(model=model, n_models=n_models, seed=seed)
      self.n_detected_changes = 0
      self.w = w
      self.adwin_delta = adwin_delta
      self.bagging_method = bagging_method
      self._drift_detectors = [
          drift.ADWIN(delta=self.adwin_delta)
          for _ in range(self.n_models)
      ]
  
      # Set bagging function
      if bagging_method == "bag":
          self._bagging_fct = self._leveraging_bag
      elif bagging_method == "me":
          self._bagging_fct = self._leveraging_bag_me
      elif bagging_method == "half":
          self._bagging_fct = self._leveraging_bag_half
      elif bagging_method == "wt":
          self._bagging_fct = self._leveraging_bag_wt
      elif bagging_method == "subag":
          self._bagging_fct = self._leveraging_subag
      else:
          raise ValueError(
              f"Invalid bagging_method: {bagging_method}\n"
              f"Valid options: {self._BAGGING_METHODS}"
          )
  
imports: from __future__ import annotations
  import collections
  import statistics
  from river import base, drift, linear_model, utils
label_desc: Use image node_id 1 to create a new LeveragingBaggingClassifier object from inherited base classes: BaggingClassifier with example: obj = LeveragingBaggingClassifier(model, n_models, w, adwin_delta, bagging_method, seed)