How do you expose missing positions when aligning predictions and labels?
zip_longest pairs positions through the longest input and fills the exhausted side with a sentinel.
Python example and interpretation
Two predictions and one label leave the second prediction visible for inspection. Match by sample ID instead when the streams may arrive in different orders.
from itertools import zip_longest
list(zip_longest(['cat','dog'],['cat'],fillvalue=None))Result [('cat', 'cat'), ('dog', None)]
中文
怎样对齐不等长的预测和真值并显出缺项?
zip_longest 一直配对到最长输入耗尽,用指定值填补较短一侧。
Python 算例与适用条件
两条预测只有一条真值,第二条仍出现在核对表中。若记录顺序可能不同,应按样本编号连接。
from itertools import zip_longest
list(zip_longest(['cat','dog'],['cat'],fillvalue=None))结果 [('cat', 'cat'), ('dog', None)]