Search in sources :

Example 6 with GDBTrainer

use of org.apache.ignite.ml.composition.boosting.GDBTrainer in project ignite by apache.

the class GDBOnTreesRegressionExportImportExample method main.

/**
 * Run example.
 *
 * @param args Command line arguments, none required.
 */
public static void main(String[] args) throws IOException {
    System.out.println();
    System.out.println(">>> GDB regression trainer example started.");
    // Start ignite grid.
    try (Ignite ignite = Ignition.start("examples/config/example-ignite.xml")) {
        System.out.println(">>> Ignite grid started.");
        // Create cache with training data.
        CacheConfiguration<Integer, double[]> trainingSetCfg = createCacheConfiguration();
        IgniteCache<Integer, double[]> trainingSet = null;
        Path jsonMdlPath = null;
        try {
            trainingSet = fillTrainingData(ignite, trainingSetCfg);
            // Create regression trainer.
            GDBTrainer trainer = new GDBRegressionOnTreesTrainer(1.0, 2000, 1, 0.).withCheckConvergenceStgyFactory(new MeanAbsValueConvergenceCheckerFactory(0.001));
            // Train decision tree model.
            GDBModel mdl = trainer.fit(ignite, trainingSet, new DoubleArrayVectorizer<Integer>().labeled(Vectorizer.LabelCoordinate.LAST));
            System.out.println("\n>>> Exported GDB regression model: " + mdl.toString(true));
            predictOnGeneratedData(mdl);
            jsonMdlPath = Files.createTempFile(null, null);
            mdl.toJSON(jsonMdlPath);
            IgniteFunction<Double, Double> lbMapper = lb -> lb;
            GDBModel modelImportedFromJSON = GDBModel.fromJSON(jsonMdlPath).withLblMapping(lbMapper);
            System.out.println("\n>>> Imported GDB regression model: " + modelImportedFromJSON.toString(true));
            predictOnGeneratedData(modelImportedFromJSON);
            System.out.println(">>> GDB regression trainer example completed.");
        } finally {
            if (trainingSet != null)
                trainingSet.destroy();
            if (jsonMdlPath != null)
                Files.deleteIfExists(jsonMdlPath);
        }
    } finally {
        System.out.flush();
    }
}
Also used : Path(java.nio.file.Path) Files(java.nio.file.Files) IgniteFunction(org.apache.ignite.ml.math.functions.IgniteFunction) IOException(java.io.IOException) Ignite(org.apache.ignite.Ignite) IgniteCache(org.apache.ignite.IgniteCache) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) MeanAbsValueConvergenceCheckerFactory(org.apache.ignite.ml.composition.boosting.convergence.mean.MeanAbsValueConvergenceCheckerFactory) GDBTrainer(org.apache.ignite.ml.composition.boosting.GDBTrainer) Ignition(org.apache.ignite.Ignition) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) VectorUtils(org.apache.ignite.ml.math.primitives.vector.VectorUtils) DoubleArrayVectorizer(org.apache.ignite.ml.dataset.feature.extractor.impl.DoubleArrayVectorizer) GDBModel(org.apache.ignite.ml.composition.boosting.GDBModel) GDBRegressionOnTreesTrainer(org.apache.ignite.ml.tree.boosting.GDBRegressionOnTreesTrainer) NotNull(org.jetbrains.annotations.NotNull) Path(java.nio.file.Path) Vectorizer(org.apache.ignite.ml.dataset.feature.extractor.Vectorizer) DoubleArrayVectorizer(org.apache.ignite.ml.dataset.feature.extractor.impl.DoubleArrayVectorizer) GDBRegressionOnTreesTrainer(org.apache.ignite.ml.tree.boosting.GDBRegressionOnTreesTrainer) GDBTrainer(org.apache.ignite.ml.composition.boosting.GDBTrainer) GDBModel(org.apache.ignite.ml.composition.boosting.GDBModel) MeanAbsValueConvergenceCheckerFactory(org.apache.ignite.ml.composition.boosting.convergence.mean.MeanAbsValueConvergenceCheckerFactory) Ignite(org.apache.ignite.Ignite)

Aggregations

Ignite (org.apache.ignite.Ignite)6 GDBTrainer (org.apache.ignite.ml.composition.boosting.GDBTrainer)6 GDBModel (org.apache.ignite.ml.composition.boosting.GDBModel)5 MeanAbsValueConvergenceCheckerFactory (org.apache.ignite.ml.composition.boosting.convergence.mean.MeanAbsValueConvergenceCheckerFactory)4 DoubleArrayVectorizer (org.apache.ignite.ml.dataset.feature.extractor.impl.DoubleArrayVectorizer)4 GDBBinaryClassifierOnTreesTrainer (org.apache.ignite.ml.tree.boosting.GDBBinaryClassifierOnTreesTrainer)4 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 Files (java.nio.file.Files)2 Path (java.nio.file.Path)2 IgniteCache (org.apache.ignite.IgniteCache)2 Ignition (org.apache.ignite.Ignition)2 RendezvousAffinityFunction (org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction)2 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)2 MedianOfMedianConvergenceCheckerFactory (org.apache.ignite.ml.composition.boosting.convergence.median.MedianOfMedianConvergenceCheckerFactory)2 Vectorizer (org.apache.ignite.ml.dataset.feature.extractor.Vectorizer)2 IgniteFunction (org.apache.ignite.ml.math.functions.IgniteFunction)2 VectorUtils (org.apache.ignite.ml.math.primitives.vector.VectorUtils)2 EncoderTrainer (org.apache.ignite.ml.preprocessing.encoding.EncoderTrainer)2 GDBRegressionOnTreesTrainer (org.apache.ignite.ml.tree.boosting.GDBRegressionOnTreesTrainer)2