write a file but stuck with just the individual rows.

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.
Who is Participating?
CEHJConnect With a Mentor Commented:
Sorry - i don't know this API so can't support it. I can only guess and suggest you try another overridden write method
You need to attach the source for DataSink
willie108Author Commented:
Who wrote the code you posted above?
willie108Author Commented:
It comes from here 17.9.1 Saving data to ¿les
in here http://jaist.dl.sourceforge.net/project/weka/documentation/3.7.x/WekaManual-3-7-7.pdf

and here:

and then using that inputMappedClassifier as a kind of wrapper.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.