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