O'Reilly logo

R Data Analysis Cookbook - Second Edition by Kuntal Ganguly

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How to do it...

To generate error/classification confusion matrices, follow these steps:

  1. First, create and display a two-way table based on the Actual and Predicted values:
> tab <- table(cp$Perf, cp$Pred, dnn = c("Actual", "Predicted")) 
> tab         Predicted Actual Low Medium High   Low 1150 84 98   Medium 166 1801 170   High 35 38 458
  1. Display the raw numbers as proportions or percentages. To get overall table-level proportions, use the following code:
> prop.table(tab) 
        Predicted 
Actual       Low  Medium    High 
  Low    0.28750 0.02100 0.02450 
  Medium 0.04150 0.45025 0.04250 
  High   0.00875 0.00950 0.11450 
  1. We often find it more convenient to interpret row-wise or column-wise percentages. To get row-wise percentages rounded to one decimal place, you can pass ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required