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 samedata = df, type = "C-bsvc", kernel = "rbfdot", kpar = "automatic", C = 10, prob.model = TRUE)> modSupport 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
a) When re-posting a question, whether on the same or different forums, it is best practice (netiquette) to link to or reply to the earlier question. [1] b) Note the guidance in the Posting Guide: For questions about functions in standard packages distributed with R (see the FAQ?Add-on packages in R), ask questions on R-help. If the question relates to a?contributed package?, e.g., one downloaded from CRAN, try contacting the package maintainer first. You can also use?find("functionname")?and?packageDescription("packagename")?to find this information.?Only?send such questions to R-help or R-devel if you get no reply or need further assistance. This applies to both requests for help and to bug reports. You have not communicated whether you have followed this recommendation. [1] https://stat.ethz.ch/pipermail/r-help/2018-December/461010.html On January 7, 2019 4:26:20 AM PST, Luigi Marongiu <marongiu.luigi at gmail.com> wrote:>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-- Sent from my phone. Please excuse my brevity.
Sorry but I don't understand the questions. I sent this question to R-help, not to an individual. I will use the REPLY TO ALL function when replying, apologies if I missed before. The question is related to an R package so I placed to the R community. On Mon, Jan 7, 2019 at 5:47 PM Jeff Newmiller <jdnewmil at dcn.davis.ca.us> wrote:> > a) When re-posting a question, whether on the same or different forums, it is best practice (netiquette) to link to or reply to the earlier question. [1] > > b) Note the guidance in the Posting Guide: > > For questions about functions in standard packages distributed with R (see the FAQ Add-on packages in R), ask questions on R-help. > If the question relates to a contributed package , e.g., one downloaded from CRAN, try contacting the package maintainer first. You can also use find("functionname") and packageDescription("packagename") to find this information. Only send such questions to R-help or R-devel if you get no reply or need further assistance. This applies to both requests for help and to bug reports. > > You have not communicated whether you have followed this recommendation. > > [1] https://stat.ethz.ch/pipermail/r-help/2018-December/461010.html > > On January 7, 2019 4:26:20 AM PST, Luigi Marongiu <marongiu.luigi at gmail.com> wrote: > >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 > > -- > Sent from my phone. Please excuse my brevity.-- Best regards, Luigi
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-bounces at r-project.org> On Behalf Of Luigi Marongiu > Sent: Monday, January 7, 2019 1:26 PM > To: r-help <r-help at 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 at 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/
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.pikal at 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-bounces at r-project.org> On Behalf Of Luigi Marongiu > > Sent: Monday, January 7, 2019 1:26 PM > > To: r-help <r-help at 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 at 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