MLR from Java/Groovy code

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

MLR from Java/Groovy code

José Heitor
Hi,

Can anyone point me to Javadoc API and/or examples of how to use MLR
algorithms from Java/Groovy code?

Thanks,
Jose



--
Sent from: https://weka.8497.n7.nabble.com/
_______________________________________________
Wekalist mailing list -- [hidden email]
Send posts to [hidden email]
To unsubscribe send an email to [hidden email]
To subscribe, unsubscribe, etc., visit https://list.waikato.ac.nz/postorius/lists/wekalist.list.waikato.ac.nz
List etiquette: http://www.cs.waikato.ac.nz/~ml/weka/mailinglist_etiquette.html
Reply | Threaded
Open this post in threaded view
|

Re: MLR from Java/Groovy code

Eibe Frank-2
Administrator
There are two steps: (a) use the package manager to load all Java code from all WEKA packages that are installed, including the RPlugin (which obviously needs to be installed first using the package manager), and (b) use reflection to create a classifier object.

Here is an example using xgboost to build the classifier via MLR. You can run this code in WEKA's Groovy console (available via the Tools menu in the GUIChooser), but this should also be valid Java once wrapped into a class.

If xgboost has not yet been installed in R as an R library, there may be some delay while the library gets installed through R in the background.

Cheers,
Eibe

// Load all packages so that MLRClassifier can be found
weka.core.WekaPackageManager.loadPackages(true);

weka.core.Instances instances = new weka.core.Instances(new FileReader("/Applications/weka-3-8-4/data/iris.arff"));
instances.setClassIndex(instances.numAttributes() - 1);
String[] options = weka.core.Utils.splitOptions("-learner classif.xgboost");
myClassifier = weka.classifiers.AbstractClassifier.forName(".MLRClassifier", options);

weka.classifiers.evaluation.Evaluation evaluation = new weka.classifiers.evaluation.Evaluation(instances);
evaluation.crossValidateModel(myClassifier, instances, 10, new Random(1));
System.out.println(evaluation.toSummaryString());
System.out.println(evaluation.toMatrixString());

> On 7/05/2020, at 6:09 AM, José Heitor <[hidden email]> wrote:
>
> Hi,
>
> Can anyone point me to Javadoc API and/or examples of how to use MLR
> algorithms from Java/Groovy code?
>
> Thanks,
> Jose
>
>
>
> --
> Sent from: https://weka.8497.n7.nabble.com/
> _______________________________________________
> Wekalist mailing list -- [hidden email]
> Send posts to [hidden email]
> To unsubscribe send an email to [hidden email]
> To subscribe, unsubscribe, etc., visit https://list.waikato.ac.nz/postorius/lists/wekalist.list.waikato.ac.nz
> List etiquette: http://www.cs.waikato.ac.nz/~ml/weka/mailinglist_etiquette.html
_______________________________________________
Wekalist mailing list -- [hidden email]
Send posts to [hidden email]
To unsubscribe send an email to [hidden email]
To subscribe, unsubscribe, etc., visit https://list.waikato.ac.nz/postorius/lists/wekalist.list.waikato.ac.nz
List etiquette: http://www.cs.waikato.ac.nz/~ml/weka/mailinglist_etiquette.html