Git Product home page Git Product logo

Comments (5)

crarlus avatar crarlus commented on July 27, 2024 1

Hi,
we experienced a problem when using ranger version 0.5. Apparantly something has changed since version 0.4 in the handling of the label data. In a simple two-class problem, it seems to rename the labels internally in numerical or lexicographical order, thus providing misleading predictions.

It is easily demonstrated with a toy example:

#  create trainingsdata
n = 1000
a1 = c(rnorm(n, 3, sd = 2), rnorm(n, 8, sd = 2))
a2 = c(rnorm(n, 8, sd = 2), rnorm(n, 3, sd = 2))

# create labels for data
labels <- as.factor(c(rep("0", n), rep("1", n)))
labels.rev <- as.factor(c(rep("1", n), rep("0", n))) # switch label -> expect switch of predictions

# training
test_forest <- ranger::ranger(dependent.variable.name = "label", data = data.frame(label = labels, a1, a2), write.forest = T, probability = T)

test_forest.rev_labels <- ranger::ranger(dependent.variable.name = "label", data = data.frame(label = labels.rev, a1, a2), write.forest = T, probability = T)

Whereas in ranger 0.4 the predictions are as expected, the first few predictions either have high probabilities for label "0" or for label "1" with reversed labels:

> head(test_forest$predictions)
             0            1
[1,] 1.0000000 0.0000000000
[2,] 1.0000000 0.0000000000
[3,] 0.7267204 0.2732796452
[4,] 0.9916530 0.0083470170
[5,] 0.9613803 0.0386196857
[6,] 0.9994949 0.0005050505
> head(test_forest.rev_labels$predictions)
              0         1
[1,] 0.00000000 1.0000000
[2,] 0.00000000 1.0000000
[3,] 0.29646739 0.7035326
[4,] 0.01103671 0.9889633
[5,] 0.04867796 0.9513220
[6,] 0.00000000 1.0000000

However, in the case of ranger 0.5 the predictions are always in favor of class "0" although in this test examples the labels have been reversed:

> head(test_forest_version5$predictions)
             0          1
[1,] 1.0000000 0.00000000
[2,] 1.0000000 0.00000000
[3,] 0.6686391 0.33136095
[4,] 1.0000000 0.00000000
[5,] 0.9776536 0.02234637
[6,] 1.0000000 0.00000000
> head(test_forest.rev_labels_version5$predictions)
             0          1
[1,] 1.0000000 0.00000000
[2,] 1.0000000 0.00000000
[3,] 0.7530120 0.24698795
[4,] 1.0000000 0.00000000
[5,] 0.9757576 0.02424242
[6,] 1.0000000 0.00000000

The predictions for test_forest.rev_labels_version5 should show high predictions for class "1".

Some more comments:

  • The same issue persists when choosing different labels, e.g. strings.
  • Also, the same is true for the prediction of independent test data, it seems to be an issue of the training.
  • Predicting a forest trained in version 0.4 yields the correct prediction when loaded in version 0.5.
  • Vice versa, a forest trained in version 0.5 does not predict correct in version 0.4.

from ranger.

mnwright avatar mnwright commented on July 27, 2024

Thanks for this detailed analysis. I can confirm that this is a bug. The prediction is made on the levels in the order they appear in the data but the labels saved with R's levels() function, which sorts them alphabetically.

from ranger.

mnwright avatar mnwright commented on July 27, 2024

Fixed.

from ranger.

Eric2333 avatar Eric2333 commented on July 27, 2024

When will this be available on CRAN?

from ranger.

mnwright avatar mnwright commented on July 27, 2024

There will probably be a CRAN release in October.

from ranger.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.