A Graphical Approach to Showing the Result of Classification Models

June 4, 2013

(This article was first published on Mario Segal - Professional Site » R, and kindly contributed to R-bloggers)

This is one of my favorite charts, it easily allows one to see how many predictions are right, and it allows one to see where the wrong ones are as well. It is the equivalent of a confusion matrix, but sometimes a picture is worth a thousand words. Some sample code is included below.



    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    GNU General Public License for more details.

    Developed by Mario Segal

#requires ggplot2. Data has to be in a dataset with three columns: actual, predicted and match.
#match is Yes if actual and predicted match, No otherwise.



fitchart <- ggplot(chartdata,aes(x=actual,y=predicted,color=actual,shape=match))+geom_jitter(alpha=.6)+theme_bw()
fitchart <- fitchart + ylab(“Predicted Activity”)+xlab(“Actual Activity”)+ggtitle(“Summary of Classification Accuracy”)
fitchart <- fitchart+theme(legend.position=”bottom”)+theme(plot.title = element_text(size=14,color=”blue”, face=”bold”))
fitchart <- fitchart+theme(axis.title.x = element_text(face=”bold”,size=14),axis.title.y = element_text(face=”bold”,size=14))
fitchart <- fitchart+theme(axis.text.x=element_text(angle=0,color=”black”,size=12),axis.text.y=element_text(color=”black”,size=12))
fitchart <- fitchart + theme(legend.text = element_text(colour=”black”, size = 10),legend.title = element_text( face=”bold”))
fitchart <- fitchart + scale_color_discrete(name=”Actual\nActivity”)+scale_shape_manual(values=c(4,20),name=”Correct\nPrediction”)

To leave a comment for the author, please follow the link and comment on their blog: Mario Segal - Professional Site » R.

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...

If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.


Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)