MCPcopy Create free account
hub / github.com/EdwardRaff/JSAT / write

Method write

JSAT/src/jsat/io/LIBSVMLoader.java:474–494  ·  view source on GitHub ↗

Writes out the given classification data set as a LIBSVM data file @param data the data set to write to a file @param os the output stream to write to. The stream will not be closed or flushed by this method

(ClassificationDataSet data, OutputStream os)

Source from the content-addressed store, hash-verified

472 * flushed by this method
473 */
474 public static void write(ClassificationDataSet data, OutputStream os)
475 {
476 PrintWriter writer = new PrintWriter(os);
477 for(int i = 0; i < data.getSampleSize(); i++)
478 {
479 int pred = data.getDataPointCategory(i);
480 Vec vals = data.getDataPoint(i).getNumericalValues();
481 writer.write(pred + " ");
482 for(IndexValue iv : vals)
483 {
484 double val = iv.getValue();
485 if(Math.rint(val) == val)//cast to long before writting to save space
486 writer.write((iv.getIndex()+1) + ":" + (long)val + " ");//+1 b/c 1 based indexing
487 else
488 writer.write((iv.getIndex()+1) + ":" + val + " ");//+1 b/c 1 based indexing
489 }
490 writer.write("\n");
491 }
492 writer.flush();
493 writer.close();
494 }
495
496 /**
497 * Writes out the given regression data set as a LIBSVM data file

Callers 1

pointToBytesMethod · 0.45

Calls 8

getDataPointCategoryMethod · 0.80
getNumericalValuesMethod · 0.80
closeMethod · 0.80
getTargetValueMethod · 0.80
getSampleSizeMethod · 0.45
getDataPointMethod · 0.45
getValueMethod · 0.45
getIndexMethod · 0.45

Tested by

no test coverage detected