How do you plot a CostSensitiveClassifier tree in R? -


in case i'm using rweka package , j48 within cost sensitive classifier function. know package "party" can plot normal j48 tree, not sure how plot csc output.

library(rweka)  csc <- costsensitiveclassifier(species ~ ., data = iris,  control = weka_control(`cost-matrix` = matrix(c(0,10, 0, 0, 0, 0, 0, 10, 0),  ncol = 3),  w = "weka.classifiers.trees.j48",  m = true))  csc costsensitiveclassifier using minimized expected misclasification cost  weka.classifiers.trees.j48 -c 0.25 -m 2  classifier model j48 pruned tree ------------------  petal.width <= 0.6: setosa (50.0) petal.width > 0.6 |   petal.width <= 1.7 |   |   petal.length <= 4.9: versicolor (48.0/1.0) |   |   petal.length > 4.9 |   |   |   petal.width <= 1.5: virginica (3.0) |   |   |   petal.width > 1.5: versicolor (3.0/1.0) |   petal.width > 1.7: virginica (46.0/1.0)  number of leaves  :     5  size of tree :  9   cost matrix   0  0  0  10  0 10   0  0  0 plot(csc) 

error in xy.coords(x, y, xlabel, ylabel, log) : 'x' list, not have components 'x' , 'y'

any great.

dput(csc)  structure(list(classifier = <s4 object of class structure("jobjref", package = "rjava")>,      predictions = structure(c(1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l,      1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l,      1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l,      1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 2l, 2l, 2l,      2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l,      2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l,      2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l,      2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l,      2l, 2l, 2l, 2l, 2l, 2l, 1l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l,      2l, 2l, 2l, 2l, 2l, 1l, 1l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l,      2l, 2l, 2l, 2l, 2l, 2l, 2l), .label = c("setosa", "versicolor",      "virginica"), class = "factor"), call = costsensitiveclassifier(formula = species ~          ., data = iris, control = weka_control(`cost-matrix` = matrix(c(0,          10, 0, 0, 0, 0, 0, 10, 0), ncol = 3), w = "weka.classifiers.trees.j48",          m = true)), handlers = structure(list(control = list(         function (x)          {             if (inherits(x, "weka_control")) {                 ind <- which(names(x) %in% substring(options,                    2l))                 if (any(ind))                    x[ind] <- lapply(x[ind], fun, ...)             }             else {                 x <- as.character(x)                 ind <- which(x %in% options)                 if (any(ind))                    x[ind + 1l] <- sapply(x[ind + 1l], fun, ...)             }             x         }, function (x)          {             if (inherits(x, "weka_control")) {                 ind <- which(names(x) %in% substring(options,                    2l))                 if (any(ind))                    x[ind] <- lapply(x[ind], fun, ...)             }             else {                 x <- as.character(x)                 ind <- which(x %in% options)                 if (any(ind))                    x[ind + 1l] <- sapply(x[ind + 1l], fun, ...)             }             x         }), data = function (mf)      {         terms <- attr(mf, "terms")         if (any(attr(terms, "order") > 1l))              stop("interactions not allowed.")         factors <- attr(terms, "factors")         varnms <- rownames(factors)[c(true, rowsums(factors)[-1l] >              0)]         mf[, sub("^`(.*)`$", "\\1", varnms), drop = false]     }), .names = c("control", "data")), levels = c("setosa",      "versicolor", "virginica"), terms = species ~ sepal.length +          sepal.width + petal.length + petal.width), .names = c("classifier",  "predictions", "call", "handlers", "levels", "terms"), class = c("costsensitiveclassifier",  "weka_meta", "weka_classifier")) 

actually, turns out pretty easy. try

library(rweka) library(party) library(partykit)   csc <- costsensitiveclassifier(species ~ ., data = iris,  control = weka_control(`cost-matrix` = matrix(c(0,10, 0, 0, 0, 0, 0, 10, 0),  ncol = 3),  w = "weka.classifiers.trees.j48",  m = true))  plot(as.party.weka_tree(csc)) 

that gives me

costsensitiveclassifier plot

the problem is, model reports it's class

> class(csc) [1] "costsensitiveclassifier" "weka_meta"     "weka_classifier"   

and there no method classes. however, there 1 "weka_tree" calls as.party.weka_tree , plots result. must admit don't know differences between costsensitiveclassifier tree , j48 tree hope plot accurate representation.


Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -