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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T12:18:57+00:00 2026-06-10T12:18:57+00:00

I trained an IBK classifier with some training data that I created manually as

  • 0

I trained an IBK classifier with some training data that I created manually as following:

ArrayList<Attribute> atts = new ArrayList<Attribute>();
ArrayList<String> classVal = new ArrayList<String>();
classVal.add("C1");
classVal.add("C2");
atts.add(new Attribute("a"));
atts.add(new Attribute("b"));
atts.add(new Attribute("c"));
atts.add(new Attribute("d"));
atts.add(new Attribute("@@class@@", classVal));

Instances dataRaw = new Instances("TestInstances", atts, 0);
dataRaw.setClassIndex(dataRaw.numAttributes() - 1);
double[] instanceValue1 = new double[]{3,0,1,0,0};
dataRaw.add(new DenseInstance(1.0, instanceValue1));

double[] instanceValue2 = new double[]{2,1,1,0,0};
dataRaw.add(new DenseInstance(1.0, instanceValue2));

double[] instanceValue3 = new double[]{2,0,2,0,0};
dataRaw.add(new DenseInstance(1.0, instanceValue3));

double[] instanceValue4 = new double[]{1,3,0,0,1};
dataRaw.add(new DenseInstance(1.0, instanceValue4));

double[] instanceValue5 = new double[]{0,3,1,0,1};
dataRaw.add(new DenseInstance(1.0, instanceValue5));

double[] instanceValue6 = new double[]{0,2,1,1,1};
dataRaw.add(new DenseInstance(1.0, instanceValue6));

Then I build up the classifier:

IBk ibk = new IBk();
try {
    ibk.buildClassifier(dataRaw);

} catch (Exception e) {
    e.printStackTrace();
}

I want to create a new instance with unlabeled class and classify this instance, I tried the following with no luck.

IBk ibk = new IBk();
try {
    ibk.buildClassifier(dataRaw);
    double[] values = new double[]{3,1,0,0,-1};
    DenseInstance newInst = new DenseInstance(1.0,values);
    double classif = ibk.classifyInstance(newInst);
    System.out.println(classif);
} catch (Exception e) {
    e.printStackTrace();
}

I just get the following errors

weka.core.UnassignedDatasetException: DenseInstance doesn't have access to a dataset!
at weka.core.AbstractInstance.classAttribute(AbstractInstance.java:98)
at weka.classifiers.AbstractClassifier.classifyInstance(AbstractClassifier.java:74)
at TextCategorizationTest.instancesWithDoubleValues(TextCategorizationTest.java:136)
at TextCategorizationTest.main(TextCategorizationTest.java:33)

Looks like I am doing something wrong while creating a new instance. How can I create an unlabeled instance exactly ?

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-06-10T12:18:59+00:00Added an answer on June 10, 2026 at 12:18 pm

    The problem is with this line:

    double classif = ibk.classifyInstance(newInst);
    

    When you try to classify newInst, Weka throws an exception because newInst has no Instances object (i.e., dataset) associated with it – thus it does not know anything about its class attribute.

    You should first create a new Instances object similar to the dataRaw, add your unlabeled instance to it, set class index, and only then try classifying it, e.g.:

    Instances dataUnlabeled = new Instances("TestInstances", atts, 0);
    dataUnlabeled.add(newInst);
    dataUnlabeled.setClassIndex(dataUnlabeled.numAttributes() - 1);        
    double classif = ibk.classifyInstance(dataUnlabeled.firstInstance());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any free/open source OCR available that can be trained for new symbols
I have a restfull webservice that requires loading trained model files and to create
I have successfully trained a classifier (bayesnet) and constructed a test set (ARFF-format), which
I always tend to run into the following design problem that I'm never quite
I'm not trained in Linux, but I can muddle through with some doc lookups,
Using kernlab I've trained a model with code like the following: my.model <- ksvm(result
i have a trained j48 classifier and i want to classify one record by
How do I save a trained Naive Bayes classifier to disk and use it
I'm new to java but my experience with Matlab and C trained me to
Python regular expression I have a string that contains keywords but sometimes the keywords

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.