Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added precision, recall, f1_score #20

Merged
merged 8 commits into from
Jun 9, 2018
Merged

Conversation

mthorrell
Copy link

@mthorrell mthorrell commented Apr 19, 2018

would like to have some type checking since precision, recall and f1 depend on 0 and 1 predictions, but basics should be here. Referencing issue #19.

@codecov-io
Copy link

codecov-io commented Apr 19, 2018

Codecov Report

Merging #20 into dev will increase coverage by 0.09%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##              dev      #20      +/-   ##
==========================================
+ Coverage   98.01%   98.11%   +0.09%     
==========================================
  Files           5        5              
  Lines         101      106       +5     
==========================================
+ Hits           99      104       +5     
  Misses          2        2
Impacted Files Coverage Δ
R/binary_classification.R 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 426aa55...ac43891. Read the comment docs.

Copy link
Owner

@mfrasco mfrasco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR. This looks really great. Thanks for following the package theme of defining some metrics in terms of other metrics. In addition to my documentation requests and formatting requests, can you also generate documentation for the new functions by running devtools::document()?


#' Precision
#'
#' \code{precision} computes proportion of predicted 1's that are actual 1's
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you change this to, "computes proportion of observations predicted to be in the positive class (i.e. the element in \code{predicted} equals 1) that actually belong to the positive class (i.e. the element in \code{actual} equals 1)?

Thanks

#' Precision
#'
#' \code{precision} computes proportion of predicted 1's that are actual 1's
#' @export
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add #' @seealso \code{\link{recall}} \code{\link{fbeta_score}}

#' Precision
#'
#' \code{precision} computes proportion of predicted 1's that are actual 1's
#' @export
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also add #' @inheritParams params_binary

#' predicted <- c(1, 1, 1, 1, 1, 1)
#' precision(actual, predicted)
precision <- function(actual, predicted) {
return(mean(actual[predicted == 1]))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you use four spaces as the indentation?

#' @examples
#' actual <- c(1, 1, 1, 0, 0, 0)
#' predicted <- c(1, 0, 1, 1, 1, 1)
#' recall(actual, predicted)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add all of the same documentation improvements that were listed for precision?

#' actual <- c(1, 1, 1, 0, 0, 0)
#' predicted <- c(1, 0, 1, 1, 1, 1)
#' recall(actual, predicted)
f1_score <- function(actual, predicted, beta = 1) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fbeta_score

#' @examples
#' actual <- c(1, 1, 1, 0, 0, 0)
#' predicted <- c(1, 0, 1, 1, 1, 1)
#' recall(actual, predicted)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same documentation improvements

#'
#' \code{f1_score} computes the f1 score
#' @export
#' @seealso \code{\link{precision}}, \code{\link{recall}}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need the comma here

#' recall(actual, predicted)
f1_score <- function(actual, predicted, beta = 1) {
prec = precision(actual, predicted)
rec = recall(actual, predicted)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you use the assignment operator <- and use four spaces.

expect_equal(f1_score(c(1,1,0,0),c(1,1,0,0)), 1)
expect_equal(f1_score(c(0,0,1,1),c(1,1,1,0)), 2/5)
expect_equal(f1_score(c(1,1,1,1),c(1,0,0,1)), 2/3)
})
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the unit tests!

@mthorrell
Copy link
Author

thanks for the comments. Let me know your feedback on the F-beta score descriptions I made if you'd like that changed or if you want it to be more specific.

If this looks good, still to be done is to update the TeX equations on the main page.

@mfrasco
Copy link
Owner

mfrasco commented Apr 29, 2018

I think that this looks great. I like the descriptions of the fbeta_score function. In your original comment on this PR, you mentioned that you would like to do type checking on the inputs. I'm going to defer that work to a different PR, as the type checking needs to be made throughout the repo.

If you could add the equations to the README, I'll approve the PR.

@mthorrell
Copy link
Author

Sorry for the delay. I think this does it.

@dimagor
Copy link

dimagor commented Jun 9, 2018

Really excited to see these changes make it into this awesome package. Any thoughts on when this PR will be merged and ideally up on CRAN?

@mfrasco
Copy link
Owner

mfrasco commented Jun 9, 2018

@mthorrell I must have missed the email notification that alerted me to the fact that you pushed changes a month ago! I'm sorry. This all looks good. I'll merge this now. @dimagor I can push to CRAN this weekend.

@mfrasco mfrasco merged commit 07bcee0 into mfrasco:dev Jun 9, 2018
@dimagor
Copy link

dimagor commented Jun 24, 2018

@mfrasco thank you for merging this. Any luck with the CRAN update?

@mfrasco
Copy link
Owner

mfrasco commented Jul 10, 2018

@dimagor On CRAN now. Sorry for the delay. I missed the email from CRAN that described the changes that I needed to make in order to get it approved.

@dimagor
Copy link

dimagor commented Jul 10, 2018

Fantastic! Thanks a lot!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants