Skip to content

Commit

Permalink
added incremental example
Browse files Browse the repository at this point in the history
  • Loading branch information
fracpete committed Oct 7, 2024
1 parent d79dd84 commit ed364ed
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

/**
* JustBuild.java
* Copyright (C) 2016 University of Waikato, Hamilton, NZ
/*
* BuildBatch.java
* Copyright (C) 2016-2024 University of Waikato, Hamilton, NZ
*/

package mekaexamples.classifiers;
Expand All @@ -33,9 +33,8 @@
* Note: The dataset must have been prepared for Meka already.
*
* @author FracPete (fracpete at waikato dot ac dot nz)
* @version $Revision$
*/
public class JustBuild {
public class BuildBatch {

public static void main(String[] args) throws Exception {
if (args.length != 1)
Expand All @@ -49,5 +48,6 @@ public static void main(String[] args) throws Exception {
BR classifier = new BR();
// further configuration of classifier
classifier.buildClassifier(data);
System.out.println(classifier.getModel());
}
}
56 changes: 56 additions & 0 deletions src/main/java/mekaexamples/classifiers/BuildIncremental.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

/*
* BuildIncremental.java
* Copyright (C) 2024 University of Waikato, Hamilton, NZ
*/

package mekaexamples.classifiers;

import meka.classifiers.multilabel.incremental.BRUpdateable;
import meka.core.MLUtils;
import weka.core.Instance;
import weka.core.Instances;
import weka.core.converters.ConverterUtils.DataSource;

/**
* Builds a BRUpdateable Meka classifier incrementally on a dataset supplied by the user.
* <br>
* Expected parameters: &lt;dataset&gt;
* <br>
* Note: The dataset must have been prepared for Meka already.
*
* @author FracPete (fracpete at waikato dot ac dot nz)
*/
public class BuildIncremental {

public static void main(String[] args) throws Exception {
if (args.length != 1)
throw new IllegalArgumentException("Required arguments: <dataset>");

System.out.println("Loading data: " + args[0]);
Instances data = DataSource.read(args[0]);
MLUtils.prepareData(data);

System.out.println("Build BRUpdateable classifier");
BRUpdateable classifier = new BRUpdateable();
// further configuration of classifier
classifier.buildClassifier(new Instances(data, 0));
for (Instance inst: data)
classifier.updateClassifier(inst);
System.out.println(classifier.getModel());
}
}

0 comments on commit ed364ed

Please sign in to comment.