Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9193827
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T21:15:30+00:00 2026-06-17T21:15:30+00:00

I have trained a classifier for my instances, and now want to export it

  • 0

I have trained a classifier for my instances, and now want to export it to an Android application, where the Weka library will be unavailable.

It is not suitable to simply add the Weka library in the Android application, because of it’s size (6.5 Mb).

Is there any other way to use my classifier to evaluate and label other unlabeled instances? Are there any smaller, independent library specifically design for this?

Of course I could, eventually, write my own library to interpret the output model of Weka, but it would seem logical to me, that such a solution already exists. (although it escapes me, somehow)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T21:15:31+00:00Added an answer on June 17, 2026 at 9:15 pm

    After paying more attention the output model of weka, I noticed that by using the option that generates the tree in a Java class form, I can use it separatly from the weka library.

    You can remove the generated WekaWrapper and keep only the internal class, which is a basic implementation of the tree:

    The class looks something like this:

    public class WekaWrapper
      extends Classifier {
    
      /**
       * Returns only the toString() method.
       *
       * @return a string describing the classifier
       */
      public String globalInfo() {
        return toString();
      }
    
      /**
       * Returns the capabilities of this classifier.
       *
       * @return the capabilities
       */
      public Capabilities getCapabilities() {
        weka.core.Capabilities result = new weka.core.Capabilities(this);
    
        result.enable(weka.core.Capabilities.Capability.NOMINAL_ATTRIBUTES);
        result.enable(weka.core.Capabilities.Capability.NOMINAL_CLASS);
        result.enable(weka.core.Capabilities.Capability.MISSING_CLASS_VALUES);
    
        result.setMinimumNumberInstances(0);
    
        return result;
      }
    
      /**
       * only checks the data against its capabilities.
       *
       * @param i the training data
       */
      public void buildClassifier(Instances i) throws Exception {
        // can classifier handle the data?
        getCapabilities().testWithFail(i);
      }
    
      /**
       * Classifies the given instance.
       *
       * @param i the instance to classify
       * @return the classification result
       */
      public double classifyInstance(Instance i) throws Exception {
        Object[] s = new Object[i.numAttributes()];
    
        for (int j = 0; j < s.length; j++) {
          if (!i.isMissing(j)) {
            if (i.attribute(j).isNominal())
              s[j] = new String(i.stringValue(j));
            else if (i.attribute(j).isNumeric())
              s[j] = new Double(i.value(j));
          }
        }
    
        // set class value to missing
        s[i.classIndex()] = null;
    
        return WekaClassifier.classify(s);
      }
    
      /**
       * Returns the revision string.
       * 
       * @return        the revision
       */
      public String getRevision() {
        return RevisionUtils.extract("1.0");
      }
    
      /**
       * Returns only the classnames and what classifier it is based on.
       *
       * @return a short description
       */
      public String toString() {
        return "Auto-generated classifier wrapper, based on weka.classifiers.trees.Id3 (generated with Weka 3.6.9).\n" + this.getClass().getName() + "/WekaClassifier";
      }
    
      /**
       * Runs the classfier from commandline.
       *
       * @param args the commandline arguments
       */
      public static void main(String args[]) {
        runClassifier(new WekaWrapper(), args);
      }
    }
    
    class WekaClassifier {
      private static void checkMissing(Object[] i, int index) {
        if (i[index] == null)
          throw new IllegalArgumentException("Null values are not allowed!");
      }
    
      public static double classify(Object[] i) {
        return node0(i);
      }
    
      protected static double node0(Object[] i) {
        return 0.0; // unacc
      }
    }
    

    So, yeah, in fact you can do it really easy. Things to remember:

    • to classify an instance, call the classify(Object[]) method;
    • the return value will be a float value;
    • the return values are explained in comments, right next to the return command;
    • the parameters have no validation, so be careful in which order you are inputing them (this part was done by the weka dependent part);
    • the order is the one defined in the arff file.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a trained j48 classifier and i want to classify one record by
I have a classifier that I trained using Python's scikit-learn. How can I use
Im trying to build a text classifier in JAVA with Weka. I have read
I have trained a NN with Back Propagation algorithm and calculated the MSE. Now
I have a trained and pickled NLTK tagger (Brill's transformational rule-based tagger). I want
I've trained a classifier in Weka, and I'm able to use it on test
I have locally trained a sklearn classifier and I have to create a simple
I have successfully trained a classifier (bayesnet) and constructed a test set (ARFF-format), which
I have trained xor neural network in MATLAB and got these weights: iw: [-2.162
I have a restfull webservice that requires loading trained model files and to create

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.