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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T14:52:52+00:00 2026-06-02T14:52:52+00:00

Below is a program that shows how strings are output incorrectly if the ARFF

  • 0

Below is a program that shows how strings are output incorrectly if the ARFF saver from weka is writing in incremental mode. The program below runs in incremental mode if a parameter is passed to the program and in batch mode if no parameter is passed.

Note that in batch mode, the ARFF file contains strings … normal operation.
In incremental mode, the ARFF file contains integers in place of strings … strange !

Any ideas on how to get the ARFF formater to output strings in incremental format?

import java.io.File;
import java.io.IOException;

import weka.core.Attribute;
import weka.core.FastVector;
import weka.core.Instance;
import weka.core.Instances;
import weka.core.converters.ArffSaver;
import weka.core.converters.Saver;

public class ArffTest {
    static Instances instances; 
    static ArffSaver saver;
    static boolean flag=false;

    public static void addData(String ticker, double price) throws IOException{
        int numAttr = instances.numAttributes(); // same for
        double[] vals = new double[numAttr]; 
        int i=0;
        vals[i++] = instances.attribute(0).addStringValue(ticker);
        vals[i++] = price;
        Instance instance = new Instance(1.0, vals);
        if (flag)
            saver.writeIncremental(instance);
        else
            instances.add(instance);
    }

    public static void main(String[] args) {
        if(args.length>0){
            flag=true;
        }
        FastVector atts = new FastVector();         // attributes
        atts.addElement(new Attribute("Ticker", (FastVector)null));// symbol
        atts.addElement(new Attribute("Price"));    // price that order exited at.

        instances = new Instances("Samples", atts, 0);  // create header
        saver = new ArffSaver();
        saver.setInstances(instances);
        if(flag)
            saver.setRetrieval(Saver.INCREMENTAL);

        try{
            saver.setFile(new File("test.arff"));
            addData("YY", 23.0);
            addData("XY", 24.0);
            addData("XX", 29.0);
            if(flag)
                saver.writeIncremental(null);
            else
                saver.writeBatch();
        }catch(Exception e){
            System.out.println("Exception");
        }
    }
}
  • 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-02T14:52:55+00:00Added an answer on June 2, 2026 at 2:52 pm

    You forgot to add the newly created Instance to the dataset.

    Instance instance = new DenseInstance(1.0, vals);
    instance.setDataset(instances); //Add instance!
    if (flag)
       saver.writeIncremental(instance);
    else
       instances.add(instance);
    

    The Instance must have access to the dataset to retrieve the String
    attribute. If it doesn’t it just writes out the index.

    Besides that I recommend to use Weka 3.7.6. Instance is now an
    interface with two implementations.

    cheers,
    Muki

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

Sidebar

Related Questions

Below is the program that I wrote. /******************************************************************************* * This program reads EOF from
I have a favorite C# program similar to the one below that shows that
Below I have written a sample program that I have written to learn about
I need to create program that creates a XML schema like below using System.Xml.XmlSchema
below i have a code that runs in most of my simple programs ..
Down below is my incomplete program. I am having problems with writing to a
So I am making a program that emails a list of users from a
The code below shows a sample that I've used recently to explain the different
My program is receiving an integer array from a browser application that's interpreted as
I have an onCreate method that runs the code below. In a nutshell the

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.