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 8052651
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T07:35:59+00:00 2026-06-05T07:35:59+00:00

I WEKA, I came across the following code: Instances train = DataSource.read(args[0]); train.setClassIndex(train.numAttributes() –

  • 0

I WEKA, I came across the following code:

Instances train = DataSource.read(args[0]);
train.setClassIndex(train.numAttributes() - 1);
Instances test = DataSource.read(args[1]);
test.setClassIndex(test.numAttributes() - 1);
// train classifier
J48 cls = new J48();
cls.buildClassifier(train);
// output predictions
System.out.println("# - actual - predicted - distribution");
for (int i = 0; i < test.numInstances(); i++) {
    double pred = cls.classifyInstance(test.instance(i));
    double[] dist = cls.distributionForInstance(test.instance(i));
    System.out.print((i+1) + " - ");
    System.out.print(test.instance(i).toString(test.classIndex()) + " - ");
    System.out.print(test.classAttribute().value((int) pred) + " - ");
    System.out.println(Utils.arrayToString(dist));
}

The objective here is to run a pre-built classifier on a test set of data, and then to print the actual class, predicted class and the class membership value distribution.
I understand everything except one line:

System.out.print(test.classAttribute().value((int) pred) + " - ");

If “test” is a group of instances, how will the above statement be able to print the predicted class value for the current instance inside the for loop?

Thanks
Abhishek S

  • 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-05T07:36:01+00:00Added an answer on June 5, 2026 at 7:36 am

    I think that test.classAttribute() gives you all the classes that the test instances could be assigned to. The second part .value((int) pred) then selects the class out of this group which matches to pred, which is the predicted class for the current test instance.

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

Sidebar

Related Questions

I came across the following documentation for HierarchicalClusterer class in WEKA: public void setLinkType(SelectedTag
I'm trying to train a set of ~30,000 instances using an SMO classifier with
Im trying to build a text classifier in JAVA with Weka. I have read
I've just used Weka to train my SVM classifier under Classify tag. Now I
I used the weka to train a J48 classifier,and it returned a textual representation
Hi, I am using weka.classifier.meta. Vote. I am combining three classifiers, one of them
I have downloaded and unzipped the following WEKA version weka-3-4-19. This is on a
I'm building a text classifier in java with Weka library. First i remove stopwords,
so I'm using Weka Machine Learning Library's JAVA API and I have the following
I am an absolute beginner. Never made a classifier or anything in weka using

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.