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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:59:48+00:00 2026-05-27T02:59:48+00:00

I want to classify really long lines of texts. Strings. Here is the error

  • 0

I want to classify really long lines of texts. Strings.

Here is the error I am getting:

Exception in thread "main" java.lang.IllegalStateException: No input instance format defined
at weka.filters.unsupervised.attribute.StringToWordVector.input(StringToWordVector.java:681)
at org.berlin.weka.test.TestWeka.main(TestWeka.java:61)

Here is the code but I keep getting exceptions, maybe this is not setup correctly.

package org.berlin.weka.test;

import weka.classifiers.Classifier;
import weka.classifiers.functions.SMO;
import weka.core.Attribute;
import weka.core.FastVector;
import weka.core.Instance;
import weka.core.Instances;
import weka.filters.Filter;
import weka.filters.unsupervised.attribute.StringToWordVector;

public class TestWeka {

    /*
     * java -cp %WEKA_HOME% 
       weka.classifiers.meta.FilteredClassifier 
       -t ReutersAcq-train.arff 
       -T ReutersAcq-test.arff 
       -W "weka.classifiers.functions.SMO -N 2" 
       -F "weka.filters.unsupervised.attribute.StringToWordVector -S"
     */

    public static void main(final String [] args) throws Exception {
        System.out.println("Running");

        final StringToWordVector filter = new StringToWordVector();
        final Classifier classifier = new SMO(); 

        // Create numeric attributes.
        final String[] keywords = { "test1", "test2"};
        FastVector attributes = new FastVector(keywords.length + 1);
        for (int i = 0 ; i < keywords.length; i++) {
          attributes.addElement(new Attribute(keywords[i]));
        }        
        // Add class attribute.
        final FastVector classValues = new FastVector(2);
        classValues.addElement("miss");
        classValues.addElement("hit");

        attributes.addElement(new Attribute("Class", classValues));

        final Instances data = new Instances("Data1", attributes, 100);
        data.setClassIndex(data.numAttributes() - 1);

        ///////////

        Instance instance = new Instance(10);
        instance.setDataset(data);
        // instance.setValue(testset.attribute(0),testset.attribute(0).addStringValue(obj.toString()));
        System.out.println("==>." + data.attribute(0));
        instance.setValue(data.attribute(0), data.attribute(0).addStringValue("test1"));
        instance.setDataset(data);

        // Add class value to instance.
        instance.setClassValue(1.0);

        // Add instance to training data.
        data.add(instance);

        // Use filter.
        filter.input(instance);
        Instances filteredData = Filter.useFilter(data, filter);

        // Rebuild classifier.
        classifier.buildClassifier(filteredData);               
    }

} // End of the class //
  • 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-27T02:59:49+00:00Added an answer on May 27, 2026 at 2:59 am

    Can you try by setting the input format first as following :

    //rest of your code

    // Use filter
    filter.input(instance);
    filter.setInputFormat(data); //data instances that you are going to input to the filter
    Instances filteredData = Filter.useFilter(data, filter);

    For example , you can refer to http://weka.wikispaces.com/Use+WEKA+in+your+Java+code
    and Remove filter. (notice that they set input format of the filter before passing instances to filter)

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

Sidebar

Related Questions

want to rewrite urls like site.com/software to wp-content/themes/dir/software.php and something is not working.. Here's
I want to classify a list of string in Python depending on whether they
For example, I want to classify c*t => CLASS1, and d*g => CLASS2: Pattern
I want to classify a new instance using serialized classifier. I found this class
Let's say I have a person table, and I want it to classify all
I want to use model-based clustering to classify 1,225 time series (24 periods each).
I want to classify documents (composed of words) into 3 classes (Positive, Negative, Unknown/Neutral).
Want to know what the stackoverflow community feels about the various free and non-free
Want my FireFox at work to be in sync with my FireFox at my
want to know why String behaves like value type while using ==. String s1

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.