GithubHelp home page GithubHelp logo

Comments (5)

sjsw avatar sjsw commented on June 11, 2024

It looks like this was actually caused by an outdated version of glmnet and not by forestry itself.

from rforestry.

sjsw avatar sjsw commented on June 11, 2024

Actually it seems it is not related to glment version, rather the error is intermittent because it depends on the seed used to construct the forest. I think it probably arises when a tree contains leaves that are grown to purity, which causes glmnet to fail when called in the plotting method. This could be fixed by patching the plotting function to not call glmnet when the variance of the outcome in a leaf is zero.

from rforestry.

linanqiu avatar linanqiu commented on June 11, 2024

For the case where you have this error:

Error in if (any(lambda < 0)) stop("lambdas should be non-negative") : 
  missing value where TRUE/FALSE needed

The cause is:

Rforestry/R/plottree.R

Lines 238 to 252 in cecf729

if (forestry_tree@linear) {
# ridge forest
for (leaf_id in node_info$node_id[node_info$is_leaf]) {
# leaf_id = 5
###
this_ds <- dta_x[leaf_idx[[leaf_id]],
forestry_tree@linFeats + 1]
encoder <- onehot::onehot(this_ds)
remat <- predict(encoder, this_ds)
###
y_leaf <- dta_y[leaf_idx[[leaf_id]]]
plm <- glmnet::glmnet(x = remat,
y = y_leaf,
lambda = forestry_tree@overfitPenalty * sd(y_leaf)/nrow(remat),
alpha = 0)

As you said, y_leaf is a single element vector. sd(y_leaf) = NA, causing lambda = NA.

Browse[1]> n
debug at C:/Users/Linan Qiu/Desktop/temp.R#227: plm <- glmnet::glmnet(x = remat, y = y_leaf, lambda = forestry_tree@overfitPenalty * 
    sd(y_leaf)/nrow(remat), alpha = 0)
Browse[2]> forestry_tree@overfitPenalty * sd(y_leaf)/nrow(remat)
[1] NA
Browse[2]> sd(y_leaf)
[1] NA
Browse[2]> y_leaf
[1] -19.65548

from rforestry.

linanqiu avatar linanqiu commented on June 11, 2024

For the case where you have the other error:

 Error in elnet(xd, is.sparse, ix, jx, y, weights, offset, type.gaussian,  : 
  y is constant; gaussian glmnet fails at standardization step 

The cause is still that couple of lines, but that's when y_leaf has length > 1 but consist of all the same elements:

# added these print statements to the if block above:

#      message(glue('overfitPenalty: {forestry_tree@overfitPenalty}'))
#      message(glue('y_leaf: {paste0(y_leaf, collapse = ", ")}, sd(y_leaf): {sd(y_leaf)}'))
#      message(glue('nrow(remat): {nrow(remat)}'))

overfitPenalty: 1
y_leaf: -9.56037240704544, -9.56037240704544, -9.56037240704544, sd(y_leaf): 0
nrow(remat): 3

Y is constant, which is what glmnet is complaining about. Could be because glmnet does some standardization (https://stackoverflow.com/questions/54755857/glmnet-error-nulldev-0-stopy-is-constant-gaussian-glmnet-fails-at-standa) and fails at sd(y_leaf) = 0

These two cases seem to exhaust the errors I've seen by clicking source a dozen times 😛

Seems like the right thing to do for a linear aggregator at leaf in these cases is just to return Y?

from rforestry.

sjsw avatar sjsw commented on June 11, 2024

This LGTM, Linan! :)

from rforestry.

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.