subscript - in R Plot importance variables of Random Forest model -
what doing wrong here? "subscript out of bound" mean?
i got below code (first block) excerpt form revolution r online seminar regarding datamining in r. i'm trying incorporate in rf model ran can't pass think ordering of variables. want plot importance of variables.
i included little more needed below give context. erroring out third line of code. second code block errors getting applied data working with. can me figure out?
------------------------------------------------------------------------- # list importance of variables. rn <- round(importance(model.rf), 2) rn[order(rn[,3], decreasing=true),] ##@# of # plot variable importance varimpplot(model.rf, main="",col="dark blue") title(main="variable importance random forest weather.csv", sub=paste(format(sys.time(), "%y-%b-%d %h:%m:%s"), sys.info()["user"])) #--------------------------------------------------------------------------
my errors:
> rn[order(rn[,2], decreasing=true),] error in order(rn[, 2], decreasing = true) : subscript out of bounds
think understand confusion. bet 4-finger kit kat if type in ncol(rn)
you'll see rn has 2 columns, not 3 might expect. first "column" you're seeing on screen isn't column - it's row names object rn. type rownames(rn)
confirm this. final column of rn want order therefore rn[,2] rather rn[,3]. "subscript out of bounds" message comes because you've asked r order column 3, rn doesn't have column 3.
here's brief detective trail interested in "importance" object is... installed library(randomforest) , ran example documentation online:
set.seed(4543) data(mtcars) mtcars.rf <- randomforest(mpg ~ ., data=mtcars, ntree=1000, keep.forest=false, importance=true) importance(mtcars.rf)
turns out "importance" object in case looks (first few rows save space):
%incmse incnodepurity cyl 17.058932 181.70840 disp 19.203139 242.86776 hp 17.708221 191.15919 ...
obviously ncol(importance(mtcars.rf)) 2, , row names thing leading confusion :)
Comments
Post a Comment