class_docstr: Aggregated Mondrian Forest classifier for online learning.
  
  This implementation is truly online[^1], in the sense that a single pass is performed, and that
  predictions can be produced anytime.
  
  Each node in a tree predicts according to the distribution of the labels
  it contains. This distribution is regularized using a "Jeffreys" prior
  with parameter `dirichlet`. For each class with `count` labels in the
  node and `n_samples` samples in it, the prediction of a node is given by
  
  $\frac{count + dirichlet}{n_{samples} + dirichlet \times n_{classes}}$.
  
  The prediction for a sample is computed as the aggregated predictions of all the
  subtrees along the path leading to the leaf node containing the sample. The
  aggregation weights are exponential weights with learning rate `step` and log-loss
  when `use_aggregation` is `True`.
  
  This computation is performed exactly thanks to a context tree weighting algorithm.
  More details can be found in the paper cited in the references below.
  
  The final predictions are the average class probabilities predicted by each of the
  `n_estimators` trees in the forest.
  
  Parameters
  ----------
  n_estimators
      The number of trees in the forest.
  step
      Step-size for the aggregation weights. Default is 1 for classification with
      the log-loss, which is usually the best choice.
  use_aggregation
      Controls if aggregation is used in the trees. It is highly recommended to
      leave it as `True`.
  dirichlet
      Regularization level of the class frequencies used for predictions in each node. A rule of
      thumb is to set this to `1 / n_classes`, where `n_classes` is the expected number of
      classes which might appear. Default is `dirichlet = 0.5`, which works well for binary
      classification problems.
  split_pure
      Controls if nodes that contains only sample of the same class should be
      split ("pure" nodes). Default is `False`, namely pure nodes are not split,
      but `True` can be sometimes better.
  seed
      Random seed for reproducibility.
  
  Notes
  -----
  Only log_loss used for the computation of the aggregation weights is supported for now, namely
  the log-loss for multi-class classification.
  
  Examples
  --------
  
  >>> from river import datasets
  >>> from river import evaluate
  >>> from river import forest
  >>> from river import metrics
  
  >>> dataset = datasets.Bananas().take(500)
  
  >>> model = forest.AMFClassifier(
  ...     n_estimators=10,
  ...     use_aggregation=True,
  ...     dirichlet=0.5,
  ...     seed=1
  ... )
  
  >>> metric = metrics.Accuracy()
  
  >>> evaluate.progressive_val_score(dataset, model, metric)
  Accuracy: 85.37%
  
  References
  ----------
  [^1]: Mourtada, J., Gaïffas, S., & Scornet, E. (2021). AMF: Aggregated Mondrian forests for online
  learning. Journal of the Royal Statistical Society Series B: Statistical Methodology, 83(3), 505-533.
class_docstr_tok: ["Aggregated","Mondrian","Forest","classifier","for","online","learning",".","This","implementation","is","truly","online","[","^1","]",",","in","the","sense","that","a","single","pass","is","performed",",","and","that","predictions","can","be","produced","anytime",".","Each","node","in","a","tree","predicts","according","to","the","distribution","of","the","labels","it","contains",".","This","distribution","is","regularized","using","a","``","Jeffreys","''","prior","with","parameter","`","dirichlet","`",".","For","each","class","with","`","count","`","labels","in","the","node","and","`","n_samples","`","samples","in","it",",","the","prediction","of","a","node","is","given","by","$","\\frac","{","count","+","dirichlet","}","{","n_","{","samples","}","+","dirichlet","\\times","n_","{","classes","}","}","$",".","The","prediction","for","a","sample","is","computed","as","the","aggregated","predictions","of","all","the","subtrees","along","the","path","leading","to","the","leaf","node","containing","the","sample",".","The","aggregation","weights","are","exponential","weights","with","learning","rate","`","step","`","and","log-loss","when","`","use_aggregation","`","is","`","True","`",".","This","computation","is","performed","exactly","thanks","to","a","context","tree","weighting","algorithm",".","More","details","can","be","found","in","the","paper","cited","in","the","references","below",".","The","final","predictions","are","the","average","class","probabilities","predicted","by","each","of","the","`","n_estimators","`","trees","in","the","forest",".","Parameters","--","--","--","--","--","n_estimators","The","number","of","trees","in","the","forest",".","step","Step-size","for","the","aggregation","weights",".","Default","is","1","for","classification","with","the","log-loss",",","which","is","usually","the","best","choice",".","use_aggregation","Controls","if","aggregation","is","used","in","the","trees",".","It","is","highly","recommended","to","leave","it","as","`","True","`",".","dirichlet","Regularization","level","of","the","class","frequencies","used","for","predictions","in","each","node",".","A","rule","of","thumb","is","to","set","this","to","`","1","\/","n_classes","`",",","where","`","n_classes","`","is","the","expected","number","of","classes","which","might","appear",".","Default","is","`","dirichlet","=","0.5","`",",","which","works","well","for","binary","classification","problems",".","split_pure","Controls","if","nodes","that","contains","only","sample","of","the","same","class","should","be","split","(","``","pure","''","nodes",")",".","Default","is","`","False","`",",","namely","pure","nodes","are","not","split",",","but","`","True","`","can","be","sometimes","better",".","seed","Random","seed","for","reproducibility",".","Notes","--","--","-","Only","log_loss","used","for","the","computation","of","the","aggregation","weights","is","supported","for","now",",","namely","the","log-loss","for","multi-class","classification",".","Examples","--","--","--","--",">",">",">","from","river","import","datasets",">",">",">","from","river","import","evaluate",">",">",">","from","river","import","forest",">",">",">","from","river","import","metrics",">",">",">","dataset","=","datasets.Bananas","(",")",".take","(","500",")",">",">",">","model","=","forest.AMFClassifier","(","...","n_estimators=10",",","...","use_aggregation=True",",","...","dirichlet=0.5",",","...","seed=1","...",")",">",">",">","metric","=","metrics.Accuracy","(",")",">",">",">","evaluate.progressive_val_score","(","dataset",",","model",",","metric",")","Accuracy",":","85.37","%","References","--","--","--","--","--","[","^1","]",":","Mourtada",",","J.",",","Ga\u00efffas",",","S.",",","&","Scornet",",","E.","(","2021",")",".","AMF",":","Aggregated","Mondrian","forests","for","online","learning",".","Journal","of","the","Royal","Statistical","Society","Series","B",":","Statistical","Methodology",",","83","(","3",")",",","505-533","."]
code: def predict_proba_one(self, x):
      # Checking that the model has been trained once at least
      # Otherwise return the default empty dict
      if not self._is_initialized:
          return {}
  
      # initialize the scores
      scores = {c: 0 for c in self._classes}
  
      # Simply computes the prediction for each tree and average it
      for tree in self:
          predictions = tree.predict_proba_one(x)
          for c in self._classes:
              scores[c] += predictions[c] / self.n_estimators
  
      return scores
  
imports: from __future__ import annotations
  import abc
  import random
  from river import base
  from river.tree.mondrian import MondrianTreeClassifier, MondrianTreeRegressor
label_desc: Use image node_id 4 for calling the AMFClassifier obj's underlying member method code with example usage: obj.predict_proba_one(x) and returns: scores, dict