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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T03:38:11+00:00 2026-05-25T03:38:11+00:00

We are trying to implement a WEKA classifier from inside a Java program. So

  • 0

We are trying to implement a WEKA classifier from inside a Java program. So far so good, everything works well however when building the classifier from the training set in Weka GUI we used the StringToWordVector IDF transform to help improve classification accuracy.

How, from within Java for new instances do I calculate the IDF transform to set for each token value in the new instance before passing the instance to the classifier?

The basic code looks like this:

Instances ins = vectorize(msg);
Instances unlabeled = new Instances(train,1);
Instance inst = new Instance(unlabeled.numAttributes());

String tmp = "";

for(int i=0; i < ins.numAttributes(); i++) {
    tmp = ins.attribute(i).name();
    if(unlabeled.attribute(tmp)!=null)
      inst.setValue(unlabeled.attribute(tmp), 1.0); //TODO: Need to figure out the IDF transformed value to put here NOT 1!!
}

unlabeled.add(inst);

unlabeled.setClassIndex(classIdx);

.....cl.distributionForInstance(unlabeled.instance(i));

So how do I go about coding this so that I put the correct value in the new instance I want to classify?

Just to be clear the line inst.setValue(unlabeled.attribute(tmp), 1.0); needs to be changed from 1.0 to the IDF transformed number…

  • 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-25T03:38:12+00:00Added an answer on May 25, 2026 at 3:38 am

    You need to use FilteredClassifier for this purpose. The code snippet is :

    
        StringToWordVector  strWVector = new StringToWordVector();   
        filteredClassifier fcls = new FilteredClassifier();
        fcls.setFilter(strWVector);
        fcls.setClassifier(new SMO());
        fcls.buildClassifier(yourdata)
         //rest of your code 
    
    
    

    This is much easier as you can pass your instances all at once.FilteredClassifier takes care of all other details. The code is not tested but it will get you started.

    Edit : You can do in the following way too. This is code snippet from weka tutorial See http://weka.wikispaces.com/Use+WEKA+in+your+Java+code#Filter-Filtering%20on-the-fly Batch Mode for details

    
    Instances train = ...   // from somewhere
     Instances test = ...    // from somewhere
     Standardize filter = new Standardize();
     filter.setInputFormat(train);  // initializing the filter once with training set
     Instances newTrain = Filter.useFilter(train, filter);  // configures the Filter based on train instances and returns filtered instances
     Instances newTest = Filter.useFilter(test, filter);    // create new test se
    
    

    HTH

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

Sidebar

Related Questions

Am trying to implement a Java program which sends an Apple Push Notification to
Am trying to implement a generic way for reading sections from a config file.
Ok well I'm trying implement something similar to the 'undo' function in many image
Trying to implement some nested loops that are spitting out good old nested html
Im trying to implement something given to me however I've come across an error
I am trying implement Unblock me Puzzle. i want to change image position from
I've a webbrowser control and I'm trying implement IDocHostUIHandler in the container. However since
Trying to implement the following structure from c to use NSArray in objective-c: In
I'm trying implement a bracket in my program (using C#/.NET MVC) and I am
trying to implement a multiplayer. Using the sample from Game Center - Sending and

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.