use of org.apache.ignite.ml.tree.DecisionTreeRegressionTrainer in project ignite by apache.
the class DecisionTreeRegressionExportImportExample method main.
/**
* Executes example.
*
* @param args Command line arguments, none required.
*/
public static void main(String... args) throws IOException {
System.out.println(">>> Decision tree regression trainer example started.");
// Start ignite grid.
try (Ignite ignite = Ignition.start("examples/config/example-ignite.xml")) {
System.out.println("\n>>> Ignite grid started.");
// Create cache with training data.
CacheConfiguration<Integer, LabeledVector<Double>> trainingSetCfg = new CacheConfiguration<>();
trainingSetCfg.setName("TRAINING_SET");
trainingSetCfg.setAffinity(new RendezvousAffinityFunction(false, 10));
IgniteCache<Integer, LabeledVector<Double>> trainingSet = null;
Path jsonMdlPath = null;
try {
trainingSet = ignite.createCache(trainingSetCfg);
// Fill training data.
generatePoints(trainingSet);
// Create regression trainer.
DecisionTreeRegressionTrainer trainer = new DecisionTreeRegressionTrainer(10, 0);
// Train decision tree model.
DecisionTreeModel mdl = trainer.fit(ignite, trainingSet, new LabeledDummyVectorizer<>());
System.out.println("\n>>> Exported Decision tree regression model: " + mdl);
jsonMdlPath = Files.createTempFile(null, null);
mdl.toJSON(jsonMdlPath);
DecisionTreeModel modelImportedFromJSON = DecisionTreeModel.fromJSON(jsonMdlPath);
System.out.println("\n>>> Imported Decision tree regression model: " + modelImportedFromJSON);
System.out.println(">>> ---------------------------------");
System.out.println(">>> | Prediction\t| Ground Truth\t|");
System.out.println(">>> ---------------------------------");
// Calculate score.
for (int x = 0; x < 10; x++) {
double predicted = mdl.predict(VectorUtils.of(x));
System.out.printf(">>> | %.4f\t\t| %.4f\t\t|\n", predicted, Math.sin(x));
}
System.out.println(">>> ---------------------------------");
System.out.println("\n>>> Decision tree regression trainer example completed.");
} finally {
if (trainingSet != null)
trainingSet.destroy();
if (jsonMdlPath != null)
Files.deleteIfExists(jsonMdlPath);
}
} finally {
System.out.flush();
}
}
use of org.apache.ignite.ml.tree.DecisionTreeRegressionTrainer in project ignite by apache.
the class DecisionTreeRegressionTrainerExample method main.
/**
* Executes example.
*
* @param args Command line arguments, none required.
*/
public static void main(String... args) {
System.out.println(">>> Decision tree 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, LabeledVector<Double>> trainingSetCfg = new CacheConfiguration<>();
trainingSetCfg.setName("TRAINING_SET");
trainingSetCfg.setAffinity(new RendezvousAffinityFunction(false, 10));
IgniteCache<Integer, LabeledVector<Double>> trainingSet = null;
try {
trainingSet = ignite.createCache(trainingSetCfg);
// Fill training data.
generatePoints(trainingSet);
// Create regression trainer.
DecisionTreeRegressionTrainer trainer = new DecisionTreeRegressionTrainer(10, 0);
// Train decision tree model.
DecisionTreeModel mdl = trainer.fit(ignite, trainingSet, new LabeledDummyVectorizer<>());
System.out.println(">>> Decision tree regression model: " + mdl);
System.out.println(">>> ---------------------------------");
System.out.println(">>> | Prediction\t| Ground Truth\t|");
System.out.println(">>> ---------------------------------");
// Calculate score.
for (int x = 0; x < 10; x++) {
double predicted = mdl.predict(VectorUtils.of(x));
System.out.printf(">>> | %.4f\t\t| %.4f\t\t|\n", predicted, Math.sin(x));
}
System.out.println(">>> ---------------------------------");
System.out.println(">>> Decision tree regression trainer example completed.");
} finally {
trainingSet.destroy();
}
} finally {
System.out.flush();
}
}
use of org.apache.ignite.ml.tree.DecisionTreeRegressionTrainer in project gridgain by gridgain.
the class DecisionTreeRegressionTrainerExample method main.
/**
* Executes example.
*
* @param args Command line arguments, none required.
*/
public static void main(String... args) {
System.out.println(">>> Decision tree regression trainer example started.");
// Start ignite grid.
try (Ignite ignite = Ignition.start("examples-ml/config/example-ignite.xml")) {
System.out.println(">>> Ignite grid started.");
// Create cache with training data.
CacheConfiguration<Integer, LabeledVector<Double>> trainingSetCfg = new CacheConfiguration<>();
trainingSetCfg.setName("TRAINING_SET");
trainingSetCfg.setAffinity(new RendezvousAffinityFunction(false, 10));
IgniteCache<Integer, LabeledVector<Double>> trainingSet = null;
try {
trainingSet = ignite.createCache(trainingSetCfg);
// Fill training data.
generatePoints(trainingSet);
// Create regression trainer.
DecisionTreeRegressionTrainer trainer = new DecisionTreeRegressionTrainer(10, 0);
// Train decision tree model.
DecisionTreeNode mdl = trainer.fit(ignite, trainingSet, new LabeledDummyVectorizer<>());
System.out.println(">>> Decision tree regression model: " + mdl);
System.out.println(">>> ---------------------------------");
System.out.println(">>> | Prediction\t| Ground Truth\t|");
System.out.println(">>> ---------------------------------");
// Calculate score.
for (int x = 0; x < 10; x++) {
double predicted = mdl.predict(VectorUtils.of(x));
System.out.printf(">>> | %.4f\t\t| %.4f\t\t|\n", predicted, Math.sin(x));
}
System.out.println(">>> ---------------------------------");
System.out.println(">>> Decision tree regression trainer example completed.");
} finally {
trainingSet.destroy();
}
} finally {
System.out.flush();
}
}
Aggregations