write a file but stuck with just the individual rows.

Posted on 2012-09-04
Last Modified: 2012-09-28
Hello. I have the code
		//make a copy
		Instances labeled = new Instances(dataTest);
				// label instances
		for (int i = 0; i < dataTest.numInstances(); i++) {
		  Instance mappedInstance = inputMappedClassifier.constructMappedInstance(dataTest.instance(i));
			double clsLabel = inputMappedClassifier.classifyInstance(mappedInstance);
			System.out.println(clsLabel + " -> " + mappedInstance.classAttribute().value((int) clsLabel));
		DataSink.write("C:\\Users\\Bill\\Desktop\\sampleToTestAndTrain\\labeled.csv", mappedInstance);

Open in new window


If I had put labled in the last line instead of mappedInstance like this

DataSink.write("C:\\Users\\Bill\\Desktop\\sampleToTestAndTrain\\labeled.csv", labeled);

Open in new window

it would print to a file called labeled.csv fine.

But since mappedInstance is created inside the loop, I think it represents just one row of data at a time and so even if it could be printed it would probably only be the last line that the loop generated. Actually though it cannot be printed because it is only defined in the loop and I get the error  "cannot find symbol".

Can someone suggest how to get the "accumulated set of all the mappedInstances so that I can print it to a csv file?
Thank you.
Question by:willie108
    LVL 86

    Expert Comment

    You need to attach the source for DataSink

    Author Comment

    LVL 86

    Expert Comment

    Who wrote the code you posted above?

    Author Comment

    It comes from here 17.9.1 Saving data to ¿les
    in here

    and here:

    and then using that inputMappedClassifier as a kind of wrapper.
    LVL 86

    Accepted Solution

    Sorry - i don't know this API so can't support it. I can only guess and suggest you try another overridden write method

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    Suggested Solutions

    Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
    Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
    Video by: Michael
    Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
    Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now