Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9229797
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T05:39:42+00:00 2026-06-18T05:39:42+00:00

I would like to extract the terminal nodes of the random forest R implementation.

  • 0

I would like to extract the terminal nodes of the random forest R implementation. As I have understood random forest, you have a sequence of orthogonal trees. When you predict a new observation (In regression), it enters all these trees and then you average the prediction of each individual tree. If I wanted to not average but maybe do a linear regression with these corresponding observations I would need, say, a list of the observations that are “associated” with this new observation. I have gone through the source code but havent come up with a way to obtain this. Can anyone help me?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T05:39:43+00:00Added an answer on June 18, 2026 at 5:39 am

    There must be a better way to do this, but here’s a workaround:

    library(randomForest)
    set.seed(713)
    ## data
    my.df <- data.frame(x = rnorm(100), y = rnorm(100))
    ## forest
    rf <- randomForest(y ~ x, data = my.df, ntree = 10, keep.inbag = TRUE)
    

    keep.inbag = TRUE saves the inbag observations that are used to fit each of the 10 trees in this example

    predList <- lapply(seq_len(rf$ntree), function(z) 
                predict(rf, newdata = my.df[rf$inbag[, z] == 1, ], nodes = TRUE))
    

    nodes = TRUE tracks the terminal nodes each observation ends in.

    node.list <- lapply(seq_len(rf$ntree), function(z) 
                split(x = my.df[rf$inbag[, z] == 1, "x"], 
                        f = attr(predList[[z]], "nodes")[, z]))
    

    First three terminal nodes of the first tree:

    node.list[[1]][1:3]
    
    $`3`
    [1] 2.028358 2.071939
    
    $`7`
    [1] 0.8306559
    
    $`9`
    [1] 1.660134 1.621299
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the next string /1234/somename and I would like to extract the somename
I have three mysql tables that I would like to extract some information from,
I have a string: /abc/def/ghfj.doc I would like to extract ghfj.doc from this, i.e.
I have string for example: 06.07.2010 (tor.) I would like to extract only 06.07.2010
In my table I have the following columns: id|name|gender I would like to extract
I would like to extract chains from pdb files. I have a file named
I would like to extract some lines from a text file, I have started
I have a NSString like this: 456673\tSomething But I would like to extract Something
I have a document where I would like to extract specific numbers from a
I would like to extract unique values from my (dynamically allocated) array. I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.