简体   繁体   中英

How to Find False Positive Prediction Count using R Script

Assuming "test" and "train" are two data frames for testing and traininig respectively, and "model" is a classifier that was generated using training data. I can find the number of misclassified examples like this:

n = sum(test$class_label != predict(model, test))

How can I find the number of examples that is predicted as negative but it is actually positive? (ie false positive)

NOTE: Above example assumes that the problem is a binary classification problem whose classes are, say, "yes" (positive class) and "no". Additionally, predict is a function of caret package.

This will get you a 2x2 table showing true positives, false positives, false negatives and true negatives.

> table(Truth = test$class_label, Prediction = predict(model, test))

     Prediction
Truth yes no
  yes  32  3
  no    8 27

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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