Skip to content

error in plotting model from kernlab

6 messages · Jeff Newmiller, PIKAL Petr, Luigi Marongiu

#
Dear all,
I have a set of data in this form:
'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):
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:
data = df,
            type = "C-bsvc",
            kernel = "rbfdot",
            kpar = "automatic",
            C = 10,
            prob.model = TRUE)
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:
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:
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
#
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:

  
    
#
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:

  
    
#
Hi

I cannot help you with kernlab
Why not check length of those objects?

length(pred)
length(df$cons)
seems to me selfexplanatory. What did maintainer said about it?

Cheers
Petr
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

As I said I have no experience with kernlab but I can read in manual:

"probabilities matrix of class probabilities (one column for each class and one row for each input)"

from which I understand that  pred is matrix, which should have the same number of rows as df$cons but several columns. And matrix is a vector with dimensions what means that it is column times longer than df$cons, hence it is longer than df$cons.

Plotting error suggeststs that ksvc object has to be classification object and
is not the same as "C-svc".

Cheers
Petr
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/