1

I am running 4 classifiers on a dataset and comparing their performance. When I run the following code I receive some weird errors:

library(mlbench)
library(mlr)

maxx_IL10   = c(3199,   2997,   2690,   2482,   2891,   2310,   3180,   3050,   3115,   3052,   3071,   3068,   2611,   2723,   2903,   2969)
auc_INTERLEUKIN_12P70   = c(14809,  1384.5, 760,    10922.5,    3010,   14564,  26496,  1229,   2509,   1474.5, 20697.5,    1854.5, 17352,  1457,   227,    31507.5)
maxx_TNFA   = c(3066,   2658,   2697,   3175,   2904,   2260,   2714,   3056,   3155,   3030,   3125,   2456,   3017,   2860,   1704,   3167)
fold_IL4    = c(16.02685,   0,  4.616438,   53.44898,   0,  0,  68.85714,   5.833333,   25.9,   0,  21.87629,   20.57895,   20.18792,   4.394737,   7.723404,   56.6383)
maxx_CD19   = c(3045.5, 3045.5, 3045.5, 3045.5, 2667,   1865,   3126,   2432,   3244,   3218,   2415,   3077,   3223,   2549,   3016,   3244)
auc_IL4 = c(18315.5,    0,  1348,   31112,  0,  0,  19182.5,    525,    3201.5, 0,  12976,  782,    19195.5,    835,    544.5,  26658)
Class   = c("B",    "A",    "A",    "A",    "A",    "A",    "B",    "A",    "B",    "B",    "B",    "A",    "B",    "A",    "A",    "B")

df = data.frame(maxx_IL10,  auc_INTERLEUKIN_12P70,  maxx_TNFA,  fold_IL4,   maxx_CD19,  auc_IL4,    Class)

Class.task = makeClassifTask( data = df, target = "Class", positive ="B")

fv = generateFilterValuesData(Class.task, method = "mrmr")

plotFilterValues(fv)

filtered.task = filterFeatures(Class.task, fval = fv, threshold = -.2)

n = getTaskSize(filtered.task)
train.set = sample(n, size = round(2/3 * n))
test.set = setdiff(seq_len(n), train.set)

lrn1 = makeLearner("classif.lda", predict.type = "prob")
mod1 = train(lrn1, filtered.task, subset = train.set)
pred1 = predict(mod1, task = filtered.task, subset = test.set)


lrn2 = makeLearner("classif.ksvm", predict.type = "prob")
mod2 = train(lrn2, filtered.task, subset = train.set)
pred2 = predict(mod2, task = filtered.task, subset = test.set)

lrn3 = makeLearner("classif.randomForest", predict.type = "prob")
mod3 = train(lrn3, Class.task, subset = train.set)
pred3 = predict(mod3, task = Class.task, subset = test.set)

lrn5 = makeLearner("classif.xgboost", predict.type = "prob")
mod5 = train(lrn5, Class.task, subset = train.set)
pred5 = predict(mod5, task = Class.task, subset = test.set)

### Tune wrapper for ksvm
rdesc.inner = makeResampleDesc("Holdout")
ms = list(auc, mmce)
ps = makeParamSet(
  makeDiscreteParam("C", 2^(-1:1))
)
ctrl = makeTuneControlGrid()
lrn2 = makeTuneWrapper(lrn2, rdesc.inner,ms, ps,  ctrl, show.info = FALSE)

lrns = list(lrn1, lrn2,lrn3,lrn5)
rdesc.outer = makeResampleDesc("CV", iters = 5)

bmr = benchmark(lrns, tasks = filtered.task, resampling = rdesc.outer, measures = ms, show.info = FALSE)
bmr

The errors that I receive are:

lrn2 = makeTuneWrapper(lrn2, rdesc.inner,ms, ps, ctrl, show.info = FALSE) Error in makeTuneWrapper(lrn2, rdesc.inner, ms, ps, ctrl, show.info = FALSE) : Assertion on 'measures' failed: May only contain the following types: Measure. lrns = list(lrn1, lrn2,lrn3,lrn5) rdesc.outer = makeResampleDesc("CV", iters = 5)

bmr = benchmark(lrns, tasks = filtered.task, resampling = rdesc.outer, measures = ms, show.info = FALSE) Error in FUN(X[[i]], ...) : List measures has element of wrong type function at position 1. Should be: Measure bmr Error: object 'bmr' not found

Any ideas on what I am doing wrong? Thank you!!

tom
  • 315
  • 1
  • 3
  • 10
  • The code you've posted works fine for me. Are you loading any other libraries that may shadow mlr functions? – Lars Kotthoff Jul 16 '16 at 21:22
  • Thank you!! It works if I quit R, don't save my environment, and start R fresh. Is there a way of detaching all libraries so I don't have quit R etc.? – tom Jul 17 '16 at 00:28
  • 1
    See https://stackoverflow.com/questions/7505547/detach-all-packages-while-working-in-r – Lars Kotthoff Jul 17 '16 at 21:54
  • I got the same problem in RStudio, I just removed it and reinstalled and no error anymore, odd. At the same time, R worked totally fine from terminal. – hhh Jul 18 '17 at 20:19

0 Answers0