How to evaluate weka model from matlab?

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

How to evaluate weka model from matlab?

IAN3125
I am using weka algorithms thru matlab. I am creating a set of training and testing points in matlab then create a set of instances and use a classifier in weka to create a model.

my code looks like:


 javaaddpath('C:\Program Files\MATLAB\R2013a\java\jar\weka.jar');

 import weka.classifiers.functions.*;
 import weka.core.Attribute;
 import weka.core.FastVector;
 import weka.core.Instances;
 import weka.core.DenseInstance;
 import weka.classifiers.functions.SMOreg;
 import weka.classifiers.Evaluation;

 Attribute1=javaObject('weka.core.Attribute','M');
 Attribute2=javaObject('weka.core.Attribute','F');
 Attribute3=javaObject('weka.core.Attribute','w');
 ClassAttribute=javaObject('weka.core.Attribute','Y');

 fvWekaAttribute=javaObject('weka.core.FastVector');
 fvWekaAttribute.addElement(Attribute1);
 fvWekaAttribute.addElement(Attribute2);
 fvWekaAttribute.addElement(Attribute3);
 fvWekaAttribute.addElement(ClassAttribute);

 %create training points
 isTrainingSet=javaObject('weka.core.Instances','Rel',fvWekaAttribute,10);
 isTrainingSet.setClassIndex(3)

 iExample=javaObject('weka.core.DenseInstance',4);
 iExample.setValue(fvWekaAttribute.elementAt(0), 1.0);
 iExample.setValue(fvWekaAttribute.elementAt(1), 0.5);
 iExample.setValue(fvWekaAttribute.elementAt(2), 1.0);
 iExample.setValue(fvWekaAttribute.elementAt(3), 1.0);
 isTrainingSet.add(iExample);

 iExample2=javaObject('weka.core.DenseInstance',4);
 iExample2.setValue(fvWekaAttribute.elementAt(0), 0);
 iExample2.setValue(fvWekaAttribute.elementAt(1), 0.5);
 iExample2.setValue(fvWekaAttribute.elementAt(2), 0);
 iExample2.setValue(fvWekaAttribute.elementAt(3), 0);
 isTrainingSet.add(iExample2);

 iExample3=javaObject('weka.core.DenseInstance',4);
 iExample3.setValue(fvWekaAttribute.elementAt(0), 4);
 iExample3.setValue(fvWekaAttribute.elementAt(1),4);
 iExample3.setValue(fvWekaAttribute.elementAt(2), 4);
 iExample3.setValue(fvWekaAttribute.elementAt(3), 5);
 isTrainingSet.add(iExample3);

 %create testing points points
 isTestingSet=javaObject('weka.core.Instances','Rel',fvWekaAttribute,10);
 isTestingSet.setClassIndex(3)

 iExample=javaObject('weka.core.DenseInstance',4);
 iExample.setValue(fvWekaAttribute.elementAt(0), 1.0);
 iExample.setValue(fvWekaAttribute.elementAt(1), 0.5);
 iExample.setValue(fvWekaAttribute.elementAt(2), 1.0);
 iExample.setValue(fvWekaAttribute.elementAt(3), 1.0);
 isTestingSet.add(iExample);

 iExample2=javaObject('weka.core.DenseInstance',4);
 iExample2.setValue(fvWekaAttribute.elementAt(0), 0);
 iExample2.setValue(fvWekaAttribute.elementAt(1), 0.5);
 iExample2.setValue(fvWekaAttribute.elementAt(2), 0);
 iExample2.setValue(fvWekaAttribute.elementAt(3), 0);
 isTestingSet.add(iExample2);

 iExample3=javaObject('weka.core.DenseInstance',4);
 iExample3.setValue(fvWekaAttribute.elementAt(0), 4);
 iExample3.setValue(fvWekaAttribute.elementAt(1),4);
 iExample3.setValue(fvWekaAttribute.elementAt(2), 4);
 iExample3.setValue(fvWekaAttribute.elementAt(3), 5);
 isTestingSet.add(iExample3);

 cModel = javaObject('weka.classifiers.functions.SMOreg');
 cModel.buildClassifier(isTrainingSet)

 weka.classifiers.Evaluation.evaluateModel(cModel, isTestingSet);`


Now I get an error, 'No method 'evaluateModelOnce' with matching signature found for class 'weka.classifiers.Evaluation'. .

I have zero experience with java, I believe the error is saying that the arguments of the evaluateModel is wrong? if so, How do I evaluate weka model from matlab?
Reply | Threaded
Open this post in threaded view
|

Re: How to evaluate weka model from matlab?

Eibe Frank-2
Administrator
You are almost there! Below, I have appended a version of your program that runs fine for me in Octave, with WEKA 3.8.1. The main difference is that I’m using the non-static evaluateModel() method instead of the static one you tried to use. I have also replaced FastVector (which is deprecated in recent versions of WEKA) by using ArrayList.

Note that the non-static version of the evaluateModel() method I use has a Java varargs argument, which requires the addition of the javaArray("java.lang.Object", 0) parameter in Octave. Without that (useless) parameter, Octave is unable to find the method.

There is some more information on how to use WEKA from Matlab/Octave in the following PDF:

  http://www.cs.waikato.ac.nz/~eibe/WEKA_Ecosystem.pdf

Cheers,
Eibe

javaaddpath('/home/ml/weka-3-8/weka.jar');

Attribute1=javaObject('weka.core.Attribute','M');
Attribute2=javaObject('weka.core.Attribute','F');
Attribute3=javaObject('weka.core.Attribute','w');
ClassAttribute=javaObject('weka.core.Attribute','Y');

fvWekaAttribute=javaObject('java.util.ArrayList');
fvWekaAttribute.add(Attribute1);
fvWekaAttribute.add(Attribute2);
fvWekaAttribute.add(Attribute3);
fvWekaAttribute.add(ClassAttribute);

%create training points
isTrainingSet=javaObject('weka.core.Instances','Rel',fvWekaAttribute,10);
isTrainingSet.setClassIndex(3);

iExample=javaObject('weka.core.DenseInstance', 4);
iExample.setValue(fvWekaAttribute.get(0), 1.0);
iExample.setValue(fvWekaAttribute.get(1), 0.5);
iExample.setValue(fvWekaAttribute.get(2), 1.0);
iExample.setValue(fvWekaAttribute.get(3), 1.0);
isTrainingSet.add(iExample);

iExample2=javaObject('weka.core.DenseInstance', 4);
iExample2.setValue(fvWekaAttribute.get(0), 0);
iExample2.setValue(fvWekaAttribute.get(1), 0.5);
iExample2.setValue(fvWekaAttribute.get(2), 0);
iExample2.setValue(fvWekaAttribute.get(3), 0);
isTrainingSet.add(iExample2);

iExample3=javaObject('weka.core.DenseInstance', 4);
iExample3.setValue(fvWekaAttribute.get(0), 4);
iExample3.setValue(fvWekaAttribute.get(1), 4);
iExample3.setValue(fvWekaAttribute.get(2), 4);
iExample3.setValue(fvWekaAttribute.get(3), 5);
isTrainingSet.add(iExample3);

%create testing points points
isTestingSet=javaObject('weka.core.Instances','Rel',fvWekaAttribute,10);
isTestingSet.setClassIndex(3);

iExample=javaObject('weka.core.DenseInstance', 4);
iExample.setValue(fvWekaAttribute.get(0), 1.0);
iExample.setValue(fvWekaAttribute.get(1), 0.5);
iExample.setValue(fvWekaAttribute.get(2), 1.0);
iExample.setValue(fvWekaAttribute.get(3), 1.0);
isTestingSet.add(iExample);

iExample2=javaObject('weka.core.DenseInstance', 4);
iExample2.setValue(fvWekaAttribute.get(0), 0);
iExample2.setValue(fvWekaAttribute.get(1), 0.5);
iExample2.setValue(fvWekaAttribute.get(2), 0);
iExample2.setValue(fvWekaAttribute.get(3), 0);
isTestingSet.add(iExample2);

iExample3=javaObject('weka.core.DenseInstance', 4);
iExample3.setValue(fvWekaAttribute.get(0), 4);
iExample3.setValue(fvWekaAttribute.get(1), 4);
iExample3.setValue(fvWekaAttribute.get(2), 4);
iExample3.setValue(fvWekaAttribute.get(3), 5);
isTestingSet.add(iExample3);

cModel = javaObject('weka.classifiers.functions.SMOreg');
cModel.buildClassifier(isTrainingSet);
cModel.toString()

e = javaObject("weka.classifiers.evaluation.Evaluation", isTrainingSet);
e.evaluateModel(cModel, isTestingSet, javaArray("java.lang.Object", 0));
e.toSummaryString()


> On 17/02/2017, at 2:05 AM, IAN3125 <[hidden email]> wrote:
>
> I am using weka algorithms thru matlab. I am creating a set of training and
> testing points in matlab then create a set of instances and use a classifier
> in weka to create a model.
>
> my code looks like:
>
>
> javaaddpath('C:\Program Files\MATLAB\R2013a\java\jar\weka.jar');
>
> import weka.classifiers.functions.*;
> import weka.core.Attribute;
> import weka.core.FastVector;
> import weka.core.Instances;
> import weka.core.DenseInstance;
> import weka.classifiers.functions.SMOreg;
> import weka.classifiers.Evaluation;
>
> Attribute1=javaObject('weka.core.Attribute','M');
> Attribute2=javaObject('weka.core.Attribute','F');
> Attribute3=javaObject('weka.core.Attribute','w');
> ClassAttribute=javaObject('weka.core.Attribute','Y');
>
> fvWekaAttribute=javaObject('weka.core.FastVector');
> fvWekaAttribute.addElement(Attribute1);
> fvWekaAttribute.addElement(Attribute2);
> fvWekaAttribute.addElement(Attribute3);
> fvWekaAttribute.addElement(ClassAttribute);
>
> %create training points
> isTrainingSet=javaObject('weka.core.Instances','Rel',fvWekaAttribute,10);
> isTrainingSet.setClassIndex(3)
>
> iExample=javaObject('weka.core.DenseInstance',4);
> iExample.setValue(fvWekaAttribute.elementAt(0), 1.0);
> iExample.setValue(fvWekaAttribute.elementAt(1), 0.5);
> iExample.setValue(fvWekaAttribute.elementAt(2), 1.0);
> iExample.setValue(fvWekaAttribute.elementAt(3), 1.0);
> isTrainingSet.add(iExample);
>
> iExample2=javaObject('weka.core.DenseInstance',4);
> iExample2.setValue(fvWekaAttribute.elementAt(0), 0);
> iExample2.setValue(fvWekaAttribute.elementAt(1), 0.5);
> iExample2.setValue(fvWekaAttribute.elementAt(2), 0);
> iExample2.setValue(fvWekaAttribute.elementAt(3), 0);
> isTrainingSet.add(iExample2);
>
> iExample3=javaObject('weka.core.DenseInstance',4);
> iExample3.setValue(fvWekaAttribute.elementAt(0), 4);
> iExample3.setValue(fvWekaAttribute.elementAt(1),4);
> iExample3.setValue(fvWekaAttribute.elementAt(2), 4);
> iExample3.setValue(fvWekaAttribute.elementAt(3), 5);
> isTrainingSet.add(iExample3);
>
> %create testing points points
> isTestingSet=javaObject('weka.core.Instances','Rel',fvWekaAttribute,10);
> isTestingSet.setClassIndex(3)
>
> iExample=javaObject('weka.core.DenseInstance',4);
> iExample.setValue(fvWekaAttribute.elementAt(0), 1.0);
> iExample.setValue(fvWekaAttribute.elementAt(1), 0.5);
> iExample.setValue(fvWekaAttribute.elementAt(2), 1.0);
> iExample.setValue(fvWekaAttribute.elementAt(3), 1.0);
> isTestingSet.add(iExample);
>
> iExample2=javaObject('weka.core.DenseInstance',4);
> iExample2.setValue(fvWekaAttribute.elementAt(0), 0);
> iExample2.setValue(fvWekaAttribute.elementAt(1), 0.5);
> iExample2.setValue(fvWekaAttribute.elementAt(2), 0);
> iExample2.setValue(fvWekaAttribute.elementAt(3), 0);
> isTestingSet.add(iExample2);
>
> iExample3=javaObject('weka.core.DenseInstance',4);
> iExample3.setValue(fvWekaAttribute.elementAt(0), 4);
> iExample3.setValue(fvWekaAttribute.elementAt(1),4);
> iExample3.setValue(fvWekaAttribute.elementAt(2), 4);
> iExample3.setValue(fvWekaAttribute.elementAt(3), 5);
> isTestingSet.add(iExample3);
>
> cModel = javaObject('weka.classifiers.functions.SMOreg');
> cModel.buildClassifier(isTrainingSet)
>
> weka.classifiers.Evaluation.evaluateModel(cModel, isTestingSet);`
>
>
> Now I get an error, 'No method 'evaluateModelOnce' with matching signature
> found for class 'weka.classifiers.Evaluation'. .
>
> I have zero experience with java, I believe the error is saying that the
> arguments of the evaluateModel is wrong? if so, How do I evaluate weka model
> from matlab?
>
>
>
> --
> View this message in context: http://weka.8497.n7.nabble.com/How-to-evaluate-weka-model-from-matlab-tp39422.html
> Sent from the WEKA mailing list archive at Nabble.com.
> _______________________________________________
> Wekalist mailing list
> Send posts to: [hidden email]
> List info and subscription status: https://list.waikato.ac.nz/mailman/listinfo/wekalist
> List etiquette: http://www.cs.waikato.ac.nz/~ml/weka/mailinglist_etiquette.html

