Search in sources :

Example 1 with KNNModelFormat

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;
    });
}
Also used : EuclideanDistance(org.apache.ignite.ml.math.distances.EuclideanDistance) KNNModelFormat(org.apache.ignite.ml.knn.models.KNNModelFormat) KNNModel(org.apache.ignite.ml.knn.models.KNNModel) LabeledDataset(org.apache.ignite.ml.structures.LabeledDataset) Test(org.junit.Test)

Aggregations

KNNModel (org.apache.ignite.ml.knn.models.KNNModel)1 KNNModelFormat (org.apache.ignite.ml.knn.models.KNNModelFormat)1 EuclideanDistance (org.apache.ignite.ml.math.distances.EuclideanDistance)1 LabeledDataset (org.apache.ignite.ml.structures.LabeledDataset)1 Test (org.junit.Test)1