use of org.apache.ignite.ml.knn.models.KNNModelFormat in project ignite by apache.
the class LocalModelsTest method importExportKNNModelTest.
/**
*/
@Test
public void importExportKNNModelTest() throws IOException {
executeModelTest(mdlFilePath -> {
double[][] mtx = new double[][] { { 1.0, 1.0 }, { 1.0, 2.0 }, { 2.0, 1.0 }, { -1.0, -1.0 }, { -1.0, -2.0 }, { -2.0, -1.0 } };
double[] lbs = new double[] { 1.0, 1.0, 1.0, 2.0, 2.0, 2.0 };
LabeledDataset training = new LabeledDataset(mtx, lbs);
KNNModel mdl = new KNNModel(3, new EuclideanDistance(), KNNStrategy.SIMPLE, training);
Exporter<KNNModelFormat, String> exporter = new FileExporter<>();
mdl.saveModel(exporter, mdlFilePath);
KNNModelFormat load = exporter.load(mdlFilePath);
Assert.assertNotNull(load);
KNNModel importedMdl = new KNNModel(load.getK(), load.getDistanceMeasure(), load.getStgy(), load.getTraining());
Assert.assertTrue("", mdl.equals(importedMdl));
return null;
});
}
Aggregations