Access to the Support Vector Table in One-Class SVM using LibSVM
Hello,
In order to calculate a score, I need the alpha column in the Support Vector Table of the One-Class SVM model. For information, the model was calculated using the LibSVM bloc. Is there a way to extract the example set corresponding to this table ? The idea is to extract this information automatically. I would like to avoid doing it manually.
Kind regards,
Answers
-
Hi keke,
the only way i know to access this is using Execute Script. I think @IngoRM posted something somewhere.. Otherwise we need to rebuilt this.
~Martin
0 -
Hello Martin,
Thanks for your reply.
Is there a way to do it using a Execute Python instead? I don't know java a lot.
Thanks for your help.
Kind regards.
0 -
Hey Keke,
sorry - we need to use javascript (more precise: groovy). The advantage of Javascript is, that we can use the rapidminer java classes. That means we can pass over an SVM Model class and use it. Python would not understand our SVM Model class.
But don't worry - we will build it together . Just need to find some time for some coding.
I guess, we just need to write out the svm_coeff from this class: https://github.com/rapidminer/rapidminer-studio/blob/master/src/main/java/libsvm/svm_model.java so its kind of straight forward
~Martin
0 -
Ok, i quickly built it.
The script below just creates one col with the alphas. It's by the way not the libsvm class but RM's kernel model class which is used.
Best,
Martin
import com.rapidminer.operator.learner.functions.kernel.KernelModel;
import com.rapidminer.tools.Ontology;
// Just in case we want to log stuff in between
import java.util.logging.Level
import com.rapidminer.tools.LogService;
// we can use LogService.root.log(Level.INFO,STRINGVALUE) to see it in RM log window
KernelModel svm = input[0];
Attribute[] attributes= new Attribute[1];
attributes[0] = AttributeFactory.createAttribute("alpha", Ontology.REAL);
MemoryExampleTable table = new MemoryExampleTable(attributes);
DataRowFactory ROW_FACTORY = new DataRowFactory(0);
String[] strings = new String[1];
int supportvectors = svm.getNumberOfSupportVectors()
for(int i = 0; i< supportvectors; ++i){
strings[0] = svm.getAlpha(i).toString();
DataRow row = ROW_FACTORY.create(strings, attributes);
table.addDataRow(row);
}
return table.createExampleSet();;0