• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 295
  • Last Modified:

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);
			mappedInstance.setClassValue(clsLabel);
			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.
0
willie108
Asked:
willie108
  • 3
  • 2
1 Solution
 
CEHJCommented:
You need to attach the source for DataSink
0
 
willie108Author Commented:
0
 
CEHJCommented:
Who wrote the code you posted above?
0
 
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:
http://weka.wikispaces.com/Use+WEKA+in+your+Java+code

and then using that inputMappedClassifier as a kind of wrapper.
0
 
CEHJCommented:
Sorry - i don't know this API so can't support it. I can only guess and suggest you try another overridden write method
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now