1
def get_sum_metrics(predictions, metrics=[]):
   for i in range(3):
       metrics.append(lambda x: x + i)

   sum_metrics = 0
   for metric in metrics:
       sum_metrics += metric(predictions)

   return sum_metrics

The function get_sum_metrics takes two arguments: a prediction and a list of metrics to apply to the prediction (say, for instance, the accuracy or the precision). Note that each metric is a function, not a number. The function should compute each of the metrics for the prediction and sum them. It should also add to this sum three default metrics, in this case, adding 0, 1 or 2 to the prediction.

user8577431
  • 63
  • 1
  • 2
  • 5

1 Answers1

3

I had the same problem, another user solved it LINK

def get_sum_metrics(predictions, metrics=None):
  if metrics is None:
     metrics = []  
  for i in range(0,3):
     f = lambda x, i=i: x+i
     metrics.append(f)
  sum_metrics = 0
  for metric in metrics:
     sum_metrics += metric(predictions)
  return sum_metrics
eljosephavila
  • 46
  • 1
  • 1