liveBook · Manning

Precision

As explained in Natural Language Processing in Action, Second Edition

Precision is the proportion of retrieved or classified items that are relevant or correct.

Precision measures how often a positive result is correct. In search, it is the proportion of retrieved documents that are relevant; in classification, it is the proportion of items labeled positive that truly belong to the positive class. Precision = true positives / all predicted positives. section 2.3.2 section 4.2.1

Flagging toxic comments

A classifier labels 1,038 test comments as toxic, but only 125 are truly toxic. Its precision is 125 / 1,038, or about 12%. The remaining 913 flags are false positives: nontoxic comments labeled toxic. Low precision can increase moderators’ workload or lead to legitimate comments being hidden. section 4.2.1

>>> from sklearn.metrics import confusion_matrix
>>> confusion_matrix(y_test, lda.predict(X_test))
array([[1261,  913],
       [ 201,  125]], dtype=int64)

The confusion matrix shows 125 correctly flagged toxic comments and 913 nontoxic comments incorrectly flagged as toxic. section 4.2.1

Recall asks a different question: of all the items that really are positive, how many were found? The same classifier identifies 125 of 326 toxic comments, for a recall of 38.3%. Labeling every comment toxic would give perfect recall, but precision would suffer because most comments are nontoxic. The preferred balance depends on the application. section 4.2.1

Search normalization

Normalizing capitalization can return documents matching both “Age” and “age,” increasing recall. But it can also return documents the searcher does not want, reducing precision. Quoted queries can request exact matches; supporting both behaviors in a search pipeline requires indexes with normalized and original capitalization. section 2.3.2

How Natural Language Processing in Action, Second Edition covers it

How deep it goes
Defines precision through a classifier’s counts and explains its tradeoff with recall and the consequences of false positives.
Examples
Uses a toxic-comment classifier and capitalization-normalized search queries to illustrate precision.
What you can do after
Evaluate and understand classifier and search results by interpreting precision alongside recall and considering false-positive consequences.
How it connects
Connects precision with recall, accuracy, confusion matrices, classification, and vocabulary normalization.

Also explained in

Compare how 20 books explain precision →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Natural Language Processing in Action, Second Edition. The section links point to the parts of the book it draws on.