_______________________________________________
Wekalist mailing list
Send posts to: [hidden email]
List info and subscription status: https://list.waikato.ac.nz/mailman/listinfo/wekalist
List etiquette: http://www.cs.waikato.ac.nz/~ml/weka/mailinglist_etiquette.html
Reply | Threaded
Open this post in threaded view
|

Re: How to evaluate weka model from matlab?

IAN3125
Thanks Frank,

Your suggestion works pretty fine except for matlab line:' e.evaluateModel(cModel, isTestingSet, javaArray("java.lang.Object", 0)); ' gets an error so I used 'e.evaluateModel(cModel, isTestingSet, javaArray("java.lang.Object", 1));'.

Now I have already built a weka model, but I am still figuring out how do I get the predicted values using the weka model I made. This is what I have done so far:

clc,format compact,clear all;
javaaddpath('C:\Program Files\MATLAB\R2013a\java\jar\weka.jar');

nRV=3;

data=[...
100 30 2 324;...
55 30 2 279;...
70 30 2 294;...
85 30 2 309;...
115 30 2 339;...
130 30 2 354;...
145 30 2 369;...
100 21 2 180;...
100 24 2 228;...
100 27 2 276;...
100 33 2 372;...
100 36 2 420;...
100 39 2 468;...
100 30 -10 1860;...
100 30 -6 1348;...
100 30 -2 836;...
100 30 6 -188;...
100 30 10 -700;...
100 30 14 -1212];

