class_docstr: Weighted-average precision score.
  
  This uses the support of each label to compute an average score, whereas
  `metrics.MacroPrecision` ignores the support.
  
  Parameters
  ----------
  cm
      This parameter allows sharing the same confusion
      matrix between multiple metrics. Sharing a confusion matrix reduces the amount of storage
      and computation time.
  
  Examples
  --------
  
  >>> from river import metrics
  
  >>> y_true = [0, 1, 2, 2, 2]
  >>> y_pred = [0, 0, 2, 2, 1]
  
  >>> metric = metrics.WeightedPrecision()
  
  >>> for yt, yp in zip(y_true, y_pred):
  ...     metric.update(yt, yp)
  ...     print(metric)
  WeightedPrecision: 100.00%
  WeightedPrecision: 25.00%
  WeightedPrecision: 50.00%
  WeightedPrecision: 62.50%
  WeightedPrecision: 70.00%
class_docstr_tok: ["Weighted-average","precision","score",".","This","uses","the","support","of","each","label","to","compute","an","average","score",",","whereas","`","metrics.MacroPrecision","`","ignores","the","support",".","Parameters","--","--","--","--","--","cm","This","parameter","allows","sharing","the","same","confusion","matrix","between","multiple","metrics",".","Sharing","a","confusion","matrix","reduces","the","amount","of","storage","and","computation","time",".","Examples","--","--","--","--",">",">",">","from","river","import","metrics",">",">",">","y_true","=","[","0",",","1",",","2",",","2",",","2","]",">",">",">","y_pred","=","[","0",",","0",",","2",",","2",",","1","]",">",">",">","metric","=","metrics.WeightedPrecision","(",")",">",">",">","for","yt",",","yp","in","zip","(","y_true",",","y_pred",")",":","...","metric.update","(","yt",",","yp",")","...","print","(","metric",")","WeightedPrecision",":","100.00","%","WeightedPrecision",":","25.00","%","WeightedPrecision",":","50.00","%","WeightedPrecision",":","62.50","%","WeightedPrecision",":","70.00","%"]
code: def get(self):
      total = 0
      for c in self.cm.classes:
          try:
              tp = self.cm.true_positives(c)
              fp = self.cm.false_positives(c)
              total += self.cm.support(c) * tp / (tp + fp)
          except ZeroDivisionError:
              continue
      try:
          return total / self.cm.total_weight
      except ZeroDivisionError:
          return 0.0
  
file_path: river/river/metrics/precision.py
imports: from __future__ import annotations
  from river import metrics
label_desc: Use image node_id 1 for calling the WeightedPrecision obj's underlying member method code with example usage: obj.get() and returns: unknown, int