araastat / reprtree Goto Github PK
View Code? Open in Web Editor NEWRepresentative trees from ensembles
Representative trees from ensembles
Categorical data cutpoints based on binary expansion in getTree. Need to implement in as.tree
Labels are plotted as if plot.tree(..., type='uniform') is not in effect.
I'm attempting to use this for the random forests I've generated using the sklearn package in python, and my code runs fine in R using repl_python(), but when I get to the step of creating the tree (repr <- ReprTree(py$mod, py$data1)) it stays that it can't be run due to "Error in UseMethod("predict2"). Full error below:
Error in UseMethod("predict2") :
no applicable method for 'predict2' applied to an object of class "c('sklearn.ensemble._forest.RandomForestClassifier', 'sklearn.ensemble._forest.ForestClassifier', 'sklearn.base.ClassifierMixin', 'sklearn.ensemble._forest.BaseForest', 'sklearn.base.MultiOutputMixin', 'sklearn.ensemble._base.BaseEnsemble', 'sklearn.base.MetaEstimatorMixin', 'sklearn.base.BaseEstimator', 'python.builtin.object')"
Has anyone dealt with this before, and if so, is there a way around it?
hi, i've seen people also posting similar issue that i get when trying to use the package to plot random forest results from the caret fit. Any way around it? Here is the error I am getting:
zz <- getTree(rf.best$finalModel, k=1, labelVar=TRUE)
realtree <- reprtree:::as.tree(zz, rf.best$finalModel)
>> Error in data.frame(var = fr$var, splits = as.character(gTree[, "split point"]), :
arguments imply differing number of rows: 117, 0
No other function is available to R. e.g.
reprtree::plot.getTree(mdl_rf$finalModel)
Error: 'plot.getTree' is not an exported object from 'namespace:reprtree'
I'm using Microsoft Open R 3.4.0 and RStudio 1.0.153 on OS X Sierra 10.12.6.
Thanks
Hello !
I tried to use the function reprtree:::plot.getTree(my_model) but it is not working and I have the following message:
"Error in row.names<-.data.frame
(*tmp*
, value = strtoi(x, 2)) :
duplicate 'row.names' are not allowed
In addition: Warning message:
non-unique values when setting 'row.names': "
I tried to display my trees with the following lines of code:
rf11_100<-randomForest(Bid~., data=df11, ntree=100, proximity=TRUE)
reprtree:::plot.getTree(rf11_100,3,labelVar=TRUE)
(3 is just to get the display of the tree number 3).
Let me know if you need anything else.
Thanks for your help !
Visign
Hello,
I used the "casualForest" function from "causalTree" package, once I want to find the best tree by using "reprtree" function, I got the following error.
dataset:
N observation:9000
outcome variable: categorical (0,1)
W=categorical
cf <- causalForest(formula=fmla, data=forestX, treatment=forestX$W,
split.Rule="CT", split.Honest=T, split.Bucket=F, bucketNum = 5,
bucketMax = 100, cv.option="CT", cv.Honest=T, minsize = 2L,
split.alpha = 0.5, cv.alpha = 0.5,
sample.size.total = floor(nrow(forestX) / 2), sample.size.train.frac = .5,
mtry = ceiling(ncol(forestX)/3), nodesize = 100, num.trees=10,
ncolx=length(predictorsNames),ncov_sample=4)
ReprTree(cf,forestX,metric="d2")
[1] "Constructing distance matrix..."
Error in UseMethod("predict2") :
no applicable method for 'predict2' applied to an object of class "causalForest"
Reproducible example:
library(reprtree)
library(randomForest)
data(spam, package="kernlab")
rf <- randomForest(type ~. , data = spam, ntree = 10)
as.tree(getTree(rf, 1, labelVar = T), rf)
Produces:
Error in match.fun(FUN) : object 'factor.repr' not found
current default is left splits
The comment above is the error message I receive in R v 3.5.1 when I attempt to install the reprtree package using the code below:
`options(repos='http://cran.rstudio.org')
have.packages <- installed.packages()
cran.packages <- c('devtools','plotrix','randomForest','tree')
to.install <- setdiff(cran.packages, have.packages[,1])
if(length(to.install)>0) install.packages(to.install)
library(devtools)
if(!('reprtree' %in% installed.packages())){
install_github('araastat','reprtree')
}
for(p in c(cran.packages, 'reprtree')) eval(substitute(library(pkg), list(pkg=p)))`
Any thoughts on how to fix this?
Reproducible example:
library(reprtree)
library(randomForest)
data(spam, package="kernlab")
rf <- randomForest(type ~. , data = spam, ntree = 1)
reptr <- ReprTree(rf, spam, metric = "d2")
Produces:
[1] "Constructing distance matrix..."
Error in x[l, ] : subscript out of bounds
Solution: something like:
if ntrees = 1, then representative tree is that tree
Great package, thx
Could we add node IDs to the plot ?
Thanks!
Markus
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.