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

How to suppress the warning message for binary classification metrics? #19

Closed
liuyxpp opened this issue Jan 22, 2024 · 3 comments
Closed

Comments

@liuyxpp
Copy link
Contributor

liuyxpp commented Jan 22, 2024

I am using MLJ v0.20.2 with StatisticalMeasures.jl v0.1.3.

yt = Int.(rand(100) .> 0.5)
yp = Int.(rand(100) .> 0.5)
cm = MLJ.confmat(yp, yt)
MLJ.PositivePredictiveValue()(cm)

which emitts a warning:

┌ Warning: Levels not explicitly ordered. Using the order [0, 1]. The "positive" level is 1. 
└ @ StatisticalMeasures.ConfusionMatrices [~/.julia/packages/StatisticalMeasures/NoDLI/src/confusion_matrices.jl:333](https://vscode-remote+ssh-002dremote-002bivosrv6.vscode-resource.vscode-cdn.net/home/lyx/projects/rules/~/.julia/packages/StatisticalMeasures/NoDLI/src/confusion_matrices.jl:333)

Many other measures have similar behavior. I try to add warn=false keyword (which was found in the above mentioned confusion_matrices.jl but without success.

Is there any easy way to get rid of this warning. Or better, how can I correctly set the levels to eliminate the warning? I try a lot of ways but failed. Thanks!

@ablaom
Copy link
Member

ablaom commented Jan 22, 2024

  1. Thanks for your question.
using StatisticalMeasures

# option 1: Use categorical arrays for categorical data (recommended throughout MLJ ecosystem)
using CategoricalArrays
yt = categorical(yt, ordered=true) # ordered 0, 1
yp = categorical(yp, ordered=true)
cm = confmat(yp, yt)
PositivePredictiveValue()(cm)
# 0.5306122448979591

# option 2: Notice `confmat` is just alias for `ConfusionMatrix()`, which has `levels` as
# an option; see its docstring.
yt = Int.(rand(100) .> 0.5)
yp = Int.(rand(100) .> 0.5)
confmat2 = ConfusionMatrix(levels=[0, 1]) # negative class first
cm = confmat2(yp, yt)
PositivePredictiveValue()(cm)
# 0.5306122448979591

Is this a satisfactory answer?

@ablaom
Copy link
Member

ablaom commented Jan 22, 2024

And of course, the choice of negative class matters:

confmat2 = ConfusionMatrix(levels=[1, 0]) # negative class first
cm = confmat2(yp, yt)
PositivePredictiveValue()(cm)
# 0.5087719298245614

@liuyxpp
Copy link
Contributor Author

liuyxpp commented Jan 22, 2024

Crystal & clear, Thanks! I will follow the recommended option 1.

@liuyxpp liuyxpp closed this as completed Jan 22, 2024
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

No branches or pull requests

2 participants