Hi, the maintainer hasn't answered yet. The problem with 'acc' is that yes the objects are not of the same length but they should be: according to the manual, ' table(pred, df$cons)' would return a 2x2 matrix of the results. This is not the case, so there is a problem with the model -- that is why there is no plotting either -- even if an object of class ksvm had been created.
On Tue, Jan 8, 2019 at 4:12 PM PIKAL Petr <petr.pi...@precheza.cz> wrote: > > Hi > > I cannot help you with kernlab > > > > pred = predict(mod, df, type = "probabilities") > > > acc = table(pred, df$cons) > > Error in table(pred, df$cons) : all arguments must have the same length > > which again is weird since mod, df and df$cons are made from the same > > dataframe. > > Why not check length of those objects? > > length(pred) > length(df$cons) > > > > plot(mod, data = df) > > > kernlab::plot(mod, data = df) > > but I get this error: > > > > Error in .local(x, ...) : > > Only plots of classification ksvm objects supported > > > > seems to me selfexplanatory. What did maintainer said about it? > > Cheers > Petr > > > > -----Original Message----- > > From: R-help <r-help-boun...@r-project.org> On Behalf Of Luigi Marongiu > > Sent: Monday, January 7, 2019 1:26 PM > > To: r-help <r-help@r-project.org> > > Subject: [R] error in plotting model from kernlab > > > > Dear all, > > I have a set of data in this form: > > > str <data> > > 'data.frame': 1574 obs. of 14 variables: > > $ serial: int 12751 14157 7226 15663 11088 10464 1003 10427 11934 3999 > > ... > > $ plate : int 43 46 22 50 38 37 3 37 41 11 ... > > $ well : int 79 333 314 303 336 96 235 59 30 159 ... > > $ sample: int 266 295 151 327 231 218 21 218 249 84 ... > > $ target: chr "HEV 2-AI5IQWR" "Dientamoeba fragilis-AIHSPMK" "Astro > > 2 Liu-AI20UKB" "C difficile GDH-AIS086J" ... > > $ ori.ct: num 0 33.5 0 0 0 ... > > $ ct.out: int 0 1 0 0 0 0 0 1 0 0 ... > > $ mr : num -0.002 0.109 0.002 0 0.001 0.006 0.015 0.119 0.003 0.004 ... > > $ fcn : num 44.54 36.74 6.78 43.09 44.87 ... > > $ mr.out: int 0 1 0 0 0 0 0 1 0 0 ... > > $ oper.a: int 0 1 0 0 0 0 0 1 0 0 ... > > $ oper.b: int 0 1 0 0 0 0 0 1 0 0 ... > > $ oper.c: int 0 1 0 0 0 0 0 1 0 0 ... > > $ cons : int 0 1 0 0 0 0 0 1 0 0 ... > > from which I have selected two numerical variables correspondig to x > > and y in a Cartesian plane and one outcome variable (z): > > > df = subset(t.data, select = c(mr, fcn, cons)) > > > df$cons = factor(c("negative", "positive")) > > > head(df) > > mr fcn cons > > 1 -0.002 44.54 negative > > 2 0.109 36.74 positive > > 3 0.002 6.78 negative > > 4 0.000 43.09 positive > > 5 0.001 44.87 negative > > 6 0.006 2.82 positive > > > > I created an SVM the method with the KERNLAB package with: > > > mod = ksvm(cons ~ mr+fcn, # i prefer it to the more canonical "." but the > > outcome is the same > > data = df, > > type = "C-bsvc", > > kernel = "rbfdot", > > kpar = "automatic", > > C = 10, > > prob.model = TRUE) > > > > > mod > > Support Vector Machine object of class "ksvm" > > > > SV type: C-bsvc (classification) > > parameter : cost C = 10 > > > > Gaussian Radial Basis kernel function. > > Hyperparameter : sigma = 42.0923201429106 > > > > Number of Support Vectors : 1439 > > > > Objective Function Value : -12873.45 > > Training error : 0.39263 > > Probability model included. > > > > First of all, I am not sure if the model worked because 1439 support > > vectors out of 1574 data points means that over 90% of the data is > > required to fix the hyperplane. this does not look like a model but a > > patch. Secondly, the prediction is rubbish -- but this is another > > story -- and when I try to create a confusion table of the processed > > data I get: > > > pred = predict(mod, df, type = "probabilities") > > > acc = table(pred, df$cons) > > Error in table(pred, df$cons) : all arguments must have the same length > > which again is weird since mod, df and df$cons are made from the same > > dataframe. > > > > Coming to the actual error, I tried to plot the model with: > > > plot(mod, data = df) > > > kernlab::plot(mod, data = df) > > but I get this error: > > > > Error in .local(x, ...) : > > Only plots of classification ksvm objects supported > > > > Would you know what I am missing? > > Thank you > > -- > > Best regards, > > Luigi > > > > ______________________________________________ > > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > > https://stat.ethz.ch/mailman/listinfo/r-help > > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > > and provide commented, minimal, self-contained, reproducible code. > Osobní údaje: Informace o zpracování a ochraně osobních údajů obchodních > partnerů PRECHEZA a.s. jsou zveřejněny na: > https://www.precheza.cz/zasady-ochrany-osobnich-udaju/ | Information about > processing and protection of business partner’s personal data are available > on website: https://www.precheza.cz/en/personal-data-protection-principles/ > Důvěrnost: Tento e-mail a jakékoliv k němu připojené dokumenty jsou důvěrné a > podléhají tomuto právně závaznému prohláąení o vyloučení odpovědnosti: > https://www.precheza.cz/01-dovetek/ | This email and any documents attached > to it may be confidential and are subject to the legally binding disclaimer: > https://www.precheza.cz/en/01-disclaimer/ > -- Best regards, Luigi ______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.