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