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)
| 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 |
no test coverage detected