How to set parameter of SMO?
IngoRM
New Altair Community Member
Original message from SourceForge forum at http://sourceforge.net/forum/forum.php?thread_id=2038567&;forum_id=390413
I want to use SMO to get well-calibrated probability
I call the "setparameter" method in my program,but the output's probability is still equal to 0 or 1, i.e. it doesn't work.(I call the method getParameter("M"), the result is "true"! , not default value "false")
But I run SMO by GUI, I can set parameter to get well-calibrated probability
I also try to set others parameters of SMO or other Weka algorithm. it is also invalid. But I can set parameter in non-weka algorithm, it's valid
Someone please help me...
My Java Code:
//build model
Operator SMOOperator = OperatorService.createOperator("W-SMO");
SMOOperator.setParameter("M", "true");
Learner learner = (Learner) SMOOperator;
Model model = learner.learn(trainingset);
// apply model
IOContainer testingSetContainer = testingSetContainer.append(model);
Operator modelApp = OperatorService.createOperator(ModelApplier.class);
testingSetContainer = modelApp.apply(testingSetContainer);
// print results
ExampleSet resultSet = resultSetContainer.get(ExampleSet.class);
ExampleTable tableReader = resultSet.getExampleTable();
DataRowReader rowReader = tableReader.getDataRowReader();
DataRow row;
Attribute aid = resultSet.getAttributes().getId();
Attribute apl = resultSet.getAttributes().getPredictedLabel();
Attribute al = resultSet.getAttributes().getLabel();
Attribute ac = resultSet.getAttributes().get("confidence(1)");
while(rowReader.hasNext())
{
row=(DataRow)rowReader.next();
System.out.println("id = "+row.get(aid)+" label = "+row.get(al)+" prediction = "+row.get(apl)+" confidence = "+row.get(ac));
}
Result:
id = 685.0 label = 0.0 prediction = 0.0 confidence = 0.0
id = 701.0 label = 0.0 prediction = 0.0 confidence = 0.0
id = 697.0 label = 0.0 prediction = 0.0 confidence = 0.0
.........................................................
Answer by Harri:
In SMO, you have to set the logistic parameter (I forget exact name but there is only one) 'true' to get true probabilities.
Harri
Answer by topic starter:
I have been checked the tutorial.
In SMO, the description of parameter "M" is
M: Fit logistic models to SVM outputs. (boolean; default: false)
I am sure that I set the "correct" parameter, correct parameter name and correct value
(if I type wrong name ex. "m"(lowercase) or wrong value ex. "trrue" then the error information will print out)
Why I set "M" parameter in RapidMiner GUI is work, but in java code is wrong?
I also try to set other parameter value randomly, such as
C: The complexity constant C. (default 1) (real; -1-+1)
L: The tolerance parameter. (default 1.0e-3) (real; -1-+1)
My accuracy is not change. it seems that I can only use default setting
This problem also exist in Weka learning algorithm "W-MultilayerPerceptron",
but not exist in RapidMiner learning algorithm "DecisionTree"
this problem is very confused.
Answer by Ingo Mierswa:
Hello,
does it also apply if you use
Model model = SMOOperator.apply(new IOContainer(trainingset)).getInput(Model.class);
instead of
Learner learner = (Learner) SMOOperator;
Model model = learner.learn(trainingset);
Probably the parameters are not given to the Weka operators in the learn(...) method.
Cheers,
Ingo
Answer by topic starter:
Hello,
the line of code will occur compile error...
Model model = SMOOperator.apply(new IOContainer(trainingset)).getInput(Model.class);
In IOContainer class, getInput() method is not exist
I try to revise these code like this...
Operator SMOOperator = OperatorService.createOperator("W-SMO");
SMOOperator.setParameter("M", "true");
try {
Model model = SMOOperator.apply(trainingSetIOContainer).get(Model.class);
} catch (OperatorException e1) {
e1.printStackTrace();
}
But the parameter value which I set is also invalid, the problem still exist in Weka learning algorithm
Do someone know other way to set parameter value for weka operator?
Answer by Ingo Mierswa:
Ok, I found the reason: since all Weka operators are dynamically created the parameters are not initialized directly after operator creation and you have to do this manually. Just use the following lines
Operator smoOperator = OperatorService.createOperator("W-SMO");
smoOperator.getParameterTypes(); // <-- this is the important workaround
smoOperator.setParameter("M", "true");
for operator creation and parameter setting and it will work. I will also add a fix to the CVS version of RapidMiner so that you will not have to invoke "getParameterTypes()" for the Weka operators for future versions of RapidMiner.
Hope that helps. Cheers,
Ingo
I want to use SMO to get well-calibrated probability
I call the "setparameter" method in my program,but the output's probability is still equal to 0 or 1, i.e. it doesn't work.(I call the method getParameter("M"), the result is "true"! , not default value "false")
But I run SMO by GUI, I can set parameter to get well-calibrated probability
I also try to set others parameters of SMO or other Weka algorithm. it is also invalid. But I can set parameter in non-weka algorithm, it's valid
Someone please help me...
My Java Code:
//build model
Operator SMOOperator = OperatorService.createOperator("W-SMO");
SMOOperator.setParameter("M", "true");
Learner learner = (Learner) SMOOperator;
Model model = learner.learn(trainingset);
// apply model
IOContainer testingSetContainer = testingSetContainer.append(model);
Operator modelApp = OperatorService.createOperator(ModelApplier.class);
testingSetContainer = modelApp.apply(testingSetContainer);
// print results
ExampleSet resultSet = resultSetContainer.get(ExampleSet.class);
ExampleTable tableReader = resultSet.getExampleTable();
DataRowReader rowReader = tableReader.getDataRowReader();
DataRow row;
Attribute aid = resultSet.getAttributes().getId();
Attribute apl = resultSet.getAttributes().getPredictedLabel();
Attribute al = resultSet.getAttributes().getLabel();
Attribute ac = resultSet.getAttributes().get("confidence(1)");
while(rowReader.hasNext())
{
row=(DataRow)rowReader.next();
System.out.println("id = "+row.get(aid)+" label = "+row.get(al)+" prediction = "+row.get(apl)+" confidence = "+row.get(ac));
}
Result:
id = 685.0 label = 0.0 prediction = 0.0 confidence = 0.0
id = 701.0 label = 0.0 prediction = 0.0 confidence = 0.0
id = 697.0 label = 0.0 prediction = 0.0 confidence = 0.0
.........................................................
Answer by Harri:
In SMO, you have to set the logistic parameter (I forget exact name but there is only one) 'true' to get true probabilities.
Harri
Answer by topic starter:
I have been checked the tutorial.
In SMO, the description of parameter "M" is
M: Fit logistic models to SVM outputs. (boolean; default: false)
I am sure that I set the "correct" parameter, correct parameter name and correct value
(if I type wrong name ex. "m"(lowercase) or wrong value ex. "trrue" then the error information will print out)
Why I set "M" parameter in RapidMiner GUI is work, but in java code is wrong?
I also try to set other parameter value randomly, such as
C: The complexity constant C. (default 1) (real; -1-+1)
L: The tolerance parameter. (default 1.0e-3) (real; -1-+1)
My accuracy is not change. it seems that I can only use default setting
This problem also exist in Weka learning algorithm "W-MultilayerPerceptron",
but not exist in RapidMiner learning algorithm "DecisionTree"
this problem is very confused.
Answer by Ingo Mierswa:
Hello,
does it also apply if you use
Model model = SMOOperator.apply(new IOContainer(trainingset)).getInput(Model.class);
instead of
Learner learner = (Learner) SMOOperator;
Model model = learner.learn(trainingset);
Probably the parameters are not given to the Weka operators in the learn(...) method.
Cheers,
Ingo
Answer by topic starter:
Hello,
the line of code will occur compile error...
Model model = SMOOperator.apply(new IOContainer(trainingset)).getInput(Model.class);
In IOContainer class, getInput() method is not exist
I try to revise these code like this...
Operator SMOOperator = OperatorService.createOperator("W-SMO");
SMOOperator.setParameter("M", "true");
try {
Model model = SMOOperator.apply(trainingSetIOContainer).get(Model.class);
} catch (OperatorException e1) {
e1.printStackTrace();
}
But the parameter value which I set is also invalid, the problem still exist in Weka learning algorithm
Do someone know other way to set parameter value for weka operator?
Answer by Ingo Mierswa:
Ok, I found the reason: since all Weka operators are dynamically created the parameters are not initialized directly after operator creation and you have to do this manually. Just use the following lines
Operator smoOperator = OperatorService.createOperator("W-SMO");
smoOperator.getParameterTypes(); // <-- this is the important workaround
smoOperator.setParameter("M", "true");
for operator creation and parameter setting and it will work. I will also add a fix to the CVS version of RapidMiner so that you will not have to invoke "getParameterTypes()" for the Weka operators for future versions of RapidMiner.
Hope that helps. Cheers,
Ingo
Tagged:
0