nltk.metrics.pk

nltk.metrics.pk(ref, hyp, k=None, boundary='1')[source]

Compute the Pk metric for a pair of segmentations A segmentation is any sequence over a vocabulary of two items (e.g. “0”, “1”), where the specified boundary value is used to mark the edge of a segmentation.

>>> '%.2f' % pk('0100'*100, '1'*400, 2)
'0.50'
>>> '%.2f' % pk('0100'*100, '0'*400, 2)
'0.50'
>>> '%.2f' % pk('0100'*100, '0100'*100, 2)
'0.00'
Parameters
  • ref (str or list) – the reference segmentation

  • hyp (str or list) – the segmentation to evaluate

  • k – window size, if None, set to half of the average reference segment length

  • boundary (str or int or bool) – boundary value

Return type

float