Skip to content

Commit

Permalink
plot.ROC() and plot.prROC() fix 🔨 (#38)
Browse files Browse the repository at this point in the history
## 📚 What?

This PR closes #36 and expands the unit-tests to include all associated
methods with `ROC()` and `prROC()`. The most important part of the PR
is,

1. The `plot`-methods now uses the finite `data.frame` for labelling and
plotting.
2. Version bumped to `v0.3-1`
3. NEWS updated
  • Loading branch information
serkor1 authored Jan 1, 2025
1 parent ce2b6ce commit c0500dc
Show file tree
Hide file tree
Showing 9 changed files with 133 additions and 84 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: SLmetrics
Title: Machine Learning Performance Evaluation on Steroids
Version: 0.3-0
Version: 0.3-1
Authors@R: c(
person(
given = "Serkan",
Expand Down
16 changes: 13 additions & 3 deletions NEWS.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@ knitr::opts_chunk$set(
set.seed(1903)
```

# Version 0.3-1

> Version 0.3-1 is considered pre-release of {SLmetrics}. We do not
> expect any breaking changes, unless a major bug/issue is reported and its nature
> forces breaking changes.
## :bug: Bug-fixes

* **Plot-method in ROC and prROC (https://github.com/serkor1/SLmetrics/issues/36):** Fixed a bug in `plot.ROC()` and `plot.prROC()` where if `panels = FALSE` additional lines would be added to the plot.

# Version 0.3-0

> Version 0.3-0 is considered pre-release of {SLmetrics}. We do not
Expand Down Expand Up @@ -124,7 +134,7 @@ SLmetrics::weighted.cmatrix(
)
```

## Bug-fixes
## :bug: Bug-fixes

* **Return named vectors:** The classification metrics when `micro == NULL` were not returning named vectors. This has been fixed.

Expand Down Expand Up @@ -194,7 +204,7 @@ try(
)
```

## Bug-fixes
## :bug: Bug-fixes

* **Floating precision:** Metrics would give different results based on the method used. This means that `foo.cmatrix()` and `foo.factor()` would produce different results (See Issue https://github.com/serkor1/SLmetrics/issues/16). This has been fixed by using higher precision `Rcpp::NumericMatrix` instead of `Rcpp::IntegerMatrix`.

Expand Down Expand Up @@ -259,7 +269,7 @@ SLmetrics::accuracy(
)
```

## Bug-fixes
## :bug: Bug-fixes

* The `plot.prROC()`- and `plot.ROC()`-functions now adds a line to the plot when `panels = FALSE`. See Issue https://github.com/serkor1/SLmetrics/issues/9.

Expand Down
19 changes: 16 additions & 3 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,17 @@

# Version 0.3-1

> Version 0.3-1 is considered pre-release of {SLmetrics}. We do not
> expect any breaking changes, unless a major bug/issue is reported and
> its nature forces breaking changes.
## :bug: Bug-fixes

- **Plot-method in ROC and prROC
(<https://github.com/serkor1/SLmetrics/issues/36>):** Fixed a bug in
`plot.ROC()` and `plot.prROC()` where if `panels = FALSE` additional
lines would be added to the plot.

# Version 0.3-0

> Version 0.3-0 is considered pre-release of {SLmetrics}. We do not
Expand Down Expand Up @@ -143,7 +156,7 @@ SLmetrics::weighted.cmatrix(
#> b 3.506631 5.426818 8.358687
#> c 6.615661 6.390454 2.233511

## Bug-fixes
## :bug: Bug-fixes

- **Return named vectors:** The classification metrics when
`micro == NULL` were not returning named vectors. This has been fixed.
Expand Down Expand Up @@ -247,7 +260,7 @@ try(
#> Error in UseMethod(generic = "weighted.accuracy", object = ..1) :
#> no applicable method for 'weighted.accuracy' applied to an object of class "cmatrix"

## Bug-fixes
## :bug: Bug-fixes

- **Floating precision:** Metrics would give different results based on
the method used. This means that `foo.cmatrix()` and `foo.factor()`
Expand Down Expand Up @@ -353,7 +366,7 @@ SLmetrics::accuracy(
)
```

## Bug-fixes
## :bug: Bug-fixes

- The `plot.prROC()`- and `plot.ROC()`-functions now adds a line to the
plot when `panels = FALSE`. See Issue
Expand Down
Binary file modified NEWS_files/figure-gfm/unnamed-chunk-10-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified NEWS_files/figure-gfm/unnamed-chunk-10-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
74 changes: 39 additions & 35 deletions R/S3_PrecisionRecallCurve.R
Original file line number Diff line number Diff line change
Expand Up @@ -124,41 +124,45 @@ plot.prROC <- function(
x,
panels = TRUE,
...) {

# 1) Plot options
#
# All common options for the
# plot goes her
pformula <- precision ~ recall
groups <- x$label
xlab <- "Recall"
ylab <- "Precision"
main <- "Precision-Recall Curve"

# 1.1) conditional plotting
# statements
if (panels) {

# 1.2) grouped by
# label.
pformula <- precision ~ recall | factor(label, labels = unique(label))

# 1.3) disable grouping
# if panelwise
groups <- NULL

}

roc_plot(
formula = pformula,
groups = groups,
xlab = xlab,
ylab = ylab,
main = main,
DT = x[is.finite(x$threshold), ],
add_poly = panels,
...
)

# 0) exract the finite
# data.frame
x <- x[is.finite(x$threshold), ]

# 1) Plot options
#
# All common options for the
# plot goes her
pformula <- precision ~ recall
groups <- x$label
xlab <- "Recall"
ylab <- "Precision"
main <- "Precision-Recall Curve"

# 1.1) conditional plotting
# statements
if (panels) {

# 1.2) grouped by
# label.
pformula <- precision ~ recall | factor(label, labels = unique(label))

# 1.3) disable grouping
# if panelwise
groups <- NULL

}

roc_plot(
formula = pformula,
groups = groups,
xlab = xlab,
ylab = ylab,
main = main,
DT = x,
add_poly = panels,
...
)

}

Expand Down
78 changes: 40 additions & 38 deletions R/S3_RecieverOperatorCharacteristics.R
Original file line number Diff line number Diff line change
Expand Up @@ -130,44 +130,46 @@ plot.ROC <- function(
x,
panels = TRUE,
...) {



# 1) Plot options
#
# All common options for the
# plot goes her
pformula <- tpr ~ fpr
groups <- x$label
xlab <- "False Positive Rate (FPR)"
ylab <- "True Positive Rate (TPR)"
main <- "Reciever Operator Characteristics"

# 1.1) conditional plotting
# statements
if (panels) {

# 1.2) grouped by
# label.
pformula <- tpr ~ fpr | factor(label, labels = unique(label))

# 1.3) disable grouping
# if panelwise
groups <- NULL

}


roc_plot(
formula = pformula,
groups = groups,
xlab = xlab,
ylab = ylab,
main = main,
DT = x[is.finite(x$threshold), ],
add_poly = panels,
...
)

# 0) exract the finite
# data.frame
x <- x[is.finite(x$threshold), ]

# 1) Plot options
#
# All common options for the
# plot goes her
pformula <- tpr ~ fpr
groups <- x$label
xlab <- "False Positive Rate (FPR)"
ylab <- "True Positive Rate (TPR)"
main <- "Reciever Operator Characteristics"

# 1.1) conditional plotting
# statements
if (panels) {

# 1.2) grouped by
# label.
pformula <- tpr ~ fpr | factor(label, labels = unique(label))

# 1.3) disable grouping
# if panelwise
groups <- NULL

}


roc_plot(
formula = pformula,
groups = groups,
xlab = xlab,
ylab = ylab,
main = main,
DT = x,
add_poly = panels,
...
)

}

Expand Down
14 changes: 12 additions & 2 deletions tests/testthat/test-ROC.R
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,22 @@ testthat::test_that(
# 2.3) Test that methods
# works as expected
testthat::expect_no_condition(
object = invisible(capture.output(SLmetrics:::print.ROC(score))),
object = invisible(capture.output(print(score))),
message = info
)

testthat::expect_no_condition(
object = SLmetrics:::plot.ROC(score),
object = invisible(capture.output(summary(score))),
message = info
)

testthat::expect_no_condition(
object = plot(score, panels = FALSE),
message = info
)

testthat::expect_no_condition(
object = plot(score, panels = TRUE),
message = info
)

Expand Down
14 changes: 12 additions & 2 deletions tests/testthat/test-prROC.R
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,22 @@ testthat::test_that(
# 2.3) Test that methods
# works as expected
testthat::expect_no_condition(
object = invisible(capture.output(SLmetrics:::print.prROC(score))),
object = invisible(capture.output(print(score))),
message = info
)

testthat::expect_no_condition(
object = SLmetrics:::plot.prROC(score),
object = invisible(capture.output(summary(score))),
message = info
)

testthat::expect_no_condition(
object = plot(score, panels = FALSE),
message = info
)

testthat::expect_no_condition(
object = plot(score, panels = TRUE),
message = info
)

Expand Down

0 comments on commit c0500dc

Please sign in to comment.