precrec

An R library for accurate and fast calculations of Precision-Recall and ROC curves

https://github.com/evalclass/precrec

Science Score: 39.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
    Found 5 DOI reference(s) in README
  • Academic publication links
  • Committers with academic emails
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (14.9%) to scientific vocabulary
Last synced: 10 months ago · JSON representation

Repository

An R library for accurate and fast calculations of Precision-Recall and ROC curves

Basic Info
Statistics
  • Stars: 44
  • Watchers: 3
  • Forks: 5
  • Open Issues: 12
  • Releases: 28
Created over 10 years ago · Last pushed about 1 year ago
Metadata Files
Readme Changelog License

README.Rmd

---
output:
  github_document
---

# Precrec 

[![R-CMD-check](https://github.com/evalclass/precrec/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/evalclass/precrec/actions/workflows/R-CMD-check.yaml)
[![codecov.io](https://codecov.io/github/evalclass/precrec/coverage.svg?branch=main)](https://app.codecov.io/github/evalclass/precrec?branch=main)
[![CodeFactor](https://www.codefactor.io/repository/github/evalclass/precrec/badge)](https://www.codefactor.io/repository/github/evalclass/precrec/)
[![CRAN_Status_Badge](https://www.r-pkg.org/badges/version-ago/precrec)](https://cran.r-project.org/package=precrec)
[![CRAN_Logs_Badge](https://cranlogs.r-pkg.org/badges/grand-total/precrec)](https://cran.r-project.org/package=precrec)

The aim of the `precrec` package is to provide an integrated platform that enables robust performance evaluations of binary classifiers. Specifically, `precrec` offers accurate calculations of ROC (Receiver Operator Characteristics) and precision-recall curves. All the main calculations of `precrec` are implemented with C++/[Rcpp](https://cran.r-project.org/package=Rcpp).

## Documentation
- [Package website](https://evalclass.github.io/precrec/) -- GitHub pages that contain all precrec documentation.

- [Introduction to precrec](https://evalclass.github.io/precrec/articles/introduction.html) -- a package vignette that contains the descriptions of the functions with several useful examples. View the vignette with `vignette("introduction", package = "precrec")` in R. The HTML version is also available on the [GitHub Pages](https://evalclass.github.io/precrec/articles/introduction.html).

- [Help pages](https://evalclass.github.io/precrec/reference/)  -- all the functions including the S3 generics except for `print` have their own help pages with plenty of examples. View the main help page with `help(package = "precrec")` in R. The HTML version is also available on the [GitHub Pages](https://evalclass.github.io/precrec/reference/).

## Six key features of precrec

### 1. Accurate curve calculations
`precrec` provides accurate precision-recall curves.

- Non-linear interpolation
- Elongation to the y-axis to estimate the first point when necessary
- Use of score-wise threshold values instead of fixed bins

`precrec` also calculates AUC scores with high accuracy.

### 2. Super fast
`precrec` calculates curves in a matter of seconds even for a fairly large dataset. It is much faster than most other tools that calculate ROC and precision-recall curves. 

### 3. Various evaluation metrics
In addition to precision-recall and ROC curves, `precrec` offers basic evaluation measures.

- Error rate
- Accuracy
- Specificity
- Sensitivity, true positive rate (TPR), recall
- Precision, positive predictive value (PPV)
- Matthews correlation coefficient
- F\-score

### 4. Confidence interval band
`precrec` calculates confidence intervals when multiple test sets are given. It automatically shows confidence bands about the averaged curve in the 
corresponding plot. 

### 5. Calculation of partial AUCs and visualization of partial curves
`precrec` calculates partial AUCs for specified x and y ranges. It can also
draw partial ROC and precision-recall curves for the specified ranges.

### 6. Supporting functions
`precrec` provides several useful functions that lack in most other evaluation tools. 

- Handling multiple models and multiple test sets
- Handling tied scores and missing scores
- Pre- and post-process functions of simple data preparation and curve analysis

## Installation

* Install the release version of `precrec` from CRAN with `install.packages("precrec")`.

* Alternatively, you can install a development version of `precrec` from [our GitHub repository](https://github.com/evalclass/precrec/). To install it:

    1. Make sure you have a working development environment.
        * **Windows**: Install Rtools (available on the CRAN website).
        * **Mac**: Install Xcode from the Mac App Store.
        * **Linux**: Install a compiler and various development libraries (details vary across different flavors of Linux).

    2. Install `devtools` from CRAN with `install.packages("devtools")`.

    3. Install `precrec` from the GitHub repository with `devtools::install_github("evalclass/precrec")`.

## Functions
The `precrec` package provides the following six functions.

Function           Description 
------------------ -----------------------------------------------------------
           evalmod Main function to calculate evaluation measures
            mmdata Reformat input data for performance evaluation calculation
       join_scores Join scores of multiple models into a list
       join_labels Join observed labels of multiple test datasets into a list     
create_sim_samples Create random samples for simulations
      format_nfold Create n-fold cross validation dataset from data frame
    
Moreover, the `precrec` package provides nine S3 generics for the S3 object created by the `evalmod` function. **N.B.** The R language specifies S3 objects and S3 generic functions as part of the most basic object-oriented system in R.

S3 generic       Package   Description 
---------------  --------  ------------------------------------------------------------------
         print   base      Print the calculation results and the summary of the test data
 as.data.frame   base      Convert a precrec object to a data frame
          plot   graphics  Plot performance evaluation measures
      autoplot   ggplot2   Plot performance evaluation measures with ggplot2
       fortify   ggplot2   Prepare a data frame for ggplot2
           auc   precrec   Make a data frame with AUC scores
          part   precrec   Calculate partial curves and partial AUC scores
          pauc   precrec   Make a data frame with pAUC scores
        auc_ci   precrec   Calculate confidence intervals of AUC scores

## Examples

Following two examples show the basic usage of `precrec` functions.

### ROC and Precision-Recall calculations

The `evalmod` function calculates ROC and Precision-Recall curves and returns an S3 object.
```{r}
library(precrec)

# Load a test dataset
data(P10N10)

# Calculate ROC and Precision-Recall curves
sscurves <- evalmod(scores = P10N10$scores, labels = P10N10$labels)
```

### Visualization of the curves

The `autoplot` function outputs ROC and Precision-Recall curves by using the 
`ggplot2` package.
```{r, fig.show='hide'}
# The ggplot2 package is required
library(ggplot2)

# Show ROC and Precision-Recall plots
autoplot(sscurves)
```

![](https://raw.githubusercontent.com/evalclass/precrec/main/README_files/figure-gfm/unnamed-chunk-2-1.png)

## Citation
*Precrec: fast and accurate precision-recall and ROC curve calculations in R*

Takaya Saito; Marc Rehmsmeier

Bioinformatics 2017; 33 (1): 145-147.

doi: [10.1093/bioinformatics/btw570](https://doi.org/10.1093/bioinformatics/btw570)

## External links
- [Classifier evaluation with imbalanced datasets](https://classeval.wordpress.com/) - our web site that contains several pages with useful tips for performance evaluation on binary classifiers.

- [The Precision-Recall Plot Is More Informative than the ROC Plot When Evaluating Binary Classifiers on Imbalanced Datasets](https://doi.org/10.1371/journal.pone.0118432) - our paper that summarized potential pitfalls of ROC plots with imbalanced datasets and advantages of using precision-recall plots instead.
 
```{r, echo = FALSE}
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "README-"
)
```

Owner

  • Name: Classifier evaluation
  • Login: evalclass
  • Kind: organization
  • Email: classeval2015@gmail.com

Classifier evaluation with imbalanced datasets

GitHub Events

Total
  • Release event: 1
  • Delete event: 1
  • Push event: 4
  • Create event: 2
Last Year
  • Release event: 1
  • Delete event: 1
  • Push event: 4
  • Create event: 2

Committers

Last synced: over 2 years ago

All Time
  • Total Commits: 439
  • Total Committers: 5
  • Avg Commits per committer: 87.8
  • Development Distribution Score (DDS): 0.319
Past Year
  • Commits: 28
  • Committers: 1
  • Avg Commits per committer: 28.0
  • Development Distribution Score (DDS): 0.0
Top Committers
Name Email Commits
Takaya Saito t****o@o****m 299
Saito, Takaya T****o@h****o 94
Takaya Saito t****o@h****o 44
takaya88 t****o@i****o 1
Dirk Eddelbuettel e****d@d****g 1
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: 11 months ago

All Time
  • Total issues: 19
  • Total pull requests: 1
  • Average time to close issues: 4 months
  • Average time to close pull requests: 21 days
  • Total issue authors: 17
  • Total pull request authors: 1
  • Average comments per issue: 2.74
  • Average comments per pull request: 1.0
  • Merged pull requests: 1
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 0
  • Pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Issue authors: 0
  • Pull request authors: 0
  • Average comments per issue: 0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • c1au6i0 (2)
  • fkgruber (2)
  • cchampod (1)
  • NinaTWang (1)
  • rushabh31 (1)
  • suzannejin (1)
  • aremiuq (1)
  • anwarMZ (1)
  • micdonato (1)
  • mfrasco (1)
  • mehrankr (1)
  • thaocad (1)
  • Zefeng-Wu (1)
  • mostafiz67 (1)
  • LINGLLIU (1)
Pull Request Authors
  • eddelbuettel (1)
Top Labels
Issue Labels
Pull Request Labels

Packages

  • Total packages: 1
  • Total downloads:
    • cran 2,749 last-month
  • Total docker downloads: 201
  • Total dependent packages: 7
  • Total dependent repositories: 17
  • Total versions: 27
  • Total maintainers: 1
cran.r-project.org: precrec

Calculate Accurate Precision-Recall and ROC (Receiver Operator Characteristics) Curves

  • Versions: 27
  • Dependent Packages: 7
  • Dependent Repositories: 17
  • Downloads: 2,749 Last month
  • Docker Downloads: 201
Rankings
Downloads: 5.9%
Dependent repos count: 6.9%
Dependent packages count: 7.3%
Stargazers count: 7.3%
Average: 10.6%
Forks count: 10.8%
Docker downloads count: 25.7%
Maintainers (1)
Last synced: 10 months ago

Dependencies

DESCRIPTION cran
  • R >= 3.2.1 depends
  • Rcpp >= 0.12.2 imports
  • assertthat >= 0.1 imports
  • data.table >= 1.10.4 imports
  • ggplot2 >= 2.1.0 imports
  • grid * imports
  • gridExtra >= 2.0.0 imports
  • methods * imports
  • withr >= 2.3.0 imports
  • knitr >= 1.11 suggests
  • patchwork >= 1.1.2 suggests
  • rmarkdown >= 0.8.1 suggests
  • testthat >= 0.11.0 suggests
  • vdiffr >= 1.0.0 suggests
.github/workflows/R-CMD-check.yaml actions
  • actions/checkout v2 composite
  • r-lib/actions/check-r-package v2 composite
  • r-lib/actions/setup-pandoc v2 composite
  • r-lib/actions/setup-r v2 composite
  • r-lib/actions/setup-r-dependencies v2 composite
.github/workflows/pkgdown.yaml actions
  • JamesIves/github-pages-deploy-action v4.4.1 composite
  • actions/checkout v3 composite
  • r-lib/actions/setup-pandoc v2 composite
  • r-lib/actions/setup-r v2 composite
  • r-lib/actions/setup-r-dependencies v2 composite
.github/workflows/test-coverage.yaml actions
  • actions/checkout v2 composite
  • r-lib/actions/setup-r v2 composite
  • r-lib/actions/setup-r-dependencies v2 composite