Search in sources :

Example 1 with FileExporter

use of org.apache.ignite.ml.FileExporter in project ignite by apache.

the class LocalModelsTest method importExportLinearRegressionModelTest.

/**
 */
@Test
public void importExportLinearRegressionModelTest() throws IOException {
    executeModelTest(mdlFilePath -> {
        LinearRegressionModel mdl = new LinearRegressionModel(new DenseVector(new double[] { 1, 2 }), 3);
        Exporter<LinearRegressionModel, String> exporter = new FileExporter<>();
        mdl.saveModel(exporter, mdlFilePath);
        LinearRegressionModel load = exporter.load(mdlFilePath);
        Assert.assertNotNull(load);
        Assert.assertEquals("", mdl, load);
        return null;
    });
}
Also used : LinearRegressionModel(org.apache.ignite.ml.regressions.linear.LinearRegressionModel) FileExporter(org.apache.ignite.ml.FileExporter) DenseVector(org.apache.ignite.ml.math.primitives.vector.impl.DenseVector) Test(org.junit.Test)

Example 2 with FileExporter

use of org.apache.ignite.ml.FileExporter in project ignite by apache.

the class LocalModelsTest method importExportLogisticRegressionModelTest.

/**
 */
@Test
public void importExportLogisticRegressionModelTest() throws IOException {
    executeModelTest(mdlFilePath -> {
        LogisticRegressionModel mdl = new LogisticRegressionModel(new DenseVector(new double[] { 1, 2 }), 3);
        Exporter<LogisticRegressionModel, String> exporter = new FileExporter<>();
        mdl.saveModel(exporter, mdlFilePath);
        LogisticRegressionModel load = exporter.load(mdlFilePath);
        Assert.assertNotNull(load);
        Assert.assertEquals("", mdl, load);
        return null;
    });
}
Also used : FileExporter(org.apache.ignite.ml.FileExporter) LogisticRegressionModel(org.apache.ignite.ml.regressions.logistic.LogisticRegressionModel) DenseVector(org.apache.ignite.ml.math.primitives.vector.impl.DenseVector) Test(org.junit.Test)

Example 3 with FileExporter

use of org.apache.ignite.ml.FileExporter in project ignite by apache.

the class LocalModelsTest method importExportSVMBinaryClassificationModelTest.

/**
 */
@Test
public void importExportSVMBinaryClassificationModelTest() throws IOException {
    executeModelTest(mdlFilePath -> {
        SVMLinearClassificationModel mdl = new SVMLinearClassificationModel(new DenseVector(new double[] { 1, 2 }), 3);
        Exporter<SVMLinearClassificationModel, String> exporter = new FileExporter<>();
        mdl.saveModel(exporter, mdlFilePath);
        SVMLinearClassificationModel load = exporter.load(mdlFilePath);
        Assert.assertNotNull(load);
        Assert.assertEquals("", mdl, load);
        return null;
    });
}
Also used : FileExporter(org.apache.ignite.ml.FileExporter) SVMLinearClassificationModel(org.apache.ignite.ml.svm.SVMLinearClassificationModel) DenseVector(org.apache.ignite.ml.math.primitives.vector.impl.DenseVector) Test(org.junit.Test)

Example 4 with FileExporter

use of org.apache.ignite.ml.FileExporter in project ignite by apache.

the class LocalModelsTest method importExportANNModelTest.

/**
 */
@Test
public void importExportANNModelTest() throws IOException {
    executeModelTest(mdlFilePath -> {
        final LabeledVectorSet<LabeledVector> centers = new LabeledVectorSet<>();
        NNClassificationModel mdl = new ANNClassificationModel(centers, new ANNClassificationTrainer.CentroidStat()).withK(4).withDistanceMeasure(new ManhattanDistance()).withWeighted(true);
        Exporter<KNNModelFormat, String> exporter = new FileExporter<>();
        mdl.saveModel(exporter, mdlFilePath);
        ANNModelFormat load = (ANNModelFormat) exporter.load(mdlFilePath);
        Assert.assertNotNull(load);
        NNClassificationModel importedMdl = new ANNClassificationModel(load.getCandidates(), new ANNClassificationTrainer.CentroidStat()).withK(load.getK()).withDistanceMeasure(load.getDistanceMeasure()).withWeighted(true);
        Assert.assertEquals("", mdl, importedMdl);
        return null;
    });
}
Also used : ANNClassificationModel(org.apache.ignite.ml.knn.ann.ANNClassificationModel) NNClassificationModel(org.apache.ignite.ml.knn.NNClassificationModel) FileExporter(org.apache.ignite.ml.FileExporter) KNNModelFormat(org.apache.ignite.ml.knn.ann.KNNModelFormat) LabeledVector(org.apache.ignite.ml.structures.LabeledVector) ANNClassificationModel(org.apache.ignite.ml.knn.ann.ANNClassificationModel) ANNModelFormat(org.apache.ignite.ml.knn.ann.ANNModelFormat) LabeledVectorSet(org.apache.ignite.ml.structures.LabeledVectorSet) ManhattanDistance(org.apache.ignite.ml.math.distances.ManhattanDistance) Test(org.junit.Test)

Example 5 with FileExporter

use of org.apache.ignite.ml.FileExporter in project ignite by apache.

the class LocalModelsTest method importExportKMeansModelTest.

/**
 */
@Test
public void importExportKMeansModelTest() throws IOException {
    executeModelTest(mdlFilePath -> {
        KMeansModel mdl = getClusterModel();
        Exporter<KMeansModelFormat, String> exporter = new FileExporter<>();
        mdl.saveModel(exporter, mdlFilePath);
        KMeansModelFormat load = exporter.load(mdlFilePath);
        Assert.assertNotNull(load);
        KMeansModel importedMdl = new KMeansModel(load.getCenters(), load.getDistance());
        Assert.assertEquals("", mdl, importedMdl);
        return null;
    });
}
Also used : KMeansModel(org.apache.ignite.ml.clustering.kmeans.KMeansModel) FileExporter(org.apache.ignite.ml.FileExporter) KMeansModelFormat(org.apache.ignite.ml.clustering.kmeans.KMeansModelFormat) Test(org.junit.Test)

Aggregations

FileExporter (org.apache.ignite.ml.FileExporter)5 Test (org.junit.Test)5 DenseVector (org.apache.ignite.ml.math.primitives.vector.impl.DenseVector)3 KMeansModel (org.apache.ignite.ml.clustering.kmeans.KMeansModel)1 KMeansModelFormat (org.apache.ignite.ml.clustering.kmeans.KMeansModelFormat)1 NNClassificationModel (org.apache.ignite.ml.knn.NNClassificationModel)1 ANNClassificationModel (org.apache.ignite.ml.knn.ann.ANNClassificationModel)1 ANNModelFormat (org.apache.ignite.ml.knn.ann.ANNModelFormat)1 KNNModelFormat (org.apache.ignite.ml.knn.ann.KNNModelFormat)1 ManhattanDistance (org.apache.ignite.ml.math.distances.ManhattanDistance)1 LinearRegressionModel (org.apache.ignite.ml.regressions.linear.LinearRegressionModel)1 LogisticRegressionModel (org.apache.ignite.ml.regressions.logistic.LogisticRegressionModel)1 LabeledVector (org.apache.ignite.ml.structures.LabeledVector)1 LabeledVectorSet (org.apache.ignite.ml.structures.LabeledVectorSet)1 SVMLinearClassificationModel (org.apache.ignite.ml.svm.SVMLinearClassificationModel)1