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

  • Home
  • SEARCH
  • 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 4608456
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T00:50:51+00:00 2026-05-22T00:50:51+00:00

I want to classify a new instance using serialized classifier. I found this class

  • 0

I want to classify a new instance using serialized classifier. I found this class but I don’t understand it.

arg[2] = class attribute name and arg[3] = 1-based index of an instance to predict from original dataset

Here is the code of this class:

import weka.core.*;
import weka.classifiers.*;

import java.io.*;

/**
 * A little class for testing deserialization and prediction.
 * 
 * @author FracPete (fracpet at waikat dot ac dot nz)
 */
public class Blah {

   /**
    * Takes 4 arguments:
    * <ol>
    *   <li>serialized model</li>
    *   <li>ARFF file</li>
    *   <li>class attribute name</li>
    *   <li>1-based index of an instance to predict from original dataset</li>
    * </ol>
    */
   public static void main(String[] args) throws Exception {
      // read the arff training file
      BufferedReader reader = new BufferedReader(new FileReader(args[1]));
      Instances in = new Instances(reader);
      in.setClass(in.attribute(args[2]));

      // instance to classify
      int index = Integer.parseInt(args[3]) - 1;
      Instance toClassifyInstance = (Instance) in.instance(index).copy();
      toClassifyInstance.setClassValue(Instance.missingValue());

      // deserialize model
      Classifier cls = null;
      ObjectInputStream ois = new ObjectInputStream(new FileInputStream(args[0]));
      cls = (Classifier) ois.readObject();
      ois.close();

      // PREDICTION
      double clsLabel = cls.classifyInstance(toClassifyInstance);
      String classLabel = in.classAttribute().value((int) clsLabel);

      System.out.println(classLabel + " =?= " + in.instance(index).stringValue(in.classIndex()));
   }
}

Thanks in advance.

  • 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-05-22T00:50:52+00:00Added an answer on May 22, 2026 at 12:50 am

    The first parameter, args[0], is the pathname of a serialized classifier that is going to be used for classification. Next parameter is the path of data set which the Instances constructor expects to be in an arff file. This set must have features that are compatible with those in the training data used when creating the serialized classifier (so, the exact same features in the same order). args[2] is the name of the attribute which is the class attribute in the data set from the arff and args[3] is the the index plus one of the instance which will have a copy of itself classified after the value of the class label has been set to missing.

    If you are trying to classify an “external” instance eg. on you have built in some code, the instance still has to have a link to some compatible data set before classifying. This can be done using the method setDataset(Instances) on an instance. There is no compatibility check done, so you might want to check with checkInstance(Instance) on an instances.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to log onto Stack Overflow using OpenID, but I thought I'd set
I want to assign the decimal variable "trans" to the double variable "this.Opacity". decimal
I want to create a Java application bundle for Mac without using Mac. According
I want to reference a COM DLL in a .NET project, but I also
I want to have a List or Array of some sort, storing this information
One simple question (but I haven't quite found an obvious answer in the NLP
I've just used Weka to train my SVM classifier under Classify tag. Now I
I want to use a temp directory that will be unique to this build.
I have a function declared like so: unsigned char** Classifier::classify(){ //... unsigned char **chars
I want to preface this by saying that this is a homework assignment. I

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.