nltk.ChunkScore
¶
-
class
nltk.
ChunkScore
(**kwargs)[source]¶ A utility class for scoring chunk parsers.
ChunkScore
can evaluate a chunk parser’s output, based on a number of statistics (precision, recall, f-measure, misssed chunks, incorrect chunks). It can also combine the scores from the parsing of multiple texts; this makes it significantly easier to evaluate a chunk parser that operates one sentence at a time.Texts are evaluated with the
score
method. The results of evaluation can be accessed via a number of accessor methods, such asprecision
andf_measure
. A typical use of theChunkScore
class is:>>> chunkscore = ChunkScore() >>> for correct in correct_sentences: ... guess = chunkparser.parse(correct.leaves()) ... chunkscore.score(correct, guess) >>> print('F Measure:', chunkscore.f_measure()) F Measure: 0.823
Variables: - kwargs –
Keyword arguments:
- max_tp_examples: The maximum number actual examples of true
positives to record. This affects the
correct
member function:correct
will not return more than this number of true positive examples. This does not affect any of the numerical metrics (precision, recall, or f-measure) - max_fp_examples: The maximum number actual examples of false
positives to record. This affects the
incorrect
member function and theguessed
member function:incorrect
will not return more than this number of examples, andguessed
will not return more than this number of true positive examples. This does not affect any of the numerical metrics (precision, recall, or f-measure) - max_fn_examples: The maximum number actual examples of false
negatives to record. This affects the
missed
member function and thecorrect
member function:missed
will not return more than this number of examples, andcorrect
will not return more than this number of true negative examples. This does not affect any of the numerical metrics (precision, recall, or f-measure) - chunk_label: A regular expression indicating which chunks
should be compared. Defaults to
'.*'
(i.e., all chunks).
- max_tp_examples: The maximum number actual examples of true
positives to record. This affects the
- _tp – List of true positives
- _fp – List of false positives
- _fn – List of false negatives
- _tp_num – Number of true positives
- _fp_num – Number of false positives
- _fn_num – Number of false negatives.
- kwargs –
Methods¶
__init__ (**kwargs) |
|
accuracy () |
Return the overall tag-based accuracy for all text that have been scored by this ChunkScore , using the IOB (conll2000) tag encoding. |
correct () |
Return the chunks which were included in the correct chunk structures, listed in input order. |
f_measure ([alpha]) |
Return the overall F measure for all texts that have been scored by this ChunkScore . |
guessed () |
Return the chunks which were included in the guessed chunk structures, listed in input order. |
incorrect () |
Return the chunks which were included in the guessed chunk structures, but not in the correct chunk structures, listed in input order. |
missed () |
Return the chunks which were included in the correct chunk structures, but not in the guessed chunk structures, listed in input order. |
precision () |
Return the overall precision for all texts that have been scored by this ChunkScore . |
recall () |
Return the overall recall for all texts that have been scored by this ChunkScore . |
score (correct, guessed) |
Given a correctly chunked sentence, score another chunked version of the same sentence. |