import weka.classifiers.functions.*;
import weka.core.Attribute.*;
import weka.core.FastVector.*;
import weka.core.Instances.*;
import weka.core.DenseInstance.*;
import weka.classifiers.functions.SMOreg.*;
import weka.classifiers.Evaluation.*;

Attribute1=javaObject('weka.core.Attribute','M');
Attribute2=javaObject('weka.core.Attribute','F');
Attribute3=javaObject('weka.core.Attribute','w');
ClassAttribute=javaObject('weka.core.Attribute','Y');

fvWekaAttribute=javaObject('java.util.ArrayList');
fvWekaAttribute.add(Attribute1);
fvWekaAttribute.add(Attribute2);
fvWekaAttribute.add(Attribute3);
fvWekaAttribute.add(ClassAttribute);

%create training points
isTrainingSet=javaObject('weka.core.Instances','Rel',fvWekaAttribute,nRV*6+1);
isTrainingSet.setClassIndex(3);

for n1=1:nRV*6+1
    iExample(n1)=javaObject('weka.core.DenseInstance', 4);
    iExample(n1).setValue(fvWekaAttribute.get(0), data(n1,1));
    iExample(n1).setValue(fvWekaAttribute.get(1), data(n1,2));
    iExample(n1).setValue(fvWekaAttribute.get(2), data(n1,3));
    iExample(n1).setValue(fvWekaAttribute.get(3), data(n1,4));
    isTrainingSet.add(iExample(n1));
end

