简体   繁体   English

使用 pdb 以简单的方式调试 python 代码

[英]debugging python code using pdb in simple way

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).函数 get_sum_metrics 接受两个参数:预测和应用于预测的指标列表(例如,准确度或精确度)。 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.它还应该将三个默认指标添加到该总和中,在这种情况下,将 0、1 或 2 添加到预测中。

I had the same problem, another user solved it LINK我遇到了同样的问题,另一个用户解决了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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM