When using R for classification, the ROC is plotted and the AUC is calculated

Source: Internet
Author: User

In the previous log, I briefly introduced the calculation of the RECALL,PRECISION,TPR,FPR and so on when using R for the logistic regression, but if the ROC curve is plotted in this way (for the concept of ROC and AUC, there are many introductions online, For example: http://beader.me/2013/12/15/auc-roc/) is too troublesome to manually adjust the classification threshold. In fact, R also provides the most basic ROC Curve Drawing Toolkit (package), combined with this log, I also introduce the installation and learning methods of the R package:

Here: http://www.r-project.org/Page Left click:

Download, Packages
CRAN

You can see the first need to select Cran mirror site, for example, we choose Beijing Jiaotong University: http://mirror.bjtu.edu.cn/cran/through a few links, you can browse this page: http://mirror.bjtu.edu.cn/cran/ web/packages/available_packages_by_name.html, the list is given in terms of the package name, along with a brief introduction to the package. We can see a description of proc here:

proc display and analyze ROC curves

The installation can be downloaded as a compressed package, but it is often cumbersome to install it, so it is recommended to install it via the R console (you can see the name and the role of the packages first in this page):

Select "Package"--"installer package" in Rgui--Select the packages that need to be installed (also automatically installed if you need to install other dependent packages), if you choose the appropriate image (from my point of view, choose Lanzhou University's image, installation speed quickly), it will be ready to install. Finally give an example of stackoverflow on the other person, after installing the package can be run.

MyData <-read.csv ("Http://www.ats.ucla.edu/stat/data/binary.csv") Mylogit <-GLM (admit ~ GRE, data = MyData, Family = "Binomial") Summary (mylogit) prob=predict (mylogit,type=c ("response")) Mydata$prob=problibrary (PROC) G <- ROC (admit ~ prob, data = MyData) plot (g)

For other ways to use this package, API documentation can be found here:Http://www.inside-r.org/packages/cran/pROC/docs/auc. To sum up so much, I believe that the novice friends will be helpful.

When using R for classification, the ROC is plotted and the AUC is calculated

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.