%create testing points
isTestingSet=javaObject('weka.core.Instances','Rel',fvWekaAttribute,nRV*6+1);
isTestingSet.setClassIndex(3);

for n1=1:nRV*6+1
    iExample(n1)=javaObject('weka.core.DenseInstance', 4);
    iExample(n1).setValue(fvWekaAttribute.get(0), data(n1,1));
    iExample(n1).setValue(fvWekaAttribute.get(1), data(n1,2));
    iExample(n1).setValue(fvWekaAttribute.get(2), data(n1,3));
    iExample(n1).setValue(fvWekaAttribute.get(3), data(n1,4));
    isTestingSet.add(iExample(n1));
end

cModel = javaObject('weka.classifiers.functions.SMOreg');
cModel.buildClassifier(isTrainingSet);
cModel.toString()

plainText = javaObject('weka.classifiers.evaluation.output.prediction.PlainText');
buffer = javaObject('java.lang.StringBuffer');
plainText.setBuffer(buffer)
bool = javaObject('java.lang.Boolean',true);
range = javaObject('weka.core.Range','1');
array = javaArray('java.lang.Object',3);
array(1) = plainText;
array(2) = range;
array(3) = bool;

e = javaObject('weka.classifiers.evaluation.Evaluation', isTrainingSet);
e.evaluateModel(cModel, isTestingSet, array);

e.toSummaryString()

R=e.correlationCoefficient()
MAE=e.meanAbsoluteError()
RMSE=e.rootMeanSquaredError()
RAE=e.relativeAbsoluteError()
RRSE=e.rootRelativeSquaredError()

This one does not work though, what is the proper way to get the predicted value?
Reply | Threaded
Open this post in threaded view
|

Re: How to evaluate weka model from matlab?

Eibe Frank-2
Administrator
I'd run the data through the model one by one to get the predictions, i.e., use something like this

p = zeros(isTestingSet.numInstances, isTestingSet.numClasses)
for i = 1:isTestingSet.numInstances
  dist = cModel.distributionForInstance(isTestingSet.instance(i - 1))
  for j = 1:isTestingSet.numClasses
    p(i,j) = dist(j)
  end
end

This code should work for both classification and regression. In the case of regression, numClasses will be 1, and distributionForInstance() just returns the predicted target value in a one-dimensional array. In the classification case, distributionForInstance() will return the estimated class probabilities.

This code is adapted from Slide 15 of

  http://www.cs.waikato.ac.nz/~eibe/WEKA_Ecosystem.pdf

Cheers,
Eibe

> On 17 Feb 2017, at 18:35, IAN3125 <[hidden email]> wrote:
>
> Thanks Frank,
>
> Your suggestion works pretty fine except for matlab line:'
> e.evaluateModel(cModel, isTestingSet, javaArray("java.lang.Object", 0)); '
> gets an error so I used 'e.evaluateModel(cModel, isTestingSet,
> javaArray("java.lang.Object", 1));'.
>
> Now I have already built a weka model, but I am still figuring out how do I
> get the predicted values using the weka model I made. This is what I have
> done so far:
>
> clc,format compact,clear all;
> javaaddpath('C:\Program Files\MATLAB\R2013a\java\jar\weka.jar');
>
> nRV=3;
>
> data=[...
> 100 30 2 324;...
> 55 30 2 279;...
> 70 30 2 294;...
> 85 30 2 309;...
> 115 30 2 339;...
> 130 30 2 354;...
> 145 30 2 369;...
> 100 21 2 180;...
> 100 24 2 228;...
> 100 27 2 276;...
> 100 33 2 372;...
> 100 36 2 420;...
> 100 39 2 468;...
> 100 30 -10 1860;...
> 100 30 -6 1348;...
> 100 30 -2 836;...
> 100 30 6 -188;...
> 100 30 10 -700;...
> 100 30 14 -1212];
>
> import weka.classifiers.functions.*;
> import weka.core.Attribute.*;
> import weka.core.FastVector.*;
> import weka.core.Instances.*;
> import weka.core.DenseInstance.*;
> import weka.classifiers.functions.SMOreg.*;
> import weka.classifiers.Evaluation.*;
>
> Attribute1=javaObject('weka.core.Attribute','M');
> Attribute2=javaObject('weka.core.Attribute','F');
> Attribute3=javaObject('weka.core.Attribute','w');
> ClassAttribute=javaObject('weka.core.Attribute','Y');
>
> fvWekaAttribute=javaObject('java.util.ArrayList');
> fvWekaAttribute.add(Attribute1);
> fvWekaAttribute.add(Attribute2);
> fvWekaAttribute.add(Attribute3);
> fvWekaAttribute.add(ClassAttribute);
>
> %create training points
> isTrainingSet=javaObject('weka.core.Instances','Rel',fvWekaAttribute,nRV*6+1);
> isTrainingSet.setClassIndex(3);
>
> for n1=1:nRV*6+1
>    iExample(n1)=javaObject('weka.core.DenseInstance', 4);
>    iExample(n1).setValue(fvWekaAttribute.get(0), data(n1,1));
>    iExample(n1).setValue(fvWekaAttribute.get(1), data(n1,2));
>    iExample(n1).setValue(fvWekaAttribute.get(2), data(n1,3));
>    iExample(n1).setValue(fvWekaAttribute.get(3), data(n1,4));
>    isTrainingSet.add(iExample(n1));
> end
>
> %create testing points
> isTestingSet=javaObject('weka.core.Instances','Rel',fvWekaAttribute,nRV*6+1);
> isTestingSet.setClassIndex(3);
>
> for n1=1:nRV*6+1
>    iExample(n1)=javaObject('weka.core.DenseInstance', 4);
>    iExample(n1).setValue(fvWekaAttribute.get(0), data(n1,1));
>    iExample(n1).setValue(fvWekaAttribute.get(1), data(n1,2));
>    iExample(n1).setValue(fvWekaAttribute.get(2), data(n1,3));
>    iExample(n1).setValue(fvWekaAttribute.get(3), data(n1,4));
>    isTestingSet.add(iExample(n1));
> end
>
> cModel = javaObject('weka.classifiers.functions.SMOreg');
> cModel.buildClassifier(isTrainingSet);
> cModel.toString()
>
> plainText =
> javaObject('weka.classifiers.evaluation.output.prediction.PlainText');
> buffer = javaObject('java.lang.StringBuffer');
> plainText.setBuffer(buffer)
> bool = javaObject('java.lang.Boolean',true);
> range = javaObject('weka.core.Range','1');
> array = javaArray('java.lang.Object',3);
> array(1) = plainText;
> array(2) = range;
> array(3) = bool;
>
> e = javaObject('weka.classifiers.evaluation.Evaluation', isTrainingSet);
> e.evaluateModel(cModel, isTestingSet, array);
>
> e.toSummaryString()
>
> R=e.correlationCoefficient()
> MAE=e.meanAbsoluteError()
> RMSE=e.rootMeanSquaredError()
> RAE=e.relativeAbsoluteError()
> RRSE=e.rootRelativeSquaredError()
>
> This one does not work though, what is the proper way to get the predicted
> value?
>
>
>
>
> --
> View this message in context: http://weka.8497.n7.nabble.com/How-to-evaluate-weka-model-from-matlab-tp39422p39438.html
> Sent from the WEKA mailing list archive at Nabble.com.
> _______________________________________________
> Wekalist mailing list
> Send posts to: [hidden email]
> List info and subscription status: https://list.waikato.ac.nz/mailman/listinfo/wekalist
> List etiquette: http://www.cs.waikato.ac.nz/~ml/weka/mailinglist_etiquette.html

