10. Confusion matrix, overall classification accuracy, kappa coefficient

Source: Internet
Author: User

First, preface

There are many indexes for characterizing classification accuracy, the most common one is the use of confusion matrix, the overall classification accuracy and kappa coefficients.

The confusion matrix can clearly see the number of correct classification of each figure and the category and number of the wrong points. However, the confusion matrix can not see the quality of classification accuracy at one glance, and it derives various classification accuracy indexes from the confusion matrix, among which the general classification accuracy (OA) and Kappa coefficient (kappa) are the most widely used.

Overall classification accuracy (OA): refers to the correct classification of the category of the number of cells and the total number of categories of the ratio; Although the OA value can characterize the classification accuracy well, the value of the multi-class figures with extremely uneven number of class cells has great influence on the many categories of the metadata, and it is not very good to characterize each category figure.

Kappa coefficient (kappa): Kappa coefficient is a proportion that represents the proportion of errors reduced by classification and completely random classification, and the calculation process can be expressed by the following formula:

Second, calculation and code

The following part of the code is mainly implemented, how to get the confusion matrix, for Oa and Kappa coefficient is easy to calculate from the confusion matrix can be obtained

1     intTolcount =0;2      for(inti =0; i<row;i++)3     {4         float*oriptr = oriclassmap.ptr<float> (0);5         float*stdptr = stdclassmap.ptr<float> (0);6          for(intj =0; j<col;j++)7         {8             intCurstdindex =int(Stdptr[j]);9             if(Curstdindex = =0)Ten                Continue; One             intCuroriindex =int(Oriptr[j]); A  -             if(Curstdindex = =Curoriindex) -conf.at<int> (curstdindex-1, curstdindex-1) = conf.at<int> (curstdindex-1, curstdindex-1)+1; the             Else -             { -conf.at<int> (curstdindex-1, curoriindex-1) = conf.at<int> (curstdindex-1, curoriindex-1)+1; -             } +tolcount++; -         } +}

Third, the calculation results show

10. Confusion matrix, overall classification accuracy, kappa coefficient

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.