Closed mikoontz closed 2 years ago
Hi,
Thank you very much for pointing out this critical problem!
However, I noticed it during my work on the package during my holidays and submitted a fix to the development version a few weeks ago. I have been re-testing it today just to be sure, and it it seems to be working as expected.
If you are going to try it, please keep in mind that the development version is still a work in progress, and some things are surely broken.
Thanks again for keeping those issues coming. I truly appreciate it!
Cheers,
Blas
[edit]: I just submitted a new version of rf_evaluate() fixing an issue that was too related to the order of the metrics!
Great news! I think we can safely close this issue then.
tl;dr
Incorrect values of evaluation metrics can be given depending on the order of the character vector passed as the
metrics=
argument torf_evaluate()
. Happens because of a forced renaming of columns based on a hard-coded order. Can be fixed with a small patch (let me know if you want a PR!)Some details
I came across this issue while working to spatially cross-validate a non-spatial model with a binomial response. I was using AUC and R^2 as my evaluation metrics, and wanted to add RMSE. I did so, then my AUC metric was appearing in the row labeled RMSE and vice versa. At first I was shocked at how low my AUC was! Then I realized I was working with the same data (and same random seed) so something else must have been going on.
In looking closely at the model object updated with the
$evaluation
data, I see that themodel$evaluation$per.fold
data.frame appears to be correct, but that themodel$evaluation$per.fold.long
andmodel$evaluation$per.model
appear to be wrong. The rows inmodel$evaluation$per.fold.long
andmodel$evaluation$per.model
that correspond to the "full" model also look to be correct, with just the rows representing "training" and "testing" having the metrics and values mislabeled.All of this suggest to me that, in the
rf_evaluate()
code,evaluation.df
is correct,performance.full
is correct, and there's an issue withperformance.training
andperformance.testing
.I think the problem is in the renaming of the columns here: https://github.com/BlasBenito/spatialRF/blob/9bc7edd444a1dac0531da07791d0332db08f6450/R/rf_evaluate.R#L403-L406.
If the order of the
metrics
character vector happens to be the same order of the metrics in the columns ofperformance.testing
andperformance.training
, then there is no problem. But if the order is different inmetrics
, then the assignment coerces the column names to the order provided by themetrics=
argument (c(metrics, "model")
).Possible fix This approach appears to work: remove the current approach to defining the
colnames()
and instead substitute the.training
part of the column names inperformance.training
or the.testing
part of the column name inperformance.testing
to be blank, then reassign theperformance.training
andperformance.testing
objects as you do withperformance.full
. That is:Minimum working example
This initial block is copied exactly from your excellent tutorial:
The next block shows the issue by running
rf_evaluate()
in two different ways, with only the order of themetrics=
argument switched.The output from
print_evaluation()
shows the problem. The values for AUC are switched with the values from RMSE!Troubleshooting code from
rf_evaluate()
that diagnosed problem to thecolnames()
assignmentContinue this block using the code from the minimum working example above.