_______________________________________________
Wekalist mailing list
Send posts to: [hidden email]
List info and subscription status: https://list.waikato.ac.nz/mailman/listinfo/wekalist
List etiquette: http://www.cs.waikato.ac.nz/~ml/weka/mailinglist_etiquette.html
Reply | Threaded
Open this post in threaded view
|

Re: How to evaluate weka model from matlab?

IAN3125
Thanks a lot Frank, this forum really helps a lot.

I am using different machine learning techniques by weka to create a response surface to be used for my thesis. this is very helpful. I will now try different regression models in weka and also use meta heuristics algorithms assuming it will increase the accuracy of the prediction.

thanks!!
Reply | Threaded
Open this post in threaded view
|

Re: How to evaluate weka model from matlab?

IAN3125
Hello Frank, sorry for the inconvenience, 

lastly, I want to ask about meta functions weka.

I seem cannot find a way to delete the default classifier 'ZeroR'  for my voting classifier, my code is like:

import weka.classifiers.meta.Vote;
import weka.classifiers.rules.ZeroR;
zeroR=javaObject('weka.classifiers.rules.ZeroR');
metaVModel1=javaObject('weka.classifiers.meta.Vote');
metaVModel1.addPreBuiltClassifier(baseModel1);
metaVModel1.addPreBuiltClassifier(baseModel2);
metaVModel1.removePreBuiltClassifier(zeroR);
metaVModel1.buildClassifier(isTrainingSet);
metaVModel1.toString() 

where baseModel1 and baseModel2 are previously defined modifier.

On Fri, Feb 17, 2017 at 2:15 PM, IAN3125 [via WEKA] <[hidden email]> wrote:
Thanks a lot Frank, this forum really helps a lot.

I am using different machine learning techniques by weka to create a response surface to be used for my thesis. this is very helpful. I will now try different regression models in weka and also use meta heuristics algorithms assuming it will increase the accuracy of the prediction.

thanks!!


If you reply to this email, your message will be added to the discussion below:
http://weka.8497.n7.nabble.com/How-to-evaluate-weka-model-from-matlab-tp39422p39440.html
To unsubscribe from How to evaluate weka model from matlab?, click here.
NAML



