Comments (4)
You are right, there is no option for the proximity matrix yet and getTerminalNodeIds()
is very slow. An option would be to add this to the predict()
function, e.g. by setting type = "terminalNodeID"
or something similar.
from ranger.
Yes this would be great to have such a functionality !
In the meantime, for those that would like to get the terminal node IDs in a faster way, you could use the following RCpp based getTerminalNodeIDs function (which should work on numeric data) :
library(Rcpp)
cppFunction('
NumericVector getTerminalNodeIDsCPP(NumericVector childNodesIDs1,NumericVector childNodesIDs2,NumericVector splitValues,NumericVector splitVarIDs,NumericMatrix mat)
{
NumericVector res(mat.nrow());
for(int i=0;i<mat.nrow();i++)
{
int nodeID = 1;
double value =0;
while (true) {
if ( (childNodesIDs1[nodeID-1] == 0 && childNodesIDs2[nodeID-1] == 0))
{
break;
}
int splitVarID = splitVarIDs[nodeID-1];
value = mat(i,splitVarID-1);//obs[splitVarID-1];
if (value <= splitValues[nodeID-1]) {
nodeID = childNodesIDs1[nodeID-1] + 1;
}
else {
nodeID = childNodesIDs2[nodeID-1] + 1;
}
}
res[i]=nodeID;
}
return(res);
}
')
getTerminalNodeIDs2<-function(data,rf)
{
res=sapply(1:rf$num.trees, function(tree) {
getTerminalNodeIDsCPP(rf$forest$child.nodeIDs[[tree]][[1]],rf$forest$child.nodeIDs[[tree]][[2]],as.double(rf$forest$split.values[[tree]]),rf$forest$split.varIDs[[tree]],as.matrix(data))
})
return(res)
}
#example
library(ranger)
rf=ranger(Species ~ ., data = iris,write.forest=T)
y1=getTerminalNodeIDs2(iris[,-5],rf)
y2=getTerminalNodeIDs(rf,iris[,-5])
identical(y1,y2)
[1] TRUE
system.time(getTerminalNodeIDs(rf,iris[,-5]))
#utilisateur système écoulé
1.551 0.016 1.613
system.time(getTerminalNodeIDs2(iris[,-5],rf))
#utilisateur système écoulé
0.033 0.001 0.034
from ranger.
New option "terminalNodes"
added to predict()
, as described above.
from ranger.
Thanks a lot !
On 21 September 2016 at 22:33, Marvin N. Wright [email protected]
wrote:
New option "terminalNodes" added to predict(), as described above.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/imbs-hl/ranger/issues/90#issuecomment-248734225, or mute
the thread
https://github.com/notifications/unsubscribe-auth/AAcme9NlnuvshLtHFGgtoODq0OOfXmOIks5qsZSIgaJpZM4JInJT
.
from ranger.
Related Issues (20)
- Define a custom loss function HOT 2
- R squared in stand alone version
- Error: Missing data in columns: predictor1, predictor2.... HOT 2
- Incorrect bounds check in beta log probability HOT 2
- Different predictions based on variable importance setting HOT 4
- `ranger()` finished, but `rsession` is still running HOT 8
- Trying to spatially predict(type="se")$se and the output has many null values and what look like spatial offsets? HOT 6
- compilation failed for package ‘ranger’ HOT 34
- ranger-cli fails to build HOT 1
- treeInfo() fails for probability trees with non-factor response HOT 1
- Poor handling of character string predictors HOT 6
- Increasing mtry crashes ranger fit HOT 3
- make fails => cannot compile C++ source on Mac HOT 2
- Error updating the package HOT 14
- warnings generated running 'Understanding random forests with randomForestExplainer' code HOT 1
- num.threads causing crashes inside caret recursive feature elimination wrapper HOT 1
- Results from importance_pvalues() differ despite setting seed HOT 1
- Decision Tree Build HOT 2
- Random forest prediction intervals using the out-of-bag predictions errors. HOT 2
- Is there a way to fit an isolation forest using ranger? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ranger.