--
Nophi Ian D. Biton
Graduate Student (Master's Degree)
Department of Civil and Construction Engineering
National Taiwan University of Science and Technology (Taiwan Tech)  
Mobile: 0965 732 409


Don't limit your challenges, Challenge your limits.
Reply | Threaded
Open this post in threaded view
|

Re: How to evaluate weka model from matlab?

Eibe Frank-2
Administrator
There is no remove() method. You need to set the array of classifiers to be used by Vote to be an empty array of Classifier objects, using the setClassifiers() method of Vote. Here is some code that gives the desired result using Octave (based on the code you sent in an earlier message):

-------

...
aModel = javaObject('weka.classifiers.functions.SMOreg');
aModel.buildClassifier(isTrainingSet);
bModel = javaObject('weka.classifiers.functions.LinearRegression');
bModel.buildClassifier(isTrainingSet);
cModel = javaObject('weka.classifiers.meta.Vote');
cModel.setClassifiers(javaArray("weka.classifiers.Classifier", 0))
cModel.addPreBuiltClassifier(aModel);
cModel.addPreBuiltClassifier(bModel);

cModel.toString()


e = javaObject("weka.classifiers.evaluation.Evaluation", isTrainingSet);
e.evaluateModel(cModel, isTestingSet, javaArray("java.lang.Object", 0));
e.toSummaryString()

--------

Note that normally you'd not actually use addPreBuiltClassifier(), unless you wanted to reuse a classifier that you built earlier. Instead, you can just use setClassifiers() to specify the set of base classifiers to use and then use buildClassifier() in Vote.

BTW: You don't need those import statements if you use fully qualified class names in the rest of the program anyway (e.g., weka.classifiers.meta.Vote instead of just Vote). Octave doesn't even support import statements at the moment it seems.

Cheers,
Eibe

> On 18 Feb 2017, at 05:10, IAN3125 <[hidden email]> wrote:
>
> Hello Frank, sorry for the inconvenience,
>
> lastly, I want to ask about meta functions weka.
>
> I seem cannot find a way to delete the default classifier 'ZeroR'  for my voting classifier, my code is like:
>
> import weka.classifiers.meta.Vote;
> import weka.classifiers.rules.ZeroR;
> zeroR=javaObject('weka.classifiers.rules.ZeroR');
> metaVModel1=javaObject('weka.classifiers.meta.Vote');
> metaVModel1.addPreBuiltClassifier(baseModel1);
> metaVModel1.addPreBuiltClassifier(baseModel2);
> metaVModel1.removePreBuiltClassifier(zeroR);
> metaVModel1.buildClassifier(isTrainingSet);
> metaVModel1.toString()
>
> where baseModel1 and baseModel2 are previously defined modifier.
>
> On Fri, Feb 17, 2017 at 2:15 PM, IAN3125 [via WEKA] <[hidden email]> wrote:
> Thanks a lot Frank, this forum really helps a lot.
>
> I am using different machine learning techniques by weka to create a response surface to be used for my thesis. this is very helpful. I will now try different regression models in weka and also use meta heuristics algorithms assuming it will increase the accuracy of the prediction.
>
> thanks!!
>
> If you reply to this email, your message will be added to the discussion below:
> http://weka.8497.n7.nabble.com/How-to-evaluate-weka-model-from-matlab-tp39422p39440.html
> To unsubscribe from How to evaluate weka model from matlab?, click here.
> NAML
>
>
>
> --
> Nophi Ian D. Biton
> Graduate Student (Master's Degree)
> Department of Civil and Construction Engineering
> National Taiwan University of Science and Technology (Taiwan Tech)  
> Mobile: 0965 732 409
>
> Don't limit your challenges, Challenge your limits.
>
> View this message in context: Re: How to evaluate weka model from matlab?
> Sent from the WEKA mailing list archive at Nabble.com.
> _______________________________________________
> Wekalist mailing list
> Send posts to: [hidden email]
> List info and subscription status: https://list.waikato.ac.nz/mailman/listinfo/wekalist
> List etiquette: http://www.cs.waikato.ac.nz/~ml/weka/mailinglist_etiquette.html

_______________________________________________
Wekalist mailing list
Send posts to: [hidden email]
List info and subscription status: https://list.waikato.ac.nz/mailman/listinfo/wekalist
List etiquette: http://www.cs.waikato.ac.nz/~ml/weka/mailinglist_etiquette.html
Reply | Threaded
Open this post in threaded view
|

Re: How to evaluate weka model from matlab?

IAN3125
This code you suggested seems not working on me. There is an error at line 'metaVModel1.buildClassifier(isTrainingSet); ' as "Java exception occurred: java.lang.NullPointerException"and also another thing is I cannot see the method weka.classifiers.meta.Vote.setClassifiers() in the documentation here: http://weka.sourceforge.net/doc.dev/weka/classifiers/meta/Vote.html#addPreBuiltClassifier-weka.classifiers.Classifier-. this is where is saw the ''.removePreBuiltClassifier' method. 

I made a workaround in this matter, my code looks like:

----
baseModel2 = javaObject('weka.classifiers.functions.SMOreg');
metaVModel1=javaObject('weka.classifiers.meta.Vote');
v1=java.lang.String('-S');
v2=java.lang.String('1');
v3=java.lang.String('-B');
v4=java.lang.String('weka.classifiers.functions.LinearRegression');
options=cat(1,v1,v2,v3,v4);
metaVModel1.setOptions(options);
metaVModel1.addPreBuiltClassifier(baseModel2);
%metaVModel1.removePreBuiltClassifier(zeroR);
metaVModel1.buildClassifier(isTrainingSet);
metaVModel1.toString()
----



On Sat, Feb 18, 2017 at 10:30 AM, Eibe Frank-2 [via WEKA] <[hidden email]> wrote:
There is no remove() method. You need to set the array of classifiers to be used by Vote to be an empty array of Classifier objects, using the setClassifiers() method of Vote. Here is some code that gives the desired result using Octave (based on the code you sent in an earlier message):

-------

...
aModel = javaObject('weka.classifiers.functions.SMOreg');
aModel.buildClassifier(isTrainingSet);
bModel = javaObject('weka.classifiers.functions.LinearRegression');
bModel.buildClassifier(isTrainingSet);
cModel = javaObject('weka.classifiers.meta.Vote');
cModel.setClassifiers(javaArray("weka.classifiers.Classifier", 0))
cModel.addPreBuiltClassifier(aModel);
cModel.addPreBuiltClassifier(bModel);

cModel.toString()


e = javaObject("weka.classifiers.evaluation.Evaluation", isTrainingSet);
e.evaluateModel(cModel, isTestingSet, javaArray("java.lang.Object", 0));
e.toSummaryString()

--------

Note that normally you'd not actually use addPreBuiltClassifier(), unless you wanted to reuse a classifier that you built earlier. Instead, you can just use setClassifiers() to specify the set of base classifiers to use and then use buildClassifier() in Vote.

BTW: You don't need those import statements if you use fully qualified class names in the rest of the program anyway (e.g., weka.classifiers.meta.Vote instead of just Vote). Octave doesn't even support import statements at the moment it seems.

Cheers,
Eibe

> On 18 Feb 2017, at 05:10, IAN3125 <[hidden email]> wrote:
>
> Hello Frank, sorry for the inconvenience,
>
> lastly, I want to ask about meta functions weka.
>
> I seem cannot find a way to delete the default classifier 'ZeroR'  for my voting classifier, my code is like:
>
> import weka.classifiers.meta.Vote;
> import weka.classifiers.rules.ZeroR;
> zeroR=javaObject('weka.classifiers.rules.ZeroR');
> metaVModel1=javaObject('weka.classifiers.meta.Vote');
> metaVModel1.addPreBuiltClassifier(baseModel1);
> metaVModel1.addPreBuiltClassifier(baseModel2);
> metaVModel1.removePreBuiltClassifier(zeroR);
> metaVModel1.buildClassifier(isTrainingSet);
> metaVModel1.toString()
>
> where baseModel1 and baseModel2 are previously defined modifier.
>
> On Fri, Feb 17, 2017 at 2:15 PM, IAN3125 [via WEKA] <[hidden email]> wrote:
> Thanks a lot Frank, this forum really helps a lot.
>
> I am using different machine learning techniques by weka to create a response surface to be used for my thesis. this is very helpful. I will now try different regression models in weka and also use meta heuristics algorithms assuming it will increase the accuracy of the prediction.
>
> thanks!!
>
> If you reply to this email, your message will be added to the discussion below:

> http://weka.8497.n7.nabble.com/How-to-evaluate-weka-model-from-matlab-tp39422p39440.html
> To unsubscribe from How to evaluate weka model from matlab?, click here.
> NAML
>
>
>
> --
> Nophi Ian D. Biton
> Graduate Student (Master's Degree)
> Department of Civil and Construction Engineering
> National Taiwan University of Science and Technology (Taiwan Tech)  
> Mobile: 0965 732 409
>
> Don't limit your challenges, Challenge your limits.
>
> View this message in context: Re: How to evaluate weka model from matlab?
> Sent from the WEKA mailing list archive at Nabble.com.
> _______________________________________________
> Wekalist mailing list
> Send posts to: [hidden email]
> List info and subscription status: https://list.waikato.ac.nz/mailman/listinfo/wekalist
> List etiquette: http://www.cs.waikato.ac.nz/~ml/weka/mailinglist_etiquette.html

_______________________________________________
Wekalist mailing list
Send posts to: [hidden email]
List info and subscription status: https://list.waikato.ac.nz/mailman/listinfo/wekalist
List etiquette: http://www.cs.waikato.ac.nz/~ml/weka/mailinglist_etiquette.html



If you reply to this email, your message will be added to the discussion below:
http://weka.8497.n7.nabble.com/How-to-evaluate-weka-model-from-matlab-tp39422p39447.html
To unsubscribe from How to evaluate weka model from matlab?, click here.
NAML



--
Nophi Ian D. Biton
Graduate Student (Master's Degree)
Department of Civil and Construction Engineering
National Taiwan University of Science and Technology (Taiwan Tech)  
Mobile: 0965 732 409


Don't limit your challenges, Challenge your limits.
Reply | Threaded
Open this post in threaded view
|

Re: How to evaluate weka model from matlab?

Eibe Frank-2
Administrator
The setClassifiers() method is inherited from MultipleClassifiersCombiner, a superclass of Vote.

Sorry, yes, I had missed the removePreBuiltClassifier() method.

Anyway, your code looks fine, but I'd probably just use the -B option multiple times instead of using addPreBuiltClassifier() because baseModel2 isn't really a pre-built classifier in your code (it will be built when metaVModel1 is built using buildClassifier()).

BTW: A more convenient way to configure options is to use the splitOptions() method. Here is an example:

  ...
  aModel = javaObject('weka.classifiers.functions.LinearRegression');
  aModel.setOptions(javaMethod('splitOptions', 'weka.core.Utils', '-C -S 1'));
  aModel.buildClassifier(isTrainingSet);
  ...

This way you can configure a classifier in WEKA's GUIs and then just copy the configuration string into Matlab.

Cheers,
Eibe

> On 18 Feb 2017, at 17:49, IAN3125 <[hidden email]> wrote:
>
> This code you suggested seems not working on me. There is an error at line 'metaVModel1.buildClassifier(isTrainingSet); ' as "Java exception occurred: java.lang.NullPointerException"and also another thing is I cannot see the method weka.classifiers.meta.Vote.setClassifiers() in the documentation here: http://weka.sourceforge.net/doc.dev/weka/classifiers/meta/Vote.html#addPreBuiltClassifier-weka.classifiers.Classifier-. this is where is saw the ''.removePreBuiltClassifier' method.
>
> I made a workaround in this matter, my code looks like:
>
> ----
> baseModel2 = javaObject('weka.classifiers.functions.SMOreg');
> metaVModel1=javaObject('weka.classifiers.meta.Vote');
> v1=java.lang.String('-S');
> v2=java.lang.String('1');
> v3=java.lang.String('-B');
> v4=java.lang.String('weka.classifiers.functions.LinearRegression');
> options=cat(1,v1,v2,v3,v4);
> metaVModel1.setOptions(options);
> metaVModel1.addPreBuiltClassifier(baseModel2);
> %metaVModel1.removePreBuiltClassifier(zeroR);
> metaVModel1.buildClassifier(isTrainingSet);
> metaVModel1.toString()
> ----
>
>
>
> On Sat, Feb 18, 2017 at 10:30 AM, Eibe Frank-2 [via WEKA] <[hidden email]> wrote:
> There is no remove() method. You need to set the array of classifiers to be used by Vote to be an empty array of Classifier objects, using the setClassifiers() method of Vote. Here is some code that gives the desired result using Octave (based on the code you sent in an earlier message):
>
> -------
>
> ...
> aModel = javaObject('weka.classifiers.functions.SMOreg');
> aModel.buildClassifier(isTrainingSet);
> bModel = javaObject('weka.classifiers.functions.LinearRegression');
> bModel.buildClassifier(isTrainingSet);
> cModel = javaObject('weka.classifiers.meta.Vote');
> cModel.setClassifiers(javaArray("weka.classifiers.Classifier", 0))
> cModel.addPreBuiltClassifier(aModel);
> cModel.addPreBuiltClassifier(bModel);
>
> cModel.toString()
>
>
> e = javaObject("weka.classifiers.evaluation.Evaluation", isTrainingSet);
> e.evaluateModel(cModel, isTestingSet, javaArray("java.lang.Object", 0));
> e.toSummaryString()
>
> --------
>
> Note that normally you'd not actually use addPreBuiltClassifier(), unless you wanted to reuse a classifier that you built earlier. Instead, you can just use setClassifiers() to specify the set of base classifiers to use and then use buildClassifier() in Vote.
>
> BTW: You don't need those import statements if you use fully qualified class names in the rest of the program anyway (e.g., weka.classifiers.meta.Vote instead of just Vote). Octave doesn't even support import statements at the moment it seems.
>
> Cheers,
> Eibe
>
> > On 18 Feb 2017, at 05:10, IAN3125 <[hidden email]> wrote:
> >
> > Hello Frank, sorry for the inconvenience,
> >
> > lastly, I want to ask about meta functions weka.
> >
> > I seem cannot find a way to delete the default classifier 'ZeroR'  for my voting classifier, my code is like:
> >
> > import weka.classifiers.meta.Vote;
> > import weka.classifiers.rules.ZeroR;
> > zeroR=javaObject('weka.classifiers.rules.ZeroR');
> > metaVModel1=javaObject('weka.classifiers.meta.Vote');
> > metaVModel1.addPreBuiltClassifier(baseModel1);
> > metaVModel1.addPreBuiltClassifier(baseModel2);
> > metaVModel1.removePreBuiltClassifier(zeroR);
> > metaVModel1.buildClassifier(isTrainingSet);
> > metaVModel1.toString()
> >
> > where baseModel1 and baseModel2 are previously defined modifier.
> >
> > On Fri, Feb 17, 2017 at 2:15 PM, IAN3125 [via WEKA] <[hidden email]> wrote:
> > Thanks a lot Frank, this forum really helps a lot.
> >
> > I am using different machine learning techniques by weka to create a response surface to be used for my thesis. this is very helpful. I will now try different regression models in weka and also use meta heuristics algorithms assuming it will increase the accuracy of the prediction.
> >
> > thanks!!
> >
> > If you reply to this email, your message will be added to the discussion below:
>
> > http://weka.8497.n7.nabble.com/How-to-evaluate-weka-model-from-matlab-tp39422p39440.html
> > To unsubscribe from How to evaluate weka model from matlab?, click here.
> > NAML
> >
> >
> >
> > --
> > Nophi Ian D. Biton
> > Graduate Student (Master's Degree)
> > Department of Civil and Construction Engineering
> > National Taiwan University of Science and Technology (Taiwan Tech)  
> > Mobile: 0965 732 409
> >
> > Don't limit your challenges, Challenge your limits.
> >
> > View this message in context: Re: How to evaluate weka model from matlab?
> > Sent from the WEKA mailing list archive at Nabble.com.
> > _______________________________________________
> > Wekalist mailing list
> > Send posts to: [hidden email]
> > List info and subscription status: https://list.waikato.ac.nz/mailman/listinfo/wekalist
> > List etiquette: http://www.cs.waikato.ac.nz/~ml/weka/mailinglist_etiquette.html
>
> _______________________________________________
> Wekalist mailing list
> Send posts to: [hidden email]
> List info and subscription status: https://list.waikato.ac.nz/mailman/listinfo/wekalist
> List etiquette: http://www.cs.waikato.ac.nz/~ml/weka/mailinglist_etiquette.html
>
>
> If you reply to this email, your message will be added to the discussion below:
> http://weka.8497.n7.nabble.com/How-to-evaluate-weka-model-from-matlab-tp39422p39447.html
> To unsubscribe from How to evaluate weka model from matlab?, click here.
> NAML
>
>
>
> --
> Nophi Ian D. Biton
> Graduate Student (Master's Degree)
> Department of Civil and Construction Engineering
> National Taiwan University of Science and Technology (Taiwan Tech)  
> Mobile: 0965 732 409
>
> Don't limit your challenges, Challenge your limits.
>
> View this message in context: Re: How to evaluate weka model from matlab?
> Sent from the WEKA mailing list archive at Nabble.com.
> _______________________________________________
> Wekalist mailing list
> Send posts to: [hidden email]
> List info and subscription status: https://list.waikato.ac.nz/mailman/listinfo/wekalist
> List etiquette: http://www.cs.waikato.ac.nz/~ml/weka/mailinglist_etiquette.html

_______________________________________________
Wekalist mailing list
Send posts to: [hidden email]
List info and subscription status: https://list.waikato.ac.nz/mailman/listinfo/wekalist
List etiquette: http://www.cs.waikato.ac.nz/~ml/weka/mailinglist_etiquette.html