You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by za...@apache.org on 2019/09/18 07:59:06 UTC
[ignite] branch master updated: IGNITE-12155: [ML] Implementation
of distributed estimator (#6857)
This is an automated email from the ASF dual-hosted git repository.
zaleslaw pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ignite.git
The following commit(s) were added to refs/heads/master by this push:
new 5cf2a2e IGNITE-12155: [ML] Implementation of distributed estimator (#6857)
5cf2a2e is described below
commit 5cf2a2e362c8ef803282b31f9a67c6d0510b1730
Author: Alexey Platonov <40...@users.noreply.github.com>
AuthorDate: Wed Sep 18 10:58:54 2019 +0300
IGNITE-12155: [ML] Implementation of distributed estimator (#6857)
---
.../ml/TrainingWithBinaryObjectExample.java | 14 +-
.../clustering/CustomersClusterizationExample.java | 29 +-
.../ml/clustering/GmmClusterizationExample.java | 8 +-
.../ml/clustering/KMeansClusterizationExample.java | 14 +-
.../examples/ml/clustering/package-info.java | 3 +-
.../dataset/AlgorithmSpecificDatasetExample.java | 52 +-
.../ml/dataset/CacheBasedDatasetExample.java | 22 +-
.../ignite/examples/ml/dataset/model/Person.java | 32 +-
.../examples/ml/dataset/model/package-info.java | 3 +-
.../ignite/examples/ml/dataset/package-info.java | 3 +-
.../TrainingWithCustomPreprocessorsExample.java | 42 +-
.../examples/ml/environment/package-info.java | 3 +-
.../ignite/examples/ml/genetic/change/Coin.java | 34 +-
.../change/OptimizeMakeChangeFitnessFunction.java | 12 +-
.../change/OptimizeMakeChangeGAExample.java | 16 +-
.../OptimizeMakeChangeTerminateCriteria.java | 14 +-
.../helloworld/HelloWorldFitnessFunction.java | 12 +-
.../ml/genetic/helloworld/HelloWorldGAExample.java | 37 +-
.../helloworld/HelloWorldTerminateCriteria.java | 14 +-
.../ignite/examples/ml/genetic/knapsack/Item.java | 16 +-
.../genetic/knapsack/KnapsackFitnessFunction.java | 8 +-
.../ml/genetic/knapsack/KnapsackGAExample.java | 16 +-
.../knapsack/KnapsackTerminateCriteria.java | 16 +-
.../ignite/examples/ml/genetic/movie/Movie.java | 24 +-
.../ml/genetic/movie/MovieFitnessFunction.java | 16 +-
.../examples/ml/genetic/movie/MovieGAExample.java | 18 +-
.../ml/genetic/movie/MovieTerminateCriteria.java | 14 +-
.../IgniteModelDistributedInferenceExample.java | 10 +-
.../examples/ml/inference/ModelStorageExample.java | 11 +-
.../TensorFlowDistributedInferenceExample.java | 19 +-
.../inference/TensorFlowLocalInferenceExample.java | 16 +-
.../TensorFlowThreadedInferenceExample.java | 16 +-
.../ignite/examples/ml/inference/package-info.java | 3 +-
.../modelparser/DecisionTreeFromSparkExample.java | 15 +-
.../DecisionTreeRegressionFromSparkExample.java | 15 +-
.../spark/modelparser/GBTFromSparkExample.java | 15 +-
.../modelparser/GBTRegressionFromSparkExample.java | 15 +-
.../spark/modelparser/KMeansFromSparkExample.java | 17 +-
.../LinearRegressionFromSparkExample.java | 15 +-
.../spark/modelparser/LogRegFromSparkExample.java | 15 +-
.../modelparser/RandomForestFromSparkExample.java | 15 +-
.../RandomForestRegressionFromSparkExample.java | 15 +-
.../spark/modelparser/SVMFromSparkExample.java | 15 +-
.../inference/spark/modelparser/package-info.java | 3 +-
.../examples/ml/inference/spark/package-info.java | 3 +-
.../examples/ml/knn/ANNClassificationExample.java | 24 +-
.../examples/ml/knn/IrisClassificationExample.java | 21 +-
.../examples/ml/knn/KNNClassificationExample.java | 16 +-
.../examples/ml/knn/KNNRegressionExample.java | 22 +-
.../ignite/examples/ml/knn/package-info.java | 3 +-
.../multiclass/OneVsRestClassificationExample.java | 10 +-
.../examples/ml/multiclass/package-info.java | 3 +-
.../ml/naivebayes/CompoundNaiveBayesExample.java | 6 +-
.../DiscreteNaiveBayesTrainerExample.java | 16 +-
.../GaussianNaiveBayesTrainerExample.java | 16 +-
.../examples/ml/naivebayes/package-info.java | 3 +-
.../ignite/examples/ml/nn/MLPTrainerExample.java | 30 +-
.../apache/ignite/examples/ml/nn/package-info.java | 3 +-
.../apache/ignite/examples/ml/package-info.java | 3 +-
.../ml/preprocessing/BinarizationExample.java | 26 +-
.../examples/ml/preprocessing/ImputingExample.java | 28 +-
.../ml/preprocessing/MaxAbsScalerExample.java | 24 +-
.../ml/preprocessing/MinMaxScalerExample.java | 22 +-
.../ml/preprocessing/NormalizationExample.java | 26 +-
.../ml/preprocessing/StandardScalerExample.java | 24 +-
.../examples/ml/preprocessing/package-info.java | 3 +-
.../linear/BostonHousePricesPredictionExample.java | 28 +-
.../linear/LinearRegressionLSQRTrainerExample.java | 20 +-
...gressionLSQRTrainerWithMinMaxScalerExample.java | 31 +-
.../linear/LinearRegressionSGDTrainerExample.java | 23 +-
.../ml/regression/linear/package-info.java | 3 +-
.../BaggedLogisticRegressionSGDTrainerExample.java | 44 +-
.../regression/logistic/bagged/package-info.java | 3 +-
.../LogisticRegressionSGDTrainerExample.java | 19 +-
.../regression/logistic/binary/package-info.java | 3 +-
.../ml/regression/logistic/package-info.java | 3 +-
.../examples/ml/regression/package-info.java | 3 +-
.../ml/selection/cv/CrossValidationExample.java | 21 +-
.../examples/ml/selection/cv/package-info.java | 3 +-
.../ignite/examples/ml/selection/package-info.java | 3 +-
.../ml/selection/scoring/EvaluatorExample.java | 32 +-
.../selection/scoring/MultipleMetricsExample.java | 25 +-
.../selection/scoring/RegressionMetricExample.java | 20 +-
.../split/TrainTestDatasetSplitterExample.java | 14 +-
.../examples/ml/selection/split/package-info.java | 3 +-
...eeClassificationTrainerSQLInferenceExample.java | 22 +-
...onTreeClassificationTrainerSQLTableExample.java | 24 +-
.../ignite/examples/ml/sql/package-info.java | 3 +-
.../ml/svm/SVMBinaryClassificationExample.java | 23 +-
.../ignite/examples/ml/svm/package-info.java | 3 +-
.../DecisionTreeClassificationTrainerExample.java | 8 +-
.../tree/DecisionTreeRegressionTrainerExample.java | 14 +-
.../examples/ml/tree/FraudDetectionExample.java | 46 +-
.../GDBOnTreesClassificationTrainerExample.java | 16 +-
.../GDBOnTreesRegressionTrainerExample.java | 16 +-
.../examples/ml/tree/boosting/package-info.java | 3 +-
.../ignite/examples/ml/tree/package-info.java | 3 +-
.../RandomForestClassificationExample.java | 12 +-
.../RandomForestRegressionExample.java | 10 +-
.../ml/tree/randomforest/package-info.java | 3 +-
.../ml/tutorial/Step_1_Read_and_Learn.java | 10 +-
.../examples/ml/tutorial/Step_2_Imputing.java | 10 +-
.../examples/ml/tutorial/Step_3_Categorial.java | 10 +-
.../Step_3_Categorial_with_One_Hot_Encoder.java | 13 +-
.../examples/ml/tutorial/Step_4_Add_age_fare.java | 10 +-
.../examples/ml/tutorial/Step_5_Scaling.java | 10 +-
.../ml/tutorial/Step_5_Scaling_with_Pipeline.java | 16 +-
.../ignite/examples/ml/tutorial/Step_6_KNN.java | 14 +-
.../ml/tutorial/Step_7_Split_train_test.java | 14 +-
.../ignite/examples/ml/tutorial/Step_8_CV.java | 40 +-
.../ml/tutorial/Step_8_CV_with_Param_Grid.java | 34 +-
.../Step_8_CV_with_Param_Grid_and_metrics.java | 41 +-
...V_with_Param_Grid_and_metrics_and_pipeline.java | 38 +-
.../ml/tutorial/Step_9_Scaling_With_Stacking.java | 10 +-
.../ignite/examples/ml/tutorial/TitanicUtils.java | 14 +-
.../ml/tutorial/TutorialStepByStepExample.java | 8 +-
.../hyperparametertuning/Step_10_RandomSearch.java | 43 +-
.../Step_11_Parallel_BrutForce_Search.java | 43 +-
.../Step_12_Parallel_Random_Search.java | 43 +-
.../Step_13_Genetic_Programming_Search.java | 43 +-
...tep_14_Parallel_Genetic_Programming_Search.java | 43 +-
.../ignite/examples/ml/tutorial/package-info.java | 3 +-
.../ignite/examples/ml/util/DatasetHelper.java | 12 +-
.../examples/ml/util/MLExamplesCommonArgs.java | 4 +-
.../ParametricVectorGeneratorExample.java | 7 +-
.../util/generators/StandardGeneratorsExample.java | 4 +-
.../generators/VectorGeneratorFamilyExample.java | 8 +-
.../examples/ml/util/generators/package-info.java | 3 +-
.../ignite/examples/ml/util/package-info.java | 3 +-
.../ml/xgboost/XGBoostModelParserExample.java | 23 +-
.../ignite/examples/ml/xgboost/package-info.java | 3 +-
.../IgniteBasicWithPersistenceTestSuite.java | 2 +-
.../IgniteSpiDiscoverySelfTestSuite.java | 4 +-
...idCommandHandlerClusterByClassAbstractTest.java | 5 +-
.../util/GridCommandHandlerClusterByClassTest.java | 37 +-
.../apache/ignite/util/GridCommandHandlerTest.java | 51 +-
...idCommandHandlerIndexingClusterByClassTest.java | 7 +-
.../util/GridCommandHandlerIndexingTest.java | 2 +-
.../util/GridCommandHandlerIndexingUtils.java | 5 +-
.../impl/cache/CacheBasedDatasetBuilder.java | 14 +-
.../ml/selection/cv/AbstractCrossValidation.java | 86 ++-
.../ignite/ml/selection/cv/CrossValidation.java | 21 +-
.../ml/selection/cv/DebugCrossValidation.java | 23 +-
.../scoring/cursor/LocalLabelPairCursor.java | 20 +-
.../scoring/evaluator/EvaluationResult.java | 96 ++++
.../ml/selection/scoring/evaluator/Evaluator.java | 639 ++++++++++++++-------
...assificationPointwiseMetricStatsAggregator.java | 249 ++++++++
.../ClassificationMetricsAggregator.java | 117 ++++
.../aggregator/MetricStatsAggregator.java | 63 ++
.../RegressionMetricStatsAggregator.java | 194 +++++++
.../evaluator/aggregator}/package-info.java | 5 +-
.../BinaryClassificationEvaluationContext.java | 156 +++++
.../context/EmptyContext.java} | 37 +-
.../evaluator/context/EvaluationContext.java | 63 ++
.../context}/package-info.java | 5 +-
.../selection/scoring/evaluator/package-info.java | 3 +-
.../selection/scoring/metric/AbstractMetrics.java | 54 --
.../ignite/ml/selection/scoring/metric/Metric.java | 41 +-
.../ml/selection/scoring/metric/MetricName.java | 213 +++++++
.../ml/selection/scoring/metric/MetricValues.java | 44 --
.../scoring/metric/classification/Accuracy.java | 65 ++-
.../metric/classification/BalancedAccuracy.java | 79 +++
.../classification/BinaryClassificationMetric.java | 71 +++
.../BinaryClassificationMetricValues.java | 181 ------
.../BinaryClassificationMetrics.java | 138 -----
.../scoring/metric/classification/ClassMetric.java | 39 --
.../scoring/metric/classification/FMeasure.java | 118 ++++
.../scoring/metric/classification/FallOut.java | 77 +++
.../classification/FalseNegativeAbsoluteValue.java | 75 +++
.../classification/FalsePositiveAbsoluteValue.java | 75 +++
.../scoring/metric/classification/Fdr.java | 76 +++
.../scoring/metric/classification/Fmeasure.java | 82 ---
.../scoring/metric/classification/MissRate.java | 77 +++
.../scoring/metric/classification/Npv.java | 76 +++
.../scoring/metric/classification/Precision.java | 83 +--
.../scoring/metric/classification/ROCAUC.java | 141 -----
.../scoring/metric/classification/Recall.java | 82 +--
.../scoring/metric/classification/Specificity.java | 76 +++
.../classification/TrueNegativeAbsoluteValue.java | 75 +++
.../classification/TruePositiveAbsoluteValue.java | 75 +++
.../metric/classification/package-info.java | 3 +-
.../ml/selection/scoring/metric/package-info.java | 3 +-
.../selection/scoring/metric/regression/Mae.java | 68 +++
.../selection/scoring/metric/regression/Mse.java | 68 +++
.../ml/selection/scoring/metric/regression/R2.java | 71 +++
.../metric/regression/RegressionMetricValues.java | 81 ---
.../metric/regression/RegressionMetrics.java | 81 ---
.../selection/scoring/metric/regression/Rmse.java | 68 +++
.../selection/scoring/metric/regression/Rss.java | 68 +++
.../scoring/metric/regression/package-info.java | 3 +-
.../ignite/ml/selection/SelectionTestSuite.java | 15 +-
.../ml/selection/cv/CrossValidationTest.java | 61 +-
.../BinaryClassificationEvaluatorTest.java | 9 +-
.../scoring/evaluator/RegressionEvaluatorTest.java | 45 +-
...ficationPointwiseMetricStatsAggregatorTest.java | 107 ++++
.../RegressionMetricStatsAggregatorTest.java | 96 ++++
.../BinaryClassificationEvaluationContextTest.java | 149 +++++
.../metric/classification/AccuracyTest.java | 47 --
.../BinaryClassificationMetricsTest.java | 192 ++-----
.../BinaryClassificationMetricsValuesTest.java | 49 --
.../metric/classification/FmeasureTest.java | 46 --
.../metric/classification/PrecisionTest.java | 46 --
.../scoring/metric/classification/ROCAUCTest.java | 121 ----
.../scoring/metric/classification/RecallTest.java | 46 --
.../metric/regression/RegressionMetricsTest.java | 139 ++---
205 files changed, 4912 insertions(+), 2925 deletions(-)
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/TrainingWithBinaryObjectExample.java b/examples/src/main/java/org/apache/ignite/examples/ml/TrainingWithBinaryObjectExample.java
index 9eec9d1..e823684 100644
--- a/examples/src/main/java/org/apache/ignite/examples/ml/TrainingWithBinaryObjectExample.java
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/TrainingWithBinaryObjectExample.java
@@ -34,7 +34,9 @@ import org.apache.ignite.ml.dataset.impl.cache.CacheBasedDatasetBuilder;
* Example of support model training with binary objects.
*/
public class TrainingWithBinaryObjectExample {
- /** Run example. */
+ /**
+ * Run example.
+ */
public static void main(String[] args) throws Exception {
System.out.println();
System.out.println(">>> Model training over cached dataset with binary objects usage example started.");
@@ -57,15 +59,19 @@ public class TrainingWithBinaryObjectExample {
KMeansModel kmdl = trainer.fit(datasetBuilder, vectorizer);
System.out.println(">>> Model trained over binary objects. Model " + kmdl);
- } finally {
+ }
+ finally {
dataCache.destroy();
}
- } finally {
+ }
+ finally {
System.out.flush();
}
}
- /** Populate cache with some binary objects. */
+ /**
+ * Populate cache with some binary objects.
+ */
private static IgniteCache<Integer, BinaryObject> populateCache(Ignite ignite) {
CacheConfiguration<Integer, BinaryObject> cacheConfiguration = new CacheConfiguration<>();
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/clustering/CustomersClusterizationExample.java b/examples/src/main/java/org/apache/ignite/examples/ml/clustering/CustomersClusterizationExample.java
index 95e2bb4..be7a498 100644
--- a/examples/src/main/java/org/apache/ignite/examples/ml/clustering/CustomersClusterizationExample.java
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/clustering/CustomersClusterizationExample.java
@@ -43,15 +43,16 @@ import org.apache.ignite.ml.util.SandboxMLCache;
/**
* Example of using KMeans clusterization to determine the optimal count of clusters in data.
- *
- * Description of model can be found in: https://en.wikipedia.org/wiki/Kmeans .
- * Original dataset can be downloaded from: https://archive.ics.uci.edu/ml/datasets/Wholesale+customers .
- * Copy of dataset are stored in: modules/ml/src/main/resources/datasets/wholesale_customers.csv .
- * Score for clusterizer estimation: mean of entropy in clusters.
- * Description of entropy can be found in: https://en.wikipedia.org/wiki/Entropy_(information_theory) .
+ * <p>
+ * Description of model can be found in: https://en.wikipedia.org/wiki/Kmeans . Original dataset can be downloaded from:
+ * https://archive.ics.uci.edu/ml/datasets/Wholesale+customers . Copy of dataset are stored in:
+ * modules/ml/src/main/resources/datasets/wholesale_customers.csv . Score for clusterizer estimation: mean of entropy in
+ * clusters. Description of entropy can be found in: https://en.wikipedia.org/wiki/Entropy_(information_theory) .
*/
public class CustomersClusterizationExample {
- /** Runs example. */
+ /**
+ * Runs example.
+ */
public static void main(String[] args) throws IOException {
try (Ignite ignite = Ignition.start("examples/config/example-ignite.xml")) {
System.out.println(">>> Ignite grid started.");
@@ -62,7 +63,7 @@ public class CustomersClusterizationExample {
dataCache = new SandboxMLCache(ignite).fillCacheWith(MLSandboxDatasets.WHOLESALE_CUSTOMERS);
System.out.println(">>> Start traininig and scoring.");
- for(int amountOfClusters = 1; amountOfClusters < 10; amountOfClusters++) {
+ for (int amountOfClusters = 1; amountOfClusters < 10; amountOfClusters++) {
KMeansTrainer trainer = new KMeansTrainer()
.withAmountOfClusters(amountOfClusters)
.withDistance(new EuclideanDistance())
@@ -85,10 +86,12 @@ public class CustomersClusterizationExample {
double entropy = computeMeanEntropy(dataCache, split.getTestFilter(), vectorizer, mdl);
System.out.println(String.format(">> Clusters mean entropy [%d clusters]: %.2f", amountOfClusters, entropy));
}
- } finally {
+ }
+ finally {
dataCache.destroy();
}
- } finally {
+ }
+ finally {
System.out.flush();
}
}
@@ -96,10 +99,10 @@ public class CustomersClusterizationExample {
/**
* Computes mean entropy in clusters.
*
- * @param cache Dataset cache.
- * @param filter Test dataset filter.
+ * @param cache Dataset cache.
+ * @param filter Test dataset filter.
* @param vectorizer Upstream vectorizer.
- * @param model KMeans model.
+ * @param model KMeans model.
* @return Score.
*/
private static double computeMeanEntropy(IgniteCache<Integer, Vector> cache,
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/clustering/GmmClusterizationExample.java b/examples/src/main/java/org/apache/ignite/examples/ml/clustering/GmmClusterizationExample.java
index 4c80c70..8089c90 100644
--- a/examples/src/main/java/org/apache/ignite/examples/ml/clustering/GmmClusterizationExample.java
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/clustering/GmmClusterizationExample.java
@@ -40,7 +40,7 @@ import org.apache.ignite.ml.util.generators.primitives.vector.VectorGeneratorsFa
* Example of using GMM clusterization algorithm. Gaussian Mixture Algorithm (GMM, see {@link GmmModel}, {@link
* GmmTrainer}) can be used for input dataset data distribution representation as mixture of multivariance gaussians.
* More info: https://en.wikipedia.org/wiki/Mixture_model#Gaussian_mixture_model .
- *
+ * <p>
* In this example GMM are used for gaussians shape recovering - means and covariances of them.
*/
public class GmmClusterizationExample {
@@ -106,10 +106,12 @@ public class GmmClusterizationExample {
}
System.out.println(">>>");
- } finally {
+ }
+ finally {
dataCache.destroy();
}
- } finally {
+ }
+ finally {
System.out.flush();
}
}
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/clustering/KMeansClusterizationExample.java b/examples/src/main/java/org/apache/ignite/examples/ml/clustering/KMeansClusterizationExample.java
index edbc617..24b1b5c 100644
--- a/examples/src/main/java/org/apache/ignite/examples/ml/clustering/KMeansClusterizationExample.java
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/clustering/KMeansClusterizationExample.java
@@ -42,13 +42,15 @@ import org.apache.ignite.ml.util.SandboxMLCache;
* After that it trains the model based on the specified data using
* <a href="https://en.wikipedia.org/wiki/K-means_clustering">KMeans</a> algorithm.</p>
* <p>
- * Finally, this example loops over the test set of data points, applies the trained model to predict what cluster
- * does this point belong to, and compares prediction to expected outcome (ground truth).</p>
+ * Finally, this example loops over the test set of data points, applies the trained model to predict what cluster does
+ * this point belong to, and compares prediction to expected outcome (ground truth).</p>
* <p>
* You can change the test data used in this example and re-run it to explore this algorithm further.</p>
*/
public class KMeansClusterizationExample {
- /** Run example. */
+ /**
+ * Run example.
+ */
public static void main(String[] args) throws IOException {
System.out.println();
System.out.println(">>> KMeans clustering algorithm over cached dataset usage example started.");
@@ -93,10 +95,12 @@ public class KMeansClusterizationExample {
System.out.println(">>> ---------------------------------");
System.out.println(">>> KMeans clustering algorithm over cached dataset usage example completed.");
}
- } finally {
+ }
+ finally {
dataCache.destroy();
}
- } finally {
+ }
+ finally {
System.out.flush();
}
}
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/clustering/package-info.java b/examples/src/main/java/org/apache/ignite/examples/ml/clustering/package-info.java
index 872aa16..4844f88 100644
--- a/examples/src/main/java/org/apache/ignite/examples/ml/clustering/package-info.java
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/clustering/package-info.java
@@ -16,7 +16,6 @@
*/
/**
- * <!-- Package description. -->
- * ML clustering examples.
+ * <!-- Package description. --> ML clustering examples.
*/
package org.apache.ignite.examples.ml.clustering;
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/dataset/AlgorithmSpecificDatasetExample.java b/examples/src/main/java/org/apache/ignite/examples/ml/dataset/AlgorithmSpecificDatasetExample.java
index 8011583..5305724 100644
--- a/examples/src/main/java/org/apache/ignite/examples/ml/dataset/AlgorithmSpecificDatasetExample.java
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/dataset/AlgorithmSpecificDatasetExample.java
@@ -67,7 +67,9 @@ import org.apache.ignite.ml.structures.LabeledVector;
* AlgorithmSpecificDatasetExample.AlgorithmSpecificPartitionContext} class.</p>
*/
public class AlgorithmSpecificDatasetExample {
- /** Run example. */
+ /**
+ * Run example.
+ */
public static void main(String[] args) throws Exception {
try (Ignite ignite = Ignition.start("examples/config/example-ignite.xml")) {
System.out.println(">>> Algorithm Specific Dataset example started.");
@@ -78,7 +80,7 @@ public class AlgorithmSpecificDatasetExample {
Vectorizer<Integer, Vector, Integer, Double> vectorizer = new DummyVectorizer<Integer>(1);
- IgniteFunction<LabeledVector<Double>, LabeledVector<double[]>> func = lv -> new LabeledVector<>(lv.features(), new double[]{lv.label()});
+ IgniteFunction<LabeledVector<Double>, LabeledVector<double[]>> func = lv -> new LabeledVector<>(lv.features(), new double[] {lv.label()});
//NOTE: This class is part of Developer API and all lambdas should be loaded on server manually.
Preprocessor<Integer, Vector> preprocessor = new PatchedPreprocessor<>(func, vectorizer);
@@ -123,10 +125,12 @@ public class AlgorithmSpecificDatasetExample {
}
System.out.println(">>> Algorithm Specific Dataset example completed.");
- } finally {
+ }
+ finally {
persons.destroy();
}
- } finally {
+ }
+ finally {
System.out.flush();
}
}
@@ -136,7 +140,9 @@ public class AlgorithmSpecificDatasetExample {
*/
private static class AlgorithmSpecificDataset
extends DatasetWrapper<AlgorithmSpecificPartitionContext, SimpleLabeledDatasetData> {
- /** BLAS (Basic Linear Algebra Subprograms) instance. */
+ /**
+ * BLAS (Basic Linear Algebra Subprograms) instance.
+ */
private static final BLAS blas = BLAS.getInstance();
/**
@@ -149,7 +155,9 @@ public class AlgorithmSpecificDatasetExample {
super(delegate);
}
- /** Calculate gradient. */
+ /**
+ * Calculate gradient.
+ */
double[] gradient(double[] x) {
return computeWithCtx((ctx, data, partIdx) -> {
double[] tmp = Arrays.copyOf(data.getLabels(), data.getRows());
@@ -172,7 +180,9 @@ public class AlgorithmSpecificDatasetExample {
}, this::sum);
}
- /** Sum of two vectors. */
+ /**
+ * Sum of two vectors.
+ */
public double[] sum(double[] a, double[] b) {
if (a == null)
return b;
@@ -190,24 +200,34 @@ public class AlgorithmSpecificDatasetExample {
* Algorithm specific partition context which keeps iteration number.
*/
private static class AlgorithmSpecificPartitionContext implements Serializable {
- /** */
+ /**
+ *
+ */
private static final long serialVersionUID = 1887368924266684044L;
- /** Iteration number. */
+ /**
+ * Iteration number.
+ */
private int iteration;
- /** */
+ /**
+ *
+ */
int getIteration() {
return iteration;
}
- /** */
+ /**
+ *
+ */
void setIteration(int iteration) {
this.iteration = iteration;
}
}
- /** */
+ /**
+ *
+ */
private static IgniteCache<Integer, Vector> createCache(Ignite ignite) {
CacheConfiguration<Integer, Vector> cacheConfiguration = new CacheConfiguration<>();
@@ -216,10 +236,10 @@ public class AlgorithmSpecificDatasetExample {
IgniteCache<Integer, Vector> persons = ignite.createCache(cacheConfiguration);
- persons.put(1, new DenseVector(new Serializable[]{"Mike", 42, 10000}));
- persons.put(2, new DenseVector(new Serializable[]{"John", 32, 64000}));
- persons.put(3, new DenseVector(new Serializable[]{"George", 53, 120000}));
- persons.put(4, new DenseVector(new Serializable[]{"Karl", 24, 70000}));
+ persons.put(1, new DenseVector(new Serializable[] {"Mike", 42, 10000}));
+ persons.put(2, new DenseVector(new Serializable[] {"John", 32, 64000}));
+ persons.put(3, new DenseVector(new Serializable[] {"George", 53, 120000}));
+ persons.put(4, new DenseVector(new Serializable[] {"Karl", 24, 70000}));
return persons;
}
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/dataset/CacheBasedDatasetExample.java b/examples/src/main/java/org/apache/ignite/examples/ml/dataset/CacheBasedDatasetExample.java
index cb8a990..b2cdc54 100644
--- a/examples/src/main/java/org/apache/ignite/examples/ml/dataset/CacheBasedDatasetExample.java
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/dataset/CacheBasedDatasetExample.java
@@ -43,7 +43,9 @@ import org.apache.ignite.ml.math.primitives.vector.impl.DenseVector;
* You can change the test data used in this example and re-run it to explore this functionality further.</p>
*/
public class CacheBasedDatasetExample {
- /** Run example. */
+ /**
+ * Run example.
+ */
public static void main(String[] args) throws Exception {
try (Ignite ignite = Ignition.start("examples/config/example-ignite.xml")) {
System.out.println(">>> Cache Based Dataset example started.");
@@ -64,15 +66,19 @@ public class CacheBasedDatasetExample {
}
System.out.println(">>> Cache Based Dataset example completed.");
- } finally {
+ }
+ finally {
persons.destroy();
}
- } finally {
+ }
+ finally {
System.out.flush();
}
}
- /** */
+ /**
+ *
+ */
private static IgniteCache<Integer, Vector> createCache(Ignite ignite) {
CacheConfiguration<Integer, Vector> cacheConfiguration = new CacheConfiguration<>();
@@ -81,10 +87,10 @@ public class CacheBasedDatasetExample {
IgniteCache<Integer, Vector> persons = ignite.createCache(cacheConfiguration);
- persons.put(1, new DenseVector(new Serializable[]{"Mike", 42, 10000}));
- persons.put(2, new DenseVector(new Serializable[]{"John", 32, 64000}));
- persons.put(3, new DenseVector(new Serializable[]{"George", 53, 120000}));
- persons.put(4, new DenseVector(new Serializable[]{"Karl", 24, 70000}));
+ persons.put(1, new DenseVector(new Serializable[] {"Mike", 42, 10000}));
+ persons.put(2, new DenseVector(new Serializable[] {"John", 32, 64000}));
+ persons.put(3, new DenseVector(new Serializable[] {"George", 53, 120000}));
+ persons.put(4, new DenseVector(new Serializable[] {"Karl", 24, 70000}));
return persons;
}
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/dataset/model/Person.java b/examples/src/main/java/org/apache/ignite/examples/ml/dataset/model/Person.java
index 3770de8..84b90ae 100644
--- a/examples/src/main/java/org/apache/ignite/examples/ml/dataset/model/Person.java
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/dataset/model/Person.java
@@ -17,22 +17,30 @@
package org.apache.ignite.examples.ml.dataset.model;
-/** Person model. */
+/**
+ * Person model.
+ */
public class Person {
- /** Name. */
+ /**
+ * Name.
+ */
private final String name;
- /** Age. */
+ /**
+ * Age.
+ */
private final double age;
- /** Salary. */
+ /**
+ * Salary.
+ */
private final double salary;
/**
* Constructs a new instance of person.
*
- * @param name Name.
- * @param age Age.
+ * @param name Name.
+ * @param age Age.
* @param salary Salary.
*/
public Person(String name, double age, double salary) {
@@ -41,17 +49,23 @@ public class Person {
this.salary = salary;
}
- /** */
+ /**
+ *
+ */
public String getName() {
return name;
}
- /** */
+ /**
+ *
+ */
public double getAge() {
return age;
}
- /** */
+ /**
+ *
+ */
public double getSalary() {
return salary;
}
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/dataset/model/package-info.java b/examples/src/main/java/org/apache/ignite/examples/ml/dataset/model/package-info.java
index c91c40e..27491c9 100644
--- a/examples/src/main/java/org/apache/ignite/examples/ml/dataset/model/package-info.java
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/dataset/model/package-info.java
@@ -16,8 +16,7 @@
*/
/**
- * <!-- Package description. -->
- * Models used in machine learning dataset examples.
+ * <!-- Package description. --> Models used in machine learning dataset examples.
*/
package org.apache.ignite.examples.ml.dataset.model;
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/dataset/package-info.java b/examples/src/main/java/org/apache/ignite/examples/ml/dataset/package-info.java
index d9a670a..a6bceb4 100644
--- a/examples/src/main/java/org/apache/ignite/examples/ml/dataset/package-info.java
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/dataset/package-info.java
@@ -16,8 +16,7 @@
*/
/**
- * <!-- Package description. -->
- * Machine learning dataset examples.
+ * <!-- Package description. --> Machine learning dataset examples.
*/
package org.apache.ignite.examples.ml.dataset;
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/environment/TrainingWithCustomPreprocessorsExample.java b/examples/src/main/java/org/apache/ignite/examples/ml/environment/TrainingWithCustomPreprocessorsExample.java
index 19e1262..1ab9f6b 100644
--- a/examples/src/main/java/org/apache/ignite/examples/ml/environment/TrainingWithCustomPreprocessorsExample.java
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/environment/TrainingWithCustomPreprocessorsExample.java
@@ -34,21 +34,20 @@ import org.apache.ignite.ml.preprocessing.imputing.ImputerTrainer;
import org.apache.ignite.ml.preprocessing.minmaxscaling.MinMaxScalerTrainer;
import org.apache.ignite.ml.preprocessing.normalization.NormalizationTrainer;
import org.apache.ignite.ml.selection.scoring.evaluator.Evaluator;
-import org.apache.ignite.ml.selection.scoring.metric.regression.RegressionMetricValues;
-import org.apache.ignite.ml.selection.scoring.metric.regression.RegressionMetrics;
+import org.apache.ignite.ml.selection.scoring.metric.MetricName;
import org.apache.ignite.ml.structures.LabeledVector;
import org.apache.ignite.ml.tree.DecisionTreeClassificationTrainer;
import org.apache.ignite.ml.util.MLSandboxDatasets;
import org.apache.ignite.ml.util.SandboxMLCache;
/**
- * This example demostrates an ability of using custom client classes in cluster in case of absence of
- * these classes on server nodes. Preprocessors (see {@link Preprocessor}, preprocessor trainers
- * (see {@link PreprocessingTrainer} and vectorizers (see {@link Vectorizer}) can be defined in client code and
- * deployed to server nodes during training phase.
- *
- * For demonstrating of deployment abilities of ml-related classes you can run this example with binary build.
- * NOTE: This binary build should be run with copied basic ml libs from optional directory (ignite-ml at least).
+ * This example demostrates an ability of using custom client classes in cluster in case of absence of these classes on
+ * server nodes. Preprocessors (see {@link Preprocessor}, preprocessor trainers (see {@link PreprocessingTrainer} and
+ * vectorizers (see {@link Vectorizer}) can be defined in client code and deployed to server nodes during training
+ * phase.
+ * <p>
+ * For demonstrating of deployment abilities of ml-related classes you can run this example with binary build. NOTE:
+ * This binary build should be run with copied basic ml libs from optional directory (ignite-ml at least).
*/
public class TrainingWithCustomPreprocessorsExample {
/**
@@ -88,11 +87,8 @@ public class TrainingWithCustomPreprocessorsExample {
.fit(ignite, trainingSet);
System.out.println(">>> Perform scoring.");
- double score = Evaluator.evaluate(
- trainingSet,
- mdl,
- mdl.getPreprocessor(),
- new RegressionMetrics().withMetric(RegressionMetricValues::r2)
+ double score = Evaluator.evaluate(trainingSet,
+ mdl, mdl.getPreprocessor(), MetricName.R2
);
System.out.println(">>> R^2 score: " + score);
@@ -100,8 +96,8 @@ public class TrainingWithCustomPreprocessorsExample {
}
/**
- * Custom trainer for preprocessor. This trainer just returns custom preprocessor based on given
- * preprocessor. Such trainers could be used for injecting custom preprocessors to Pipelines.
+ * Custom trainer for preprocessor. This trainer just returns custom preprocessor based on given preprocessor. Such
+ * trainers could be used for injecting custom preprocessors to Pipelines.
*
* @return Trainer for preprocessor that normalizes given vectors.
*/
@@ -119,11 +115,13 @@ public class TrainingWithCustomPreprocessorsExample {
}
/**
- * Custom vectorizer based on preprocessor. This vectorizer extends given vectors by values equal to
- * log(feature) for each feature in vector.
+ * Custom vectorizer based on preprocessor. This vectorizer extends given vectors by values equal to log(feature)
+ * for each feature in vector.
*/
private static class Vectorizer9000 extends Vectorizer.VectorizerAdapter<Integer, Vector, Integer, Double> {
- /** Base preprocessor. */
+ /**
+ * Base preprocessor.
+ */
private final Preprocessor<Integer, Vector> basePreprocessor;
/**
@@ -135,11 +133,13 @@ public class TrainingWithCustomPreprocessorsExample {
this.basePreprocessor = basePreprocessor;
}
- /** {@inheritDoc} */
+ /**
+ * {@inheritDoc}
+ */
@Override public LabeledVector<Double> apply(Integer key, Vector value) {
LabeledVector<Double> baseVec = basePreprocessor.apply(key, value);
double[] features = new double[baseVec.size() * 2];
- for(int i = 0; i < baseVec.size(); i++) {
+ for (int i = 0; i < baseVec.size(); i++) {
features[i] = baseVec.get(i);
double logValue = Math.log(baseVec.get(i));
features[i + baseVec.size()] = Double.isInfinite(logValue) || Double.isNaN(logValue) ? -1. : logValue;
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/environment/package-info.java b/examples/src/main/java/org/apache/ignite/examples/ml/environment/package-info.java
index f15cac4..93e18b8 100644
--- a/examples/src/main/java/org/apache/ignite/examples/ml/environment/package-info.java
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/environment/package-info.java
@@ -16,7 +16,6 @@
*/
/**
- * <!-- Package description. -->
- * This package contains examples of learning environment features.
+ * <!-- Package description. --> This package contains examples of learning environment features.
*/
package org.apache.ignite.examples.ml.environment;
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/genetic/change/Coin.java b/examples/src/main/java/org/apache/ignite/examples/ml/genetic/change/Coin.java
index 14b7553..2ce5dbb 100644
--- a/examples/src/main/java/org/apache/ignite/examples/ml/genetic/change/Coin.java
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/genetic/change/Coin.java
@@ -23,28 +23,42 @@ import java.io.Serializable;
* POJO to model a coin.
*/
public class Coin implements Serializable {
- /** Define Coin Type. */
+ /**
+ * Define Coin Type.
+ */
public enum CoinType {
- /** */
+ /**
+ *
+ */
PENNY,
- /** */
+ /**
+ *
+ */
QUARTER,
- /** */
+ /**
+ *
+ */
NICKEL,
- /** */
+ /**
+ *
+ */
DIME
}
- /** Number of coins. */
+ /**
+ * Number of coins.
+ */
private int numOfCoins;
- /** Coin type. */
+ /**
+ * Coin type.
+ */
private CoinType coinType;
/**
* Create instance.
*
- * @param coinType Type of coin.
+ * @param coinType Type of coin.
* @param numOfCoins Number of coins.
*/
Coin(CoinType coinType, int numOfCoins) {
@@ -88,7 +102,9 @@ public class Coin implements Serializable {
this.coinType = coinType;
}
- /** {@inheritDoc} */
+ /**
+ * {@inheritDoc}
+ */
@Override public String toString() {
return "Coin [numOfCoins=" + numOfCoins + ", coinType=" + coinType + "]";
}
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/genetic/change/OptimizeMakeChangeFitnessFunction.java b/examples/src/main/java/org/apache/ignite/examples/ml/genetic/change/OptimizeMakeChangeFitnessFunction.java
index b7c54a3..f796b7c 100644
--- a/examples/src/main/java/org/apache/ignite/examples/ml/genetic/change/OptimizeMakeChangeFitnessFunction.java
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/genetic/change/OptimizeMakeChangeFitnessFunction.java
@@ -24,11 +24,13 @@ import org.apache.ignite.ml.genetic.IFitnessFunction;
/**
* This example demonstrates how to create a {@link IFitnessFunction}.
* <p>
- * Your fitness function will vary depending on your particular use case. For this fitness function, we simply want
- * to calculate the value of an individual solution relative to other solutions.</p>
+ * Your fitness function will vary depending on your particular use case. For this fitness function, we simply want to
+ * calculate the value of an individual solution relative to other solutions.</p>
*/
public class OptimizeMakeChangeFitnessFunction implements IFitnessFunction {
- /** Target amount. */
+ /**
+ * Target amount.
+ */
private int targetAmount;
/**
@@ -38,7 +40,9 @@ public class OptimizeMakeChangeFitnessFunction implements IFitnessFunction {
this.targetAmount = targetAmount;
}
- /** {@inheritDoc} */
+ /**
+ * {@inheritDoc}
+ */
@Override public double evaluate(List<Gene> genes) {
int changeAmount = getAmountOfChange(genes);
int totalCoins = getTotalNumberOfCoins(genes);
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/genetic/change/OptimizeMakeChangeGAExample.java b/examples/src/main/java/org/apache/ignite/examples/ml/genetic/change/OptimizeMakeChangeGAExample.java
index 36a5f47..8b6e01a 100644
--- a/examples/src/main/java/org/apache/ignite/examples/ml/genetic/change/OptimizeMakeChangeGAExample.java
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/genetic/change/OptimizeMakeChangeGAExample.java
@@ -33,8 +33,8 @@ import org.apache.ignite.ml.genetic.parameter.GAGridConstants;
* <a href="https://github.com/martin-steghoefer/jgap/blob/master/examples/src/examples/MinimizingMakeChange.java">
* JGAP's "Minimize Make Change"</a> example.
* <p>
- * In this example, the objective is to calculate the minimum number of coins that equal user specified amount of
- * change ie: {@code -DAMOUNTCHANGE}.</p>
+ * In this example, the objective is to calculate the minimum number of coins that equal user specified amount of change
+ * ie: {@code -DAMOUNTCHANGE}.</p>
* <p>
* {@code mvn exec:java -Dexec.mainClass="org.apache.ignite.examples.ml.genetic.change.OptimizeMakeChangeGAExample"
* -DAMOUNTCHANGE=75}</p>
@@ -43,19 +43,19 @@ import org.apache.ignite.ml.genetic.parameter.GAGridConstants;
* <p>
* After that it launches the process of evolution on GA grid and outputs the progress and results.</p>
* <p>
- * You can change the test data and parameters of GA grid used in this example and re-run it to explore
- * this functionality further.</p>
+ * You can change the test data and parameters of GA grid used in this example and re-run it to explore this
+ * functionality further.</p>
* <p>
* Remote nodes should always be started with special configuration file which enables P2P class loading: {@code
* 'ignite.{sh|bat} examples/config/example-ignite.xml'}.</p>
* <p>
- * Alternatively you can run ExampleNodeStartup in another JVM which will start node with
- * {@code examples/config/example-ignite.xml} configuration.</p>
+ * Alternatively you can run ExampleNodeStartup in another JVM which will start node with {@code
+ * examples/config/example-ignite.xml} configuration.</p>
*/
public class OptimizeMakeChangeGAExample {
/**
* Executes example.
- *
+ * <p>
* Specify value for {@code -DAMOUNTCHANGE} JVM system variable.
*
* @param args Command line arguments, none required.
@@ -157,7 +157,7 @@ public class OptimizeMakeChangeGAExample {
/**
* Helper routine to initialize Gene pool.
- *
+ * <p>
* In typical use case genes may be stored in database.
*
* @return List of Genes.
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/genetic/change/OptimizeMakeChangeTerminateCriteria.java b/examples/src/main/java/org/apache/ignite/examples/ml/genetic/change/OptimizeMakeChangeTerminateCriteria.java
index f08f80e..267d334 100644
--- a/examples/src/main/java/org/apache/ignite/examples/ml/genetic/change/OptimizeMakeChangeTerminateCriteria.java
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/genetic/change/OptimizeMakeChangeTerminateCriteria.java
@@ -29,16 +29,20 @@ import org.apache.ignite.ml.genetic.utils.GAGridUtils;
* Terminate Condition implementation for {@link OptimizeMakeChangeGAExample}.
*/
public class OptimizeMakeChangeTerminateCriteria implements ITerminateCriteria {
- /** */
+ /**
+ *
+ */
private final Ignite ignite;
- /** */
+ /**
+ *
+ */
private final Consumer<String> logConsumer;
/**
* Create class instance.
*
- * @param ignite Ignite instance.
+ * @param ignite Ignite instance.
* @param logConsumer Logging consumer.
*/
OptimizeMakeChangeTerminateCriteria(Ignite ignite, Consumer<String> logConsumer) {
@@ -46,7 +50,9 @@ public class OptimizeMakeChangeTerminateCriteria implements ITerminateCriteria {
this.logConsumer = logConsumer;
}
- /** {@inheritDoc} */
+ /**
+ * {@inheritDoc}
+ */
@Override public boolean isTerminationConditionMet(Chromosome fittestChromosome, double averageFitnessScore,
int currGeneration) {
boolean isTerminate = true;
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/genetic/helloworld/HelloWorldFitnessFunction.java b/examples/src/main/java/org/apache/ignite/examples/ml/genetic/helloworld/HelloWorldFitnessFunction.java
index 22875fe..05d4f66 100644
--- a/examples/src/main/java/org/apache/ignite/examples/ml/genetic/helloworld/HelloWorldFitnessFunction.java
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/genetic/helloworld/HelloWorldFitnessFunction.java
@@ -24,16 +24,18 @@ import org.apache.ignite.ml.genetic.IFitnessFunction;
/**
* This example demonstrates how to create a {@link IFitnessFunction}.
* <p>
- * Your fitness function will vary depending on your particular use case. For this fitness function, we simply want
- * to calculate the value of an individual solution relative to other solutions.
+ * Your fitness function will vary depending on your particular use case. For this fitness function, we simply want to
+ * calculate the value of an individual solution relative to other solutions.
* <p>
* To do this, we increase fitness score by '1' for each character that is in correct position.</p>
* <p>
- * For our solution, genetic algorithm will continue until we achieve a fitness score of '11', as 'HELLO WORLD'
- * contains 11 characters.</p>
+ * For our solution, genetic algorithm will continue until we achieve a fitness score of '11', as 'HELLO WORLD' contains
+ * 11 characters.</p>
*/
public class HelloWorldFitnessFunction implements IFitnessFunction {
- /** {@inheritDoc} */
+ /**
+ * {@inheritDoc}
+ */
@Override public double evaluate(List<Gene> genes) {
double matches = 0;
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/genetic/helloworld/HelloWorldGAExample.java b/examples/src/main/java/org/apache/ignite/examples/ml/genetic/helloworld/HelloWorldGAExample.java
index 7e8bb8a..5a9ac62 100644
--- a/examples/src/main/java/org/apache/ignite/examples/ml/genetic/helloworld/HelloWorldGAExample.java
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/genetic/helloworld/HelloWorldGAExample.java
@@ -29,33 +29,30 @@ import org.apache.ignite.ml.genetic.parameter.GAConfiguration;
import org.apache.ignite.ml.genetic.parameter.GAGridConstants;
/**
- * This example demonstrates how to use the {@link GAGrid} framework. In this example, we want to evolve a string
- * of 11 characters such that the word 'HELLO WORLD' is found.
+ * This example demonstrates how to use the {@link GAGrid} framework. In this example, we want to evolve a string of 11
+ * characters such that the word 'HELLO WORLD' is found.
* <p>
* Code in this example launches Ignite grid, prepares simple test data (gene pool) and configures GA grid.</p>
* <p>
* After that it launches the process of evolution on GA grid and outputs the progress and results.</p>
* <p>
- * You can change the test data and parameters of GA grid used in this example and re-run it to explore
- * this functionality further.</p>
- *
+ * You can change the test data and parameters of GA grid used in this example and re-run it to explore this
+ * functionality further.</p>
+ * <p>
* For example, you may change the some basic genetic parameters on the GAConfiguration object:
- *
- * Mutation Rate
- * Crossover Rate
- * Population Size
- * Selection Method
- *
+ * <p>
+ * Mutation Rate Crossover Rate Population Size Selection Method
+ *
* <p>
* How to run from command line:</p>
* <p>
* {@code mvn exec:java -Dexec.mainClass="org.apache.ignite.examples.ml.genetic.helloworld.HelloWorldGAExample"}</p>
* <p>
- * Remote nodes should always be started with special configuration file which enables P2P class loading: {@code
+ * Remote nodes should always be started with special configuration file which enables P2P class loading: {@code
* 'ignite.{sh|bat} examples/config/example-ignite.xml'}.</p>
* <p>
- * Alternatively you can run ExampleNodeStartup in another JVM which will start node with
- * {@code examples/config/example-ignite.xml} configuration.</p>
+ * Alternatively you can run ExampleNodeStartup in another JVM which will start node with {@code
+ * examples/config/example-ignite.xml} configuration.</p>
*/
public class HelloWorldGAExample {
/**
@@ -81,19 +78,19 @@ public class HelloWorldGAExample {
// Initialize gene pool.
gaCfg.setGenePool(genes);
-
+
// Set CrossOver Rate.
gaCfg.setCrossOverRate(.05);
-
+
// Set Mutation Rate.
gaCfg.setMutationRate(.05);
-
+
// Set Selection Method.
gaCfg.setSelectionMtd(GAGridConstants.SELECTION_METHOD.SELECTION_METHOD_ROULETTE_WHEEL);
-
+
// Set Population Size.
gaCfg.setPopulationSize(2000);
-
+
// Create and set Fitness function.
HelloWorldFitnessFunction function = new HelloWorldFitnessFunction();
gaCfg.setFitnessFunction(function);
@@ -127,7 +124,7 @@ public class HelloWorldGAExample {
/**
* Helper routine to initialize Gene pool.
- *
+ * <p>
* In typical use case genes may be stored in database.
*
* @return List of Gene objects.
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/genetic/helloworld/HelloWorldTerminateCriteria.java b/examples/src/main/java/org/apache/ignite/examples/ml/genetic/helloworld/HelloWorldTerminateCriteria.java
index 6ee4542..66a8374 100644
--- a/examples/src/main/java/org/apache/ignite/examples/ml/genetic/helloworld/HelloWorldTerminateCriteria.java
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/genetic/helloworld/HelloWorldTerminateCriteria.java
@@ -31,16 +31,20 @@ import org.apache.ignite.ml.genetic.utils.GAGridUtils;
* Class terminates Genetic algorithm when fitness score is more than 10.</p>
*/
public class HelloWorldTerminateCriteria implements ITerminateCriteria {
- /** Ignite instance. */
+ /**
+ * Ignite instance.
+ */
private final Ignite ignite;
- /** */
+ /**
+ *
+ */
private final Consumer<String> logConsumer;
/**
* Create class instance.
*
- * @param ignite Ignite instance.
+ * @param ignite Ignite instance.
* @param logConsumer Logging consumer.
*/
HelloWorldTerminateCriteria(Ignite ignite, Consumer<String> logConsumer) {
@@ -48,7 +52,9 @@ public class HelloWorldTerminateCriteria implements ITerminateCriteria {
this.logConsumer = logConsumer;
}
- /** {@inheritDoc} */
+ /**
+ * {@inheritDoc}
+ */
@Override public boolean isTerminationConditionMet(Chromosome fittestChromosome, double averageFitnessScore,
int currGeneration) {
boolean isTerminate = true;
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/genetic/knapsack/Item.java b/examples/src/main/java/org/apache/ignite/examples/ml/genetic/knapsack/Item.java
index c8d13f2..6bf7947 100644
--- a/examples/src/main/java/org/apache/ignite/examples/ml/genetic/knapsack/Item.java
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/genetic/knapsack/Item.java
@@ -23,13 +23,19 @@ import java.io.Serializable;
* POJO to model an Item.
*/
public class Item implements Serializable {
- /** Weight of item in lbs. */
+ /**
+ * Weight of item in lbs.
+ */
private double weight;
- /** Value of item. */
+ /**
+ * Value of item.
+ */
private double val;
- /** Name of item. */
+ /**
+ * Name of item.
+ */
private String name;
/**
@@ -86,7 +92,9 @@ public class Item implements Serializable {
this.name = name;
}
- /** {@inheritDoc} */
+ /**
+ * {@inheritDoc}
+ */
@Override public String toString() {
return "Item [weight=" + weight + ", value=" + val + ", name=" + name + "]";
}
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/genetic/knapsack/KnapsackFitnessFunction.java b/examples/src/main/java/org/apache/ignite/examples/ml/genetic/knapsack/KnapsackFitnessFunction.java
index 5fd21d1..109b043 100644
--- a/examples/src/main/java/org/apache/ignite/examples/ml/genetic/knapsack/KnapsackFitnessFunction.java
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/genetic/knapsack/KnapsackFitnessFunction.java
@@ -25,13 +25,15 @@ import org.apache.ignite.ml.genetic.IFitnessFunction;
/**
* This example demonstrates how to create a {@link IFitnessFunction}.
* <p>
- * Your fitness function will vary depending on your particular use case. For this fitness function, we simply want
- * to calculate the weight and value of an individual solution relative to other solutions.</p>
+ * Your fitness function will vary depending on your particular use case. For this fitness function, we simply want to
+ * calculate the weight and value of an individual solution relative to other solutions.</p>
* <p>
* To do this, we total the weights and values of all the genes within a chromosome.</p>
*/
public class KnapsackFitnessFunction implements IFitnessFunction {
- /** {@inheritDoc} */
+ /**
+ * {@inheritDoc}
+ */
@Override public double evaluate(List<Gene> genes) {
double val = 0;
double weight = 0;
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/genetic/knapsack/KnapsackGAExample.java b/examples/src/main/java/org/apache/ignite/examples/ml/genetic/knapsack/KnapsackGAExample.java
index 1631a95..cd3cdfd4 100644
--- a/examples/src/main/java/org/apache/ignite/examples/ml/genetic/knapsack/KnapsackGAExample.java
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/genetic/knapsack/KnapsackGAExample.java
@@ -28,16 +28,16 @@ import org.apache.ignite.ml.genetic.Gene;
import org.apache.ignite.ml.genetic.parameter.GAConfiguration;
/**
- * This example demonstrates how to use the {@link GAGrid} framework. It shows working with Knapsack Problem:
- * Given a set of 30 items, each with a weight and a value, pack 10 items in knapsack so that the total weight
- * is less or equal 20 lbs, and the total value is maximized.
+ * This example demonstrates how to use the {@link GAGrid} framework. It shows working with Knapsack Problem: Given a
+ * set of 30 items, each with a weight and a value, pack 10 items in knapsack so that the total weight is less or equal
+ * 20 lbs, and the total value is maximized.
* <p>
* Code in this example launches Ignite grid, prepares simple test data (gene pool) and configures GA grid.</p>
* <p>
* After that it launches the process of evolution on GA grid and outputs the progress and results.</p>
* <p>
- * You can change the test data and parameters of GA grid used in this example and re-run it to explore
- * this functionality further.</p>
+ * You can change the test data and parameters of GA grid used in this example and re-run it to explore this
+ * functionality further.</p>
* <p>
* How to run from command line:</p>
* <p>
@@ -46,8 +46,8 @@ import org.apache.ignite.ml.genetic.parameter.GAConfiguration;
* Remote nodes should always be started with special configuration file which enables P2P class loading: {@code
* 'ignite.{sh|bat} examples/config/example-ignite.xml'}.</p>
* <p>
- * Alternatively you can run ExampleNodeStartup in another JVM which will start node with
- * {@code examples/config/example-ignite.xml} configuration.</p>
+ * Alternatively you can run ExampleNodeStartup in another JVM which will start node with {@code
+ * examples/config/example-ignite.xml} configuration.</p>
*/
public class KnapsackGAExample {
/**
@@ -104,7 +104,7 @@ public class KnapsackGAExample {
/**
* Helper routine to initialize Gene pool.
- *
+ * <p>
* In typical use case genes may be stored in database.
*
* @return List of Gene objects.
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/genetic/knapsack/KnapsackTerminateCriteria.java b/examples/src/main/java/org/apache/ignite/examples/ml/genetic/knapsack/KnapsackTerminateCriteria.java
index b2337f6..64a7224d 100644
--- a/examples/src/main/java/org/apache/ignite/examples/ml/genetic/knapsack/KnapsackTerminateCriteria.java
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/genetic/knapsack/KnapsackTerminateCriteria.java
@@ -31,16 +31,20 @@ import org.apache.ignite.ml.genetic.utils.GAGridUtils;
* Class terminates Genetic algorithm when once GA Grid has performed 30 generations.</p>
*/
public class KnapsackTerminateCriteria implements ITerminateCriteria {
- /** Ignite instance. */
+ /**
+ * Ignite instance.
+ */
private final Ignite ignite;
- /** */
+ /**
+ *
+ */
private final Consumer<String> logConsumer;
/**
* Create class instance.
*
- * @param ignite Ignite instance.
+ * @param ignite Ignite instance.
* @param logConsumer Logging consumer.
*/
KnapsackTerminateCriteria(Ignite ignite, Consumer<String> logConsumer) {
@@ -48,7 +52,9 @@ public class KnapsackTerminateCriteria implements ITerminateCriteria {
this.logConsumer = logConsumer;
}
- /** {@inheritDoc} */
+ /**
+ * {@inheritDoc}
+ */
@Override public boolean isTerminationConditionMet(Chromosome fittestChromosome, double averageFitnessScore,
int currGeneration) {
boolean isTerminate = true;
@@ -59,7 +65,7 @@ public class KnapsackTerminateCriteria implements ITerminateCriteria {
+ "\n Fittest is Chromosome Key: " + fittestChromosome
+ "\nTotal value is: " + fittestChromosome.getFitnessScore()
+ "\nTotal weight is: " + calculateTotalWeight(
- GAGridUtils.getGenesInOrderForChromosome(ignite, fittestChromosome))
+ GAGridUtils.getGenesInOrderForChromosome(ignite, fittestChromosome))
+ "\nChromosome: " + fittestChromosome
+ "\n" + reportItems(GAGridUtils.getGenesInOrderForChromosome(ignite, fittestChromosome))
+ "\n##########################################################################################");
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/genetic/movie/Movie.java b/examples/src/main/java/org/apache/ignite/examples/ml/genetic/movie/Movie.java
index b6080c3..2aa96d6 100644
--- a/examples/src/main/java/org/apache/ignite/examples/ml/genetic/movie/Movie.java
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/genetic/movie/Movie.java
@@ -23,19 +23,29 @@ import java.util.List;
* POJO to model a movie.
*/
public class Movie {
- /** Name of movie. */
+ /**
+ * Name of movie.
+ */
private String name;
- /** Genre of movie. */
+ /**
+ * Genre of movie.
+ */
private List genre;
- /** Rating of movie. */
+ /**
+ * Rating of movie.
+ */
private String rating;
- /** IMDB rating. */
+ /**
+ * IMDB rating.
+ */
private double imdbRating;
- /** Year of movie. */
+ /**
+ * Year of movie.
+ */
private String year;
/**
@@ -128,7 +138,9 @@ public class Movie {
this.rating = rating;
}
- /** {@inheritDoc} */
+ /**
+ * {@inheritDoc}
+ */
@Override public String toString() {
return "Movie [name=" + name + ", genre=" + genre + ", rating=" + rating + ", imdbRating=" + imdbRating
+ ", year=" + year + "]";
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/genetic/movie/MovieFitnessFunction.java b/examples/src/main/java/org/apache/ignite/examples/ml/genetic/movie/MovieFitnessFunction.java
index b433790..42b929d 100644
--- a/examples/src/main/java/org/apache/ignite/examples/ml/genetic/movie/MovieFitnessFunction.java
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/genetic/movie/MovieFitnessFunction.java
@@ -25,16 +25,18 @@ import org.apache.ignite.ml.genetic.IFitnessFunction;
/**
* This example demonstrates how to create a {@link IFitnessFunction}.
* <p>
- * Your fitness function will vary depending on your particular use case. For this fitness function, we want
- * to calculate the value of an individual solution relative to other solutions.</p>
+ * Your fitness function will vary depending on your particular use case. For this fitness function, we want to
+ * calculate the value of an individual solution relative to other solutions.</p>
* <p>
- * To do this, we increase fitness score by number of times genre is found in list of movies. In addition,
- * we increase score by fictional IMDB rating.</p>
+ * To do this, we increase fitness score by number of times genre is found in list of movies. In addition, we increase
+ * score by fictional IMDB rating.</p>
* <p>
* If there are duplicate movies in selection, we automatically apply a '0' fitness score.</p>
*/
public class MovieFitnessFunction implements IFitnessFunction {
- /** Genres. */
+ /**
+ * Genres.
+ */
private List<String> genres;
/**
@@ -46,7 +48,9 @@ public class MovieFitnessFunction implements IFitnessFunction {
this.genres = genres;
}
- /** {@inheritDoc} */
+ /**
+ * {@inheritDoc}
+ */
@Override public double evaluate(List<Gene> genes) {
double score = 0;
List<String> duplicates = new ArrayList<>();
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/genetic/movie/MovieGAExample.java b/examples/src/main/java/org/apache/ignite/examples/ml/genetic/movie/MovieGAExample.java
index cec2719..6fb60c9 100644
--- a/examples/src/main/java/org/apache/ignite/examples/ml/genetic/movie/MovieGAExample.java
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/genetic/movie/MovieGAExample.java
@@ -29,15 +29,15 @@ import org.apache.ignite.ml.genetic.parameter.GAConfiguration;
import org.apache.ignite.ml.genetic.parameter.GAGridConstants;
/**
- * In this example, we utilize {@link GAGrid} framework to calculate an optimal set of movies based on our interests
- * in various genres (ie: Action, Comedy, and Romance).
+ * In this example, we utilize {@link GAGrid} framework to calculate an optimal set of movies based on our interests in
+ * various genres (ie: Action, Comedy, and Romance).
* <p>
* Code in this example launches Ignite grid, prepares simple test data (gene pool) and configures GA grid.</p>
* <p>
* After that it launches the process of evolution on GA grid and outputs the progress and results.</p>
* <p>
- * You can change the test data and parameters of GA grid used in this example and re-run it to explore
- * this functionality further.</p>
+ * You can change the test data and parameters of GA grid used in this example and re-run it to explore this
+ * functionality further.</p>
* <p>
* How to run from command line:</p>
* <p>
@@ -47,13 +47,13 @@ import org.apache.ignite.ml.genetic.parameter.GAGridConstants;
* Remote nodes should always be started with special configuration file which enables P2P class loading: {@code
* 'ignite.{sh|bat} examples/config/example-ignite.xml'}.</p>
* <p>
- * Alternatively you can run ExampleNodeStartup in another JVM which will start node with
- * {@code examples/config/example-ignite.xml} configuration.</p>
+ * Alternatively you can run ExampleNodeStartup in another JVM which will start node with {@code
+ * examples/config/example-ignite.xml} configuration.</p>
*/
public class MovieGAExample {
/**
* Executes example.
- *
+ * <p>
* Specify value for {@code -DGENRES} JVM system variable.
*
* @param args Command line arguments, none required.
@@ -128,7 +128,9 @@ public class MovieGAExample {
}
}
- /** */
+ /**
+ *
+ */
private static List<Gene> getGenePool() {
List<Gene> list = new ArrayList<>();
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/genetic/movie/MovieTerminateCriteria.java b/examples/src/main/java/org/apache/ignite/examples/ml/genetic/movie/MovieTerminateCriteria.java
index c8d7d58..b193b7d 100644
--- a/examples/src/main/java/org/apache/ignite/examples/ml/genetic/movie/MovieTerminateCriteria.java
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/genetic/movie/MovieTerminateCriteria.java
@@ -31,16 +31,20 @@ import org.apache.ignite.ml.genetic.utils.GAGridUtils;
* Class terminates Genetic algorithm when fitness score is more than 32.</p>
*/
public class MovieTerminateCriteria implements ITerminateCriteria {
- /** Ignite instance. */
+ /**
+ * Ignite instance.
+ */
private final Ignite ignite;
- /** */
+ /**
+ *
+ */
private final Consumer<String> logConsumer;
/**
* Create class instance.
*
- * @param ignite Ignite instance.
+ * @param ignite Ignite instance.
* @param logConsumer Logging consumer.
*/
MovieTerminateCriteria(Ignite ignite, Consumer<String> logConsumer) {
@@ -49,7 +53,9 @@ public class MovieTerminateCriteria implements ITerminateCriteria {
}
- /** {@inheritDoc} */
+ /**
+ * {@inheritDoc}
+ */
@Override public boolean isTerminationConditionMet(Chromosome fittestChromosome, double averageFitnessScore,
int currGeneration) {
boolean isTerminate = true;
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/inference/IgniteModelDistributedInferenceExample.java b/examples/src/main/java/org/apache/ignite/examples/ml/inference/IgniteModelDistributedInferenceExample.java
index 19535d0..26cf41c 100644
--- a/examples/src/main/java/org/apache/ignite/examples/ml/inference/IgniteModelDistributedInferenceExample.java
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/inference/IgniteModelDistributedInferenceExample.java
@@ -46,7 +46,9 @@ import org.apache.ignite.ml.util.SandboxMLCache;
* implemented in {@link org.apache.ignite.ml.inference} package.
*/
public class IgniteModelDistributedInferenceExample {
- /** Run example. */
+ /**
+ * Run example.
+ */
public static void main(String... args) throws IOException, ExecutionException, InterruptedException {
System.out.println();
System.out.println(">>> Linear regression model over cache based dataset usage example started.");
@@ -97,10 +99,12 @@ public class IgniteModelDistributedInferenceExample {
System.out.println(">>> ---------------------------------");
System.out.println(">>> Linear regression model over cache based dataset usage example completed.");
- } finally {
+ }
+ finally {
dataCache.destroy();
}
- } finally {
+ }
+ finally {
System.out.flush();
}
}
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/inference/ModelStorageExample.java b/examples/src/main/java/org/apache/ignite/examples/ml/inference/ModelStorageExample.java
index 4787360..37c5291 100644
--- a/examples/src/main/java/org/apache/ignite/examples/ml/inference/ModelStorageExample.java
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/inference/ModelStorageExample.java
@@ -42,7 +42,9 @@ import org.apache.ignite.ml.inference.storage.model.ModelStorageFactory;
* This example demonstrates how to work with {@link ModelStorage}.
*/
public class ModelStorageExample {
- /** Run example. */
+ /**
+ * Run example.
+ */
public static void main(String... args) throws IOException, ClassNotFoundException {
try (Ignite ignite = Ignition.start("examples/config/example-ignite-ml.xml")) {
System.out.println(">>> Ignite grid started.");
@@ -82,7 +84,8 @@ public class ModelStorageExample {
System.out.println(i + " -> " + res);
}
}
- } finally {
+ }
+ finally {
System.out.flush();
}
}
@@ -107,10 +110,10 @@ public class ModelStorageExample {
/**
* Deserialized object represented as a byte array.
*
- * @param o Serialized object.
+ * @param o Serialized object.
* @param <T> Type of serialized object.
* @return Deserialized object.
- * @throws IOException In case of exception.
+ * @throws IOException In case of exception.
* @throws ClassNotFoundException In case of exception.
*/
@SuppressWarnings("unchecked")
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/inference/TensorFlowDistributedInferenceExample.java b/examples/src/main/java/org/apache/ignite/examples/ml/inference/TensorFlowDistributedInferenceExample.java
index 82b4f91..0d65219 100644
--- a/examples/src/main/java/org/apache/ignite/examples/ml/inference/TensorFlowDistributedInferenceExample.java
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/inference/TensorFlowDistributedInferenceExample.java
@@ -43,16 +43,24 @@ import org.tensorflow.Tensor;
* Apache Ignite services.
*/
public class TensorFlowDistributedInferenceExample {
- /** Path to the directory with saved TensorFlow model. */
+ /**
+ * Path to the directory with saved TensorFlow model.
+ */
private static final String MODEL_PATH = "examples/src/main/resources/models/mnist_tf_model";
- /** Path to the MNIST images data. */
+ /**
+ * Path to the MNIST images data.
+ */
private static final String MNIST_IMG_PATH = "examples/src/main/resources/datasets/t10k-images-idx3-ubyte";
- /** Path to the MNIST labels data. */
+ /**
+ * Path to the MNIST labels data.
+ */
private static final String MNIST_LBL_PATH = "examples/src/main/resources/datasets/t10k-labels-idx1-ubyte";
- /** Run example. */
+ /**
+ * Run example.
+ */
public static void main(String[] args) throws IOException, ExecutionException, InterruptedException {
try (Ignite ignite = Ignition.start("examples/config/example-ignite.xml")) {
File mdlRsrc = IgniteUtils.resolveIgnitePath(MODEL_PATH);
@@ -94,7 +102,8 @@ public class TensorFlowDistributedInferenceExample {
long t1 = System.currentTimeMillis();
System.out.println("Threaded model throughput: " + images.size() / ((t1 - t0) / 1000.0) + " req/sec");
- } finally {
+ }
+ finally {
System.out.flush();
}
}
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/inference/TensorFlowLocalInferenceExample.java b/examples/src/main/java/org/apache/ignite/examples/ml/inference/TensorFlowLocalInferenceExample.java
index 75b885f..f77ac82 100644
--- a/examples/src/main/java/org/apache/ignite/examples/ml/inference/TensorFlowLocalInferenceExample.java
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/inference/TensorFlowLocalInferenceExample.java
@@ -37,16 +37,24 @@ import org.tensorflow.Tensor;
* This example demonstrates how to: load TensorFlow model into Java, make inference using this model in one thread.
*/
public class TensorFlowLocalInferenceExample {
- /** Path to the directory with saved TensorFlow model. */
+ /**
+ * Path to the directory with saved TensorFlow model.
+ */
private static final String MODEL_PATH = "examples/src/main/resources/models/mnist_tf_model";
- /** Path to the MNIST images data. */
+ /**
+ * Path to the MNIST images data.
+ */
private static final String MNIST_IMG_PATH = "examples/src/main/resources/datasets/t10k-images-idx3-ubyte";
- /** Path to the MNIST labels data. */
+ /**
+ * Path to the MNIST labels data.
+ */
private static final String MNIST_LBL_PATH = "examples/src/main/resources/datasets/t10k-labels-idx1-ubyte";
- /** Run example. */
+ /**
+ * Run example.
+ */
public static void main(String[] args) throws IOException {
File mdlRsrc = IgniteUtils.resolveIgnitePath(MODEL_PATH);
if (mdlRsrc == null)
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/inference/TensorFlowThreadedInferenceExample.java b/examples/src/main/java/org/apache/ignite/examples/ml/inference/TensorFlowThreadedInferenceExample.java
index b4fe6d5..22f0b23 100644
--- a/examples/src/main/java/org/apache/ignite/examples/ml/inference/TensorFlowThreadedInferenceExample.java
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/inference/TensorFlowThreadedInferenceExample.java
@@ -41,16 +41,24 @@ import org.tensorflow.Tensor;
* threads.
*/
public class TensorFlowThreadedInferenceExample {
- /** Path to the directory with saved TensorFlow model. */
+ /**
+ * Path to the directory with saved TensorFlow model.
+ */
private static final String MODEL_PATH = "examples/src/main/resources/models/mnist_tf_model";
- /** Path to the MNIST images data. */
+ /**
+ * Path to the MNIST images data.
+ */
private static final String MNIST_IMG_PATH = "examples/src/main/resources/datasets/t10k-images-idx3-ubyte";
- /** Path to the MNIST labels data. */
+ /**
+ * Path to the MNIST labels data.
+ */
private static final String MNIST_LBL_PATH = "examples/src/main/resources/datasets/t10k-labels-idx1-ubyte";
- /** Run example. */
+ /**
+ * Run example.
+ */
public static void main(String[] args) throws IOException, ExecutionException, InterruptedException {
File mdlRsrc = IgniteUtils.resolveIgnitePath(MODEL_PATH);
if (mdlRsrc == null)
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/inference/package-info.java b/examples/src/main/java/org/apache/ignite/examples/ml/inference/package-info.java
index db1616b..2627436 100644
--- a/examples/src/main/java/org/apache/ignite/examples/ml/inference/package-info.java
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/inference/package-info.java
@@ -16,7 +16,6 @@
*/
/**
- * <!-- Package description. -->
- * Model inference examples.
+ * <!-- Package description. --> Model inference examples.
*/
package org.apache.ignite.examples.ml.inference;
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/inference/spark/modelparser/DecisionTreeFromSparkExample.java b/examples/src/main/java/org/apache/ignite/examples/ml/inference/spark/modelparser/DecisionTreeFromSparkExample.java
index d493c74..ab50d78 100644
--- a/examples/src/main/java/org/apache/ignite/examples/ml/inference/spark/modelparser/DecisionTreeFromSparkExample.java
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/inference/spark/modelparser/DecisionTreeFromSparkExample.java
@@ -33,17 +33,21 @@ import org.apache.ignite.ml.sparkmodelparser.SupportedSparkModels;
import org.apache.ignite.ml.tree.DecisionTreeNode;
/**
- * Run Decision Tree model loaded from snappy.parquet file.
- * The snappy.parquet file was generated by Spark MLLib model.write.overwrite().save(..) operator.
+ * Run Decision Tree model loaded from snappy.parquet file. The snappy.parquet file was generated by Spark MLLib
+ * model.write.overwrite().save(..) operator.
* <p>
* You can change the test data used in this example and re-run it to explore this algorithm further.</p>
*/
public class DecisionTreeFromSparkExample {
- /** Path to Spark DT model. */
+ /**
+ * Path to Spark DT model.
+ */
public static final String SPARK_MDL_PATH = IgniteUtils.resolveIgnitePath("examples/src/main/resources/models/spark/serialized/dt")
.toPath().toAbsolutePath().toString();
- /** Run example. */
+ /**
+ * Run example.
+ */
public static void main(String[] args) throws FileNotFoundException {
System.out.println();
System.out.println(">>> Decision Tree model loaded from Spark through serialization over partitioned dataset usage example started.");
@@ -73,7 +77,8 @@ public class DecisionTreeFromSparkExample {
System.out.println("\n>>> Accuracy " + accuracy);
System.out.println("\n>>> Test Error " + (1 - accuracy));
- } finally {
+ }
+ finally {
dataCache.destroy();
}
}
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/inference/spark/modelparser/DecisionTreeRegressionFromSparkExample.java b/examples/src/main/java/org/apache/ignite/examples/ml/inference/spark/modelparser/DecisionTreeRegressionFromSparkExample.java
index b9e4d43..17ebfec 100644
--- a/examples/src/main/java/org/apache/ignite/examples/ml/inference/spark/modelparser/DecisionTreeRegressionFromSparkExample.java
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/inference/spark/modelparser/DecisionTreeRegressionFromSparkExample.java
@@ -34,16 +34,20 @@ import org.apache.ignite.ml.structures.LabeledVector;
import org.apache.ignite.ml.tree.DecisionTreeNode;
/**
- * Run Decision tree regression model loaded from snappy.parquet file.
- * The snappy.parquet file was generated by Spark MLLib model.write.overwrite().save(..) operator.
+ * Run Decision tree regression model loaded from snappy.parquet file. The snappy.parquet file was generated by Spark
+ * MLLib model.write.overwrite().save(..) operator.
* <p>
* You can change the test data used in this example and re-run it to explore this algorithm further.</p>
*/
public class DecisionTreeRegressionFromSparkExample {
- /** Path to Spark Decision tree regression model. */
+ /**
+ * Path to Spark Decision tree regression model.
+ */
public static final String SPARK_MDL_PATH = "examples/src/main/resources/models/spark/serialized/dtreg";
- /** Run example. */
+ /**
+ * Run example.
+ */
public static void main(String[] args) throws FileNotFoundException {
System.out.println();
System.out.println(">>> Decision tree regression model loaded from Spark through serialization over partitioned dataset usage example started.");
@@ -80,7 +84,8 @@ public class DecisionTreeRegressionFromSparkExample {
}
System.out.println(">>> ---------------------------------");
- } finally {
+ }
+ finally {
dataCache.destroy();
}
}
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/inference/spark/modelparser/GBTFromSparkExample.java b/examples/src/main/java/org/apache/ignite/examples/ml/inference/spark/modelparser/GBTFromSparkExample.java
index ef28fa5..900c8b5 100644
--- a/examples/src/main/java/org/apache/ignite/examples/ml/inference/spark/modelparser/GBTFromSparkExample.java
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/inference/spark/modelparser/GBTFromSparkExample.java
@@ -32,16 +32,20 @@ import org.apache.ignite.ml.sparkmodelparser.SparkModelParser;
import org.apache.ignite.ml.sparkmodelparser.SupportedSparkModels;
/**
- * Run Gradient Boosted trees model loaded from snappy.parquet file.
- * The snappy.parquet file was generated by Spark MLLib model.write.overwrite().save(..) operator.
+ * Run Gradient Boosted trees model loaded from snappy.parquet file. The snappy.parquet file was generated by Spark
+ * MLLib model.write.overwrite().save(..) operator.
* <p>
* You can change the test data used in this example and re-run it to explore this algorithm further.</p>
*/
public class GBTFromSparkExample {
- /** Path to Spark LogReg model. */
+ /**
+ * Path to Spark LogReg model.
+ */
public static final String SPARK_MDL_PATH = "examples/src/main/resources/models/spark/serialized/gbt";
- /** Run example. */
+ /**
+ * Run example.
+ */
public static void main(String[] args) throws FileNotFoundException {
System.out.println();
System.out.println(">>> Gradient Boosted trees model loaded from Spark through serialization over partitioned dataset usage example started.");
@@ -71,7 +75,8 @@ public class GBTFromSparkExample {
System.out.println("\n>>> Accuracy " + accuracy);
System.out.println("\n>>> Test Error " + (1 - accuracy));
- } finally {
+ }
+ finally {
dataCache.destroy();
}
}
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/inference/spark/modelparser/GBTRegressionFromSparkExample.java b/examples/src/main/java/org/apache/ignite/examples/ml/inference/spark/modelparser/GBTRegressionFromSparkExample.java
index 86b788c..71b08ee 100644
--- a/examples/src/main/java/org/apache/ignite/examples/ml/inference/spark/modelparser/GBTRegressionFromSparkExample.java
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/inference/spark/modelparser/GBTRegressionFromSparkExample.java
@@ -34,16 +34,20 @@ import org.apache.ignite.ml.sparkmodelparser.SupportedSparkModels;
import org.apache.ignite.ml.structures.LabeledVector;
/**
- * Run GBT Regression model loaded from snappy.parquet file.
- * The snappy.parquet file was generated by Spark MLLib model.write.overwrite().save(..) operator.
+ * Run GBT Regression model loaded from snappy.parquet file. The snappy.parquet file was generated by Spark MLLib
+ * model.write.overwrite().save(..) operator.
* <p>
* You can change the test data used in this example and re-run it to explore this algorithm further.</p>
*/
public class GBTRegressionFromSparkExample {
- /** Path to Spark GBT Regression model. */
+ /**
+ * Path to Spark GBT Regression model.
+ */
public static final String SPARK_MDL_PATH = "examples/src/main/resources/models/spark/serialized/gbtreg";
- /** Run example. */
+ /**
+ * Run example.
+ */
public static void main(String[] args) throws FileNotFoundException {
System.out.println();
System.out.println(">>> GBT Regression model loaded from Spark through serialization over partitioned dataset usage example started.");
@@ -80,7 +84,8 @@ public class GBTRegressionFromSparkExample {
}
System.out.println(">>> ---------------------------------");
- } finally {
+ }
+ finally {
dataCache.destroy();
}
}
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/inference/spark/modelparser/KMeansFromSparkExample.java b/examples/src/main/java/org/apache/ignite/examples/ml/inference/spark/modelparser/KMeansFromSparkExample.java
index 0e1ec90..aed14e3 100644
--- a/examples/src/main/java/org/apache/ignite/examples/ml/inference/spark/modelparser/KMeansFromSparkExample.java
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/inference/spark/modelparser/KMeansFromSparkExample.java
@@ -34,16 +34,20 @@ import org.apache.ignite.ml.sparkmodelparser.SupportedSparkModels;
import org.apache.ignite.ml.structures.LabeledVector;
/**
- * Run KMeans model loaded from snappy.parquet file.
- * The snappy.parquet file was generated by Spark MLLib model.write.overwrite().save(..) operator.
+ * Run KMeans model loaded from snappy.parquet file. The snappy.parquet file was generated by Spark MLLib
+ * model.write.overwrite().save(..) operator.
* <p>
* You can change the test data used in this example and re-run it to explore this algorithm further.</p>
*/
public class KMeansFromSparkExample {
- /** Path to Spark KMeans model. */
+ /**
+ * Path to Spark KMeans model.
+ */
public static final String SPARK_MDL_PATH = "examples/src/main/resources/models/spark/serialized/kmeans";
- /** Run example. */
+ /**
+ * Run example.
+ */
public static void main(String[] args) throws FileNotFoundException {
System.out.println();
System.out.println(">>> K-means model loaded from Spark through serialization over partitioned dataset usage example started.");
@@ -68,7 +72,7 @@ public class KMeansFromSparkExample {
System.out.println(">>> ------------------------------------");
try (QueryCursor<Cache.Entry<Integer, Vector>> observations = dataCache.query(new ScanQuery<>())) {
- for (Cache.Entry<Integer,Vector> observation : observations) {
+ for (Cache.Entry<Integer, Vector> observation : observations) {
LabeledVector<Double> lv = vectorizer.apply(observation.getKey(), observation.getValue());
Vector inputs = lv.features();
double isSurvived = lv.label();
@@ -79,7 +83,8 @@ public class KMeansFromSparkExample {
}
System.out.println(">>> ---------------------------------");
- } finally {
+ }
+ finally {
dataCache.destroy();
}
}
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/inference/spark/modelparser/LinearRegressionFromSparkExample.java b/examples/src/main/java/org/apache/ignite/examples/ml/inference/spark/modelparser/LinearRegressionFromSparkExample.java
index 546f5c6..489cd28 100644
--- a/examples/src/main/java/org/apache/ignite/examples/ml/inference/spark/modelparser/LinearRegressionFromSparkExample.java
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/inference/spark/modelparser/LinearRegressionFromSparkExample.java
@@ -34,16 +34,20 @@ import org.apache.ignite.ml.sparkmodelparser.SupportedSparkModels;
import org.apache.ignite.ml.structures.LabeledVector;
/**
- * Run linear regression model loaded from snappy.parquet file.
- * The snappy.parquet file was generated by Spark MLLib model.write.overwrite().save(..) operator.
+ * Run linear regression model loaded from snappy.parquet file. The snappy.parquet file was generated by Spark MLLib
+ * model.write.overwrite().save(..) operator.
* <p>
* You can change the test data used in this example and re-run it to explore this algorithm further.</p>
*/
public class LinearRegressionFromSparkExample {
- /** Path to Spark linear regression model. */
+ /**
+ * Path to Spark linear regression model.
+ */
public static final String SPARK_MDL_PATH = "examples/src/main/resources/models/spark/serialized/linreg";
- /** Run example. */
+ /**
+ * Run example.
+ */
public static void main(String[] args) throws FileNotFoundException {
System.out.println();
System.out.println(">>> Linear regression model loaded from Spark through serialization over partitioned dataset usage example started.");
@@ -80,7 +84,8 @@ public class LinearRegressionFromSparkExample {
}
System.out.println(">>> ---------------------------------");
- } finally {
+ }
+ finally {
dataCache.destroy();
}
}
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/inference/spark/modelparser/LogRegFromSparkExample.java b/examples/src/main/java/org/apache/ignite/examples/ml/inference/spark/modelparser/LogRegFromSparkExample.java
index 48c20d8..96425ee 100644
--- a/examples/src/main/java/org/apache/ignite/examples/ml/inference/spark/modelparser/LogRegFromSparkExample.java
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/inference/spark/modelparser/LogRegFromSparkExample.java
@@ -32,16 +32,20 @@ import org.apache.ignite.ml.sparkmodelparser.SparkModelParser;
import org.apache.ignite.ml.sparkmodelparser.SupportedSparkModels;
/**
- * Run logistic regression model loaded from snappy.parquet file.
- * The snappy.parquet file was generated by Spark MLLib model.write.overwrite().save(..) operator.
+ * Run logistic regression model loaded from snappy.parquet file. The snappy.parquet file was generated by Spark MLLib
+ * model.write.overwrite().save(..) operator.
* <p>
* You can change the test data used in this example and re-run it to explore this algorithm further.</p>
*/
public class LogRegFromSparkExample {
- /** Path to Spark LogReg model. */
+ /**
+ * Path to Spark LogReg model.
+ */
public static final String SPARK_MDL_PATH = "examples/src/main/resources/models/spark/serialized/logreg";
- /** Run example. */
+ /**
+ * Run example.
+ */
public static void main(String[] args) throws FileNotFoundException {
System.out.println();
System.out.println(">>> Logistic regression model loaded from Spark through serialization over partitioned dataset usage example started.");
@@ -71,7 +75,8 @@ public class LogRegFromSparkExample {
System.out.println("\n>>> Accuracy " + accuracy);
System.out.println("\n>>> Test Error " + (1 - accuracy));
- } finally {
+ }
+ finally {
dataCache.destroy();
}
}
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/inference/spark/modelparser/RandomForestFromSparkExample.java b/examples/src/main/java/org/apache/ignite/examples/ml/inference/spark/modelparser/RandomForestFromSparkExample.java
index 7b4cf9d..8e65bbe 100644
--- a/examples/src/main/java/org/apache/ignite/examples/ml/inference/spark/modelparser/RandomForestFromSparkExample.java
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/inference/spark/modelparser/RandomForestFromSparkExample.java
@@ -32,16 +32,20 @@ import org.apache.ignite.ml.sparkmodelparser.SparkModelParser;
import org.apache.ignite.ml.sparkmodelparser.SupportedSparkModels;
/**
- * Run Random Forest model loaded from snappy.parquet file.
- * The snappy.parquet file was generated by Spark MLLib model.write.overwrite().save(..) operator.
+ * Run Random Forest model loaded from snappy.parquet file. The snappy.parquet file was generated by Spark MLLib
+ * model.write.overwrite().save(..) operator.
* <p>
* You can change the test data used in this example and re-run it to explore this algorithm further.</p>
*/
public class RandomForestFromSparkExample {
- /** Path to Spark Random Forest model. */
+ /**
+ * Path to Spark Random Forest model.
+ */
public static final String SPARK_MDL_PATH = "examples/src/main/resources/models/spark/serialized/rf";
- /** Run example. */
+ /**
+ * Run example.
+ */
public static void main(String[] args) throws FileNotFoundException {
System.out.println();
System.out.println(">>> Random Forest model loaded from Spark through serialization over partitioned dataset usage example started.");
@@ -71,7 +75,8 @@ public class RandomForestFromSparkExample {
System.out.println("\n>>> Accuracy " + accuracy);
System.out.println("\n>>> Test Error " + (1 - accuracy));
- } finally {
+ }
+ finally {
dataCache.destroy();
}
}
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/inference/spark/modelparser/RandomForestRegressionFromSparkExample.java b/examples/src/main/java/org/apache/ignite/examples/ml/inference/spark/modelparser/RandomForestRegressionFromSparkExample.java
index 76c0f3c..d3e1206 100644
--- a/examples/src/main/java/org/apache/ignite/examples/ml/inference/spark/modelparser/RandomForestRegressionFromSparkExample.java
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/inference/spark/modelparser/RandomForestRegressionFromSparkExample.java
@@ -34,16 +34,20 @@ import org.apache.ignite.ml.sparkmodelparser.SupportedSparkModels;
import org.apache.ignite.ml.structures.LabeledVector;
/**
- * Run Random Forest regression model loaded from snappy.parquet file.
- * The snappy.parquet file was generated by Spark MLLib model.write.overwrite().save(..) operator.
+ * Run Random Forest regression model loaded from snappy.parquet file. The snappy.parquet file was generated by Spark
+ * MLLib model.write.overwrite().save(..) operator.
* <p>
* You can change the test data used in this example and re-run it to explore this algorithm further.</p>
*/
public class RandomForestRegressionFromSparkExample {
- /** Path to Spark Random Forest regression model. */
+ /**
+ * Path to Spark Random Forest regression model.
+ */
public static final String SPARK_MDL_PATH = "examples/src/main/resources/models/spark/serialized/rfreg";
- /** Run example. */
+ /**
+ * Run example.
+ */
public static void main(String[] args) throws FileNotFoundException {
System.out.println();
System.out.println(">>> Random Forest regression model loaded from Spark through serialization over partitioned dataset usage example started.");
@@ -80,7 +84,8 @@ public class RandomForestRegressionFromSparkExample {
}
System.out.println(">>> ---------------------------------");
- } finally {
+ }
+ finally {
dataCache.destroy();
}
}
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/inference/spark/modelparser/SVMFromSparkExample.java b/examples/src/main/java/org/apache/ignite/examples/ml/inference/spark/modelparser/SVMFromSparkExample.java
index 48d6bb6..d9ad197 100644
--- a/examples/src/main/java/org/apache/ignite/examples/ml/inference/spark/modelparser/SVMFromSparkExample.java
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/inference/spark/modelparser/SVMFromSparkExample.java
@@ -32,16 +32,20 @@ import org.apache.ignite.ml.sparkmodelparser.SupportedSparkModels;
import org.apache.ignite.ml.svm.SVMLinearClassificationModel;
/**
- * Run SVM model loaded from snappy.parquet file.
- * The snappy.parquet file was generated by Spark MLLib model.write.overwrite().save(..) operator.
+ * Run SVM model loaded from snappy.parquet file. The snappy.parquet file was generated by Spark MLLib
+ * model.write.overwrite().save(..) operator.
* <p>
* You can change the test data used in this example and re-run it to explore this algorithm further.</p>
*/
public class SVMFromSparkExample {
- /** Path to Spark SVM model. */
+ /**
+ * Path to Spark SVM model.
+ */
public static final String SPARK_MDL_PATH = "examples/src/main/resources/models/spark/serialized/svm";
- /** Run example. */
+ /**
+ * Run example.
+ */
public static void main(String[] args) throws FileNotFoundException {
System.out.println();
System.out.println(">>> SVM model loaded from Spark through serialization over partitioned dataset usage example started.");
@@ -71,7 +75,8 @@ public class SVMFromSparkExample {
System.out.println("\n>>> Accuracy " + accuracy);
System.out.println("\n>>> Test Error " + (1 - accuracy));
- } finally {
+ }
+ finally {
dataCache.destroy();
}
}
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/inference/spark/modelparser/package-info.java b/examples/src/main/java/org/apache/ignite/examples/ml/inference/spark/modelparser/package-info.java
index 946e11c..4b994d5 100644
--- a/examples/src/main/java/org/apache/ignite/examples/ml/inference/spark/modelparser/package-info.java
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/inference/spark/modelparser/package-info.java
@@ -16,7 +16,6 @@
*/
/**
- * <!-- Package description. -->
- * Model inference examples for Spark ML via Spark Model Parser.
+ * <!-- Package description. --> Model inference examples for Spark ML via Spark Model Parser.
*/
package org.apache.ignite.examples.ml.inference.spark.modelparser;
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/inference/spark/package-info.java b/examples/src/main/java/org/apache/ignite/examples/ml/inference/spark/package-info.java
index 1db3cd2..699fe5d 100644
--- a/examples/src/main/java/org/apache/ignite/examples/ml/inference/spark/package-info.java
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/inference/spark/package-info.java
@@ -16,7 +16,6 @@
*/
/**
- * <!-- Package description. -->
- * Model inference examples for Spark ML models.
+ * <!-- Package description. --> Model inference examples for Spark ML models.
*/
package org.apache.ignite.examples.ml.inference.spark;
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/knn/ANNClassificationExample.java b/examples/src/main/java/org/apache/ignite/examples/ml/knn/ANNClassificationExample.java
index 130e890..8a23a8f 100644
--- a/examples/src/main/java/org/apache/ignite/examples/ml/knn/ANNClassificationExample.java
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/knn/ANNClassificationExample.java
@@ -45,13 +45,15 @@ import org.apache.ignite.ml.math.primitives.vector.impl.DenseVector;
* After that it trains the model based on the specified data using
* <a href="https://en.wikipedia.org/wiki/K-nearest_neighbors_algorithm">kNN</a> algorithm.</p>
* <p>
- * Finally, this example loops over the test set of data points, applies the trained model to predict what cluster
- * does this point belong to, and compares prediction to expected outcome (ground truth).</p>
+ * Finally, this example loops over the test set of data points, applies the trained model to predict what cluster does
+ * this point belong to, and compares prediction to expected outcome (ground truth).</p>
* <p>
* You can change the test data used in this example and re-run it to explore this algorithm further.</p>
*/
public class ANNClassificationExample {
- /** Run example. */
+ /**
+ * Run example.
+ */
public static void main(String[] args) {
System.out.println();
System.out.println(">>> ANN multi-class classification algorithm over cached dataset usage example started.");
@@ -120,10 +122,12 @@ public class ANNClassificationExample {
System.out.println(">>> ANN multi-class classification algorithm over cached dataset usage example completed.");
}
- } finally {
+ }
+ finally {
dataCache.destroy();
}
- } finally {
+ }
+ finally {
System.out.flush();
}
}
@@ -151,16 +155,20 @@ public class ANNClassificationExample {
/**
* Tiny changing of data depending on k parameter.
+ *
* @param datum The vector data.
- * @param k The passed parameter.
+ * @param k The passed parameter.
* @return The changed vector data.
*/
private static double[] mutate(double[] datum, int k) {
- for (int i = 0; i < datum.length; i++) datum[i] += k / 100000;
+ for (int i = 0; i < datum.length; i++)
+ datum[i] += k / 100000;
return datum;
}
- /** The Iris dataset. */
+ /**
+ * The Iris dataset.
+ */
private static final double[][] data = {
{1, 5.1, 3.5, 1.4, 0.2},
{1, 4.9, 3, 1.4, 0.2},
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/knn/IrisClassificationExample.java b/examples/src/main/java/org/apache/ignite/examples/ml/knn/IrisClassificationExample.java
index 04b24b4..c06c5c3 100644
--- a/examples/src/main/java/org/apache/ignite/examples/ml/knn/IrisClassificationExample.java
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/knn/IrisClassificationExample.java
@@ -37,15 +37,16 @@ import org.apache.ignite.ml.util.SandboxMLCache;
/**
* Example of using Knn model in Apache Ignite for iris class predicion.
- *
- * Description of model can be found in: https://en.wikipedia.org/wiki/K-nearest_neighbors_algorithm .
- * Original dataset can be downloaded from: https://archive.ics.uci.edu/ml/datasets/Wholesale+customers .
- * Copy of dataset are stored in: https://archive.ics.uci.edu/ml/datasets/iris .
- * Score for classifier estimation: accuracy .
- * Description of score can be found in: https://stattrek.com/statistics/dictionary.aspx?definition=accuracy .
+ * <p>
+ * Description of model can be found in: https://en.wikipedia.org/wiki/K-nearest_neighbors_algorithm . Original dataset
+ * can be downloaded from: https://archive.ics.uci.edu/ml/datasets/Wholesale+customers . Copy of dataset are stored in:
+ * https://archive.ics.uci.edu/ml/datasets/iris . Score for classifier estimation: accuracy . Description of score can
+ * be found in: https://stattrek.com/statistics/dictionary.aspx?definition=accuracy .
*/
public class IrisClassificationExample {
- /** Runs example. */
+ /**
+ * Runs example.
+ */
public static void main(String[] args) throws IOException {
try (Ignite ignite = Ignition.start("examples/config/example-ignite.xml")) {
System.out.println(">>> Ignite grid started.");
@@ -84,10 +85,12 @@ public class IrisClassificationExample {
);
System.out.println(">> Model accuracy: " + accuracy);
- } finally {
+ }
+ finally {
dataCache.destroy();
}
- } finally {
+ }
+ finally {
System.out.flush();
}
}
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/knn/KNNClassificationExample.java b/examples/src/main/java/org/apache/ignite/examples/ml/knn/KNNClassificationExample.java
index 4ae940b..e089f51 100644
--- a/examples/src/main/java/org/apache/ignite/examples/ml/knn/KNNClassificationExample.java
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/knn/KNNClassificationExample.java
@@ -28,6 +28,7 @@ import org.apache.ignite.ml.knn.classification.KNNClassificationTrainer;
import org.apache.ignite.ml.math.distances.EuclideanDistance;
import org.apache.ignite.ml.math.primitives.vector.Vector;
import org.apache.ignite.ml.selection.scoring.evaluator.Evaluator;
+import org.apache.ignite.ml.selection.scoring.metric.MetricName;
import org.apache.ignite.ml.util.MLSandboxDatasets;
import org.apache.ignite.ml.util.SandboxMLCache;
@@ -46,7 +47,9 @@ import org.apache.ignite.ml.util.SandboxMLCache;
* You can change the test data used in this example and re-run it to explore this algorithm further.</p>
*/
public class KNNClassificationExample {
- /** Run example. */
+ /**
+ * Run example.
+ */
public static void main(String[] args) throws IOException {
System.out.println();
System.out.println(">>> kNN multi-class classification algorithm over cached dataset usage example started.");
@@ -72,15 +75,18 @@ public class KNNClassificationExample {
double accuracy = Evaluator.evaluate(
dataCache,
mdl,
- vectorizer
- ).accuracy();
+ vectorizer,
+ MetricName.ACCURACY
+ );
System.out.println("\n>>> Accuracy " + accuracy);
- } finally {
+ }
+ finally {
if (dataCache != null)
dataCache.destroy();
}
- } finally {
+ }
+ finally {
System.out.flush();
}
}
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/knn/KNNRegressionExample.java b/examples/src/main/java/org/apache/ignite/examples/ml/knn/KNNRegressionExample.java
index 7c89aa9..7449aa5 100644
--- a/examples/src/main/java/org/apache/ignite/examples/ml/knn/KNNRegressionExample.java
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/knn/KNNRegressionExample.java
@@ -29,7 +29,7 @@ import org.apache.ignite.ml.knn.utils.indices.SpatialIndexType;
import org.apache.ignite.ml.math.distances.ManhattanDistance;
import org.apache.ignite.ml.math.primitives.vector.Vector;
import org.apache.ignite.ml.selection.scoring.evaluator.Evaluator;
-import org.apache.ignite.ml.selection.scoring.metric.regression.RegressionMetrics;
+import org.apache.ignite.ml.selection.scoring.metric.regression.Rmse;
import org.apache.ignite.ml.util.MLSandboxDatasets;
import org.apache.ignite.ml.util.SandboxMLCache;
@@ -42,14 +42,16 @@ import org.apache.ignite.ml.util.SandboxMLCache;
* After that it trains the model based on the specified data using
* <a href="https://en.wikipedia.org/wiki/K-nearest_neighbors_algorithm">kNN</a> regression algorithm.</p>
* <p>
- * Finally, this example loops over the test set of data points, applies the trained model to predict what cluster
- * does this point belong to, and compares prediction to expected outcome (ground truth).</p>
+ * Finally, this example loops over the test set of data points, applies the trained model to predict what cluster does
+ * this point belong to, and compares prediction to expected outcome (ground truth).</p>
* <p>
- * You can change the test data used in this example or trainer object settings and re-run it to explore
- * this algorithm further.</p>
+ * You can change the test data used in this example or trainer object settings and re-run it to explore this algorithm
+ * further.</p>
*/
public class KNNRegressionExample {
- /** Run example. */
+ /**
+ * Run example.
+ */
public static void main(String[] args) throws IOException {
System.out.println();
System.out.println(">>> kNN regression over cached dataset usage example started.");
@@ -76,14 +78,16 @@ public class KNNRegressionExample {
dataCache,
knnMdl,
vectorizer,
- new RegressionMetrics()
+ new Rmse()
);
System.out.println("\n>>> Rmse = " + rmse);
- } finally {
+ }
+ finally {
dataCache.destroy();
}
- } finally {
+ }
+ finally {
System.out.flush();
}
}
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/knn/package-info.java b/examples/src/main/java/org/apache/ignite/examples/ml/knn/package-info.java
index 8de4656..b8c8b21 100644
--- a/examples/src/main/java/org/apache/ignite/examples/ml/knn/package-info.java
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/knn/package-info.java
@@ -16,7 +16,6 @@
*/
/**
- * <!-- Package description. -->
- * kNN examples.
+ * <!-- Package description. --> kNN examples.
*/
package org.apache.ignite.examples.ml.knn;
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/multiclass/OneVsRestClassificationExample.java b/examples/src/main/java/org/apache/ignite/examples/ml/multiclass/OneVsRestClassificationExample.java
index 270ca7a..7201899 100644
--- a/examples/src/main/java/org/apache/ignite/examples/ml/multiclass/OneVsRestClassificationExample.java
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/multiclass/OneVsRestClassificationExample.java
@@ -56,7 +56,9 @@ import org.apache.ignite.ml.util.SandboxMLCache;
* smallest 3rd class could not be classified via linear SVM here.
*/
public class OneVsRestClassificationExample {
- /** Run example. */
+ /**
+ * Run example.
+ */
public static void main(String[] args) throws IOException {
System.out.println();
System.out.println(">>> One-vs-Rest SVM Multi-class classification model over cached dataset usage example started.");
@@ -158,11 +160,13 @@ public class OneVsRestClassificationExample {
System.out.println(">>> One-vs-Rest SVM model over cache based dataset usage example completed.");
}
- } finally {
+ }
+ finally {
if (dataCache != null)
dataCache.destroy();
}
- } finally {
+ }
+ finally {
System.out.flush();
}
}
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/multiclass/package-info.java b/examples/src/main/java/org/apache/ignite/examples/ml/multiclass/package-info.java
index dc1d8ad..0cb8ebe 100644
--- a/examples/src/main/java/org/apache/ignite/examples/ml/multiclass/package-info.java
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/multiclass/package-info.java
@@ -16,7 +16,6 @@
*/
/**
- * <!-- Package description. -->
- * Multi-class classification examples.
+ * <!-- Package description. --> Multi-class classification examples.
*/
package org.apache.ignite.examples.ml.multiclass;
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/naivebayes/CompoundNaiveBayesExample.java b/examples/src/main/java/org/apache/ignite/examples/ml/naivebayes/CompoundNaiveBayesExample.java
index 119c7aa..9109fca 100644
--- a/examples/src/main/java/org/apache/ignite/examples/ml/naivebayes/CompoundNaiveBayesExample.java
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/naivebayes/CompoundNaiveBayesExample.java
@@ -29,6 +29,7 @@ import org.apache.ignite.ml.naivebayes.compound.CompoundNaiveBayesTrainer;
import org.apache.ignite.ml.naivebayes.discrete.DiscreteNaiveBayesTrainer;
import org.apache.ignite.ml.naivebayes.gaussian.GaussianNaiveBayesTrainer;
import org.apache.ignite.ml.selection.scoring.evaluator.Evaluator;
+import org.apache.ignite.ml.selection.scoring.metric.MetricName;
import org.apache.ignite.ml.util.MLSandboxDatasets;
import org.apache.ignite.ml.util.SandboxMLCache;
@@ -84,8 +85,9 @@ public class CompoundNaiveBayesExample {
double accuracy = Evaluator.evaluate(
dataCache,
mdl,
- vectorizer
- ).accuracy();
+ vectorizer,
+ MetricName.ACCURACY
+ );
System.out.println("\n>>> Accuracy " + accuracy);
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/naivebayes/DiscreteNaiveBayesTrainerExample.java b/examples/src/main/java/org/apache/ignite/examples/ml/naivebayes/DiscreteNaiveBayesTrainerExample.java
index e2a3ee1..c62c53a 100644
--- a/examples/src/main/java/org/apache/ignite/examples/ml/naivebayes/DiscreteNaiveBayesTrainerExample.java
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/naivebayes/DiscreteNaiveBayesTrainerExample.java
@@ -27,6 +27,7 @@ import org.apache.ignite.ml.math.primitives.vector.Vector;
import org.apache.ignite.ml.naivebayes.discrete.DiscreteNaiveBayesModel;
import org.apache.ignite.ml.naivebayes.discrete.DiscreteNaiveBayesTrainer;
import org.apache.ignite.ml.selection.scoring.evaluator.Evaluator;
+import org.apache.ignite.ml.selection.scoring.metric.MetricName;
import org.apache.ignite.ml.util.MLSandboxDatasets;
import org.apache.ignite.ml.util.SandboxMLCache;
@@ -46,7 +47,9 @@ import org.apache.ignite.ml.util.SandboxMLCache;
* You can change the test data used in this example and re-run it to explore this algorithm further.</p>
*/
public class DiscreteNaiveBayesTrainerExample {
- /** Run example. */
+ /**
+ * Run example.
+ */
public static void main(String[] args) throws IOException {
System.out.println(">>> Discrete naive Bayes classification model over partitioned dataset usage example started.");
// Start ignite grid.
@@ -72,17 +75,20 @@ public class DiscreteNaiveBayesTrainerExample {
double accuracy = Evaluator.evaluate(
dataCache,
mdl,
- vectorizer
- ).accuracy();
+ vectorizer,
+ MetricName.ACCURACY
+ );
System.out.println("\n>>> Accuracy " + accuracy);
System.out.println(">>> Discrete Naive bayes model over partitioned dataset usage example completed.");
- } finally {
+ }
+ finally {
if (dataCache != null)
dataCache.destroy();
}
- } finally {
+ }
+ finally {
System.out.flush();
}
}
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/naivebayes/GaussianNaiveBayesTrainerExample.java b/examples/src/main/java/org/apache/ignite/examples/ml/naivebayes/GaussianNaiveBayesTrainerExample.java
index e117bb0..15ac6cb 100644
--- a/examples/src/main/java/org/apache/ignite/examples/ml/naivebayes/GaussianNaiveBayesTrainerExample.java
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/naivebayes/GaussianNaiveBayesTrainerExample.java
@@ -27,6 +27,7 @@ import org.apache.ignite.ml.math.primitives.vector.Vector;
import org.apache.ignite.ml.naivebayes.gaussian.GaussianNaiveBayesModel;
import org.apache.ignite.ml.naivebayes.gaussian.GaussianNaiveBayesTrainer;
import org.apache.ignite.ml.selection.scoring.evaluator.Evaluator;
+import org.apache.ignite.ml.selection.scoring.metric.MetricName;
import org.apache.ignite.ml.util.MLSandboxDatasets;
import org.apache.ignite.ml.util.SandboxMLCache;
@@ -46,7 +47,9 @@ import org.apache.ignite.ml.util.SandboxMLCache;
* You can change the test data used in this example and re-run it to explore this algorithm further.</p>
*/
public class GaussianNaiveBayesTrainerExample {
- /** Run example. */
+ /**
+ * Run example.
+ */
public static void main(String[] args) throws IOException {
System.out.println();
System.out.println(">>> Naive Bayes classification model over partitioned dataset usage example started.");
@@ -72,16 +75,19 @@ public class GaussianNaiveBayesTrainerExample {
double accuracy = Evaluator.evaluate(
dataCache,
mdl,
- vectorizer
- ).accuracy();
+ vectorizer,
+ MetricName.ACCURACY
+ );
System.out.println("\n>>> Accuracy " + accuracy);
System.out.println(">>> Naive bayes model over partitioned dataset usage example completed.");
- } finally {
+ }
+ finally {
dataCache.destroy();
}
- } finally {
+ }
+ finally {
System.out.flush();
}
}
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/naivebayes/package-info.java b/examples/src/main/java/org/apache/ignite/examples/ml/naivebayes/package-info.java
index 6d2b5ff..279ac28 100644
--- a/examples/src/main/java/org/apache/ignite/examples/ml/naivebayes/package-info.java
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/naivebayes/package-info.java
@@ -16,8 +16,7 @@
*/
/**
- * <!-- Package description. -->
- * ML naive Bayes classificator examples.
+ * <!-- Package description. --> ML naive Bayes classificator examples.
*/
package org.apache.ignite.examples.ml.naivebayes;
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/nn/MLPTrainerExample.java b/examples/src/main/java/org/apache/ignite/examples/ml/nn/MLPTrainerExample.java
index b777ab7..e3fe4b5 100644
--- a/examples/src/main/java/org/apache/ignite/examples/ml/nn/MLPTrainerExample.java
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/nn/MLPTrainerExample.java
@@ -127,20 +127,28 @@ public class MLPTrainerExample {
System.out.println("\n>>> Fail percentage: " + (failRatio * 100) + "%.");
System.out.println("\n>>> Distributed multilayer perceptron example completed.");
- } finally {
+ }
+ finally {
trainingSet.destroy();
}
- } finally {
+ }
+ finally {
System.out.flush();
}
}
- /** Point data class. */
+ /**
+ * Point data class.
+ */
private static class Point {
- /** X coordinate. */
+ /**
+ * X coordinate.
+ */
final double x;
- /** Y coordinate. */
+ /**
+ * Y coordinate.
+ */
final double y;
/**
@@ -155,16 +163,20 @@ public class MLPTrainerExample {
}
}
- /** Labeled point data class. */
+ /**
+ * Labeled point data class.
+ */
private static class LabeledPoint extends Point {
- /** Point label. */
+ /**
+ * Point label.
+ */
final double lb;
/**
* Constructs a new instance of labeled point data.
*
- * @param x X coordinate.
- * @param y Y coordinate.
+ * @param x X coordinate.
+ * @param y Y coordinate.
* @param lb Point label.
*/
LabeledPoint(double x, double y, double lb) {
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/nn/package-info.java b/examples/src/main/java/org/apache/ignite/examples/ml/nn/package-info.java
index 3a0ed29..d2c9f56 100644
--- a/examples/src/main/java/org/apache/ignite/examples/ml/nn/package-info.java
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/nn/package-info.java
@@ -16,7 +16,6 @@
*/
/**
- * <!-- Package description. -->
- * ML neural network examples.
+ * <!-- Package description. --> ML neural network examples.
*/
package org.apache.ignite.examples.ml.nn;
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/package-info.java b/examples/src/main/java/org/apache/ignite/examples/ml/package-info.java
index 0f45147..d0f08bc 100644
--- a/examples/src/main/java/org/apache/ignite/examples/ml/package-info.java
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/package-info.java
@@ -16,8 +16,7 @@
*/
/**
- * <!-- Package description. -->
- * Machine learning examples.
+ * <!-- Package description. --> Machine learning examples.
*/
package org.apache.ignite.examples.ml;
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/preprocessing/BinarizationExample.java b/examples/src/main/java/org/apache/ignite/examples/ml/preprocessing/BinarizationExample.java
index 3257ef3..1ff29ff 100644
--- a/examples/src/main/java/org/apache/ignite/examples/ml/preprocessing/BinarizationExample.java
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/preprocessing/BinarizationExample.java
@@ -40,13 +40,15 @@ import org.apache.ignite.ml.preprocessing.binarization.BinarizationTrainer;
* <p>
* After that it defines preprocessors that extract features from an upstream data and normalize features.</p>
* <p>
- * Finally, it creates the dataset based on the processed data and uses Dataset API to find and output
- * various statistical metrics of the data.</p>
+ * Finally, it creates the dataset based on the processed data and uses Dataset API to find and output various
+ * statistical metrics of the data.</p>
* <p>
* You can change the test data used in this example and re-run it to explore this functionality further.</p>
*/
public class BinarizationExample {
- /** Run example. */
+ /**
+ * Run example.
+ */
public static void main(String[] args) throws Exception {
try (Ignite ignite = Ignition.start("examples/config/example-ignite.xml")) {
System.out.println(">>> Binarization example started.");
@@ -68,15 +70,19 @@ public class BinarizationExample {
}
System.out.println(">>> Binarization example completed.");
- } finally {
+ }
+ finally {
data.destroy();
}
- } finally {
+ }
+ finally {
System.out.flush();
}
}
- /** */
+ /**
+ *
+ */
private static IgniteCache<Integer, Vector> createCache(Ignite ignite) {
CacheConfiguration<Integer, Vector> cacheConfiguration = new CacheConfiguration<>();
@@ -85,10 +91,10 @@ public class BinarizationExample {
IgniteCache<Integer, Vector> persons = ignite.createCache(cacheConfiguration);
- persons.put(1, new DenseVector(new Serializable[]{"Mike", 42, 10000}));
- persons.put(2, new DenseVector(new Serializable[]{"John", 32, 64000}));
- persons.put(3, new DenseVector(new Serializable[]{"George", 53, 120000}));
- persons.put(4, new DenseVector(new Serializable[]{"Karl", 24, 70000}));
+ persons.put(1, new DenseVector(new Serializable[] {"Mike", 42, 10000}));
+ persons.put(2, new DenseVector(new Serializable[] {"John", 32, 64000}));
+ persons.put(3, new DenseVector(new Serializable[] {"George", 53, 120000}));
+ persons.put(4, new DenseVector(new Serializable[] {"Karl", 24, 70000}));
return persons;
}
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/preprocessing/ImputingExample.java b/examples/src/main/java/org/apache/ignite/examples/ml/preprocessing/ImputingExample.java
index ee47976..eb29c84 100644
--- a/examples/src/main/java/org/apache/ignite/examples/ml/preprocessing/ImputingExample.java
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/preprocessing/ImputingExample.java
@@ -47,7 +47,9 @@ import org.apache.ignite.ml.preprocessing.imputing.ImputerTrainer;
* You can change the test data used in this example and re-run it to explore this functionality further.</p>
*/
public class ImputingExample {
- /** Run example. */
+ /**
+ * Run example.
+ */
public static void main(String[] args) throws Exception {
try (Ignite ignite = Ignition.start("examples/config/example-ignite.xml")) {
System.out.println(">>> Imputing example started.");
@@ -68,15 +70,19 @@ public class ImputingExample {
}
System.out.println(">>> Imputing example completed.");
- } finally {
+ }
+ finally {
data.destroy();
}
- } finally {
+ }
+ finally {
System.out.flush();
}
}
- /** */
+ /**
+ *
+ */
private static IgniteCache<Integer, Vector> createCache(Ignite ignite) {
CacheConfiguration<Integer, Vector> cacheConfiguration = new CacheConfiguration<>();
@@ -85,13 +91,13 @@ public class ImputingExample {
IgniteCache<Integer, Vector> persons = ignite.createCache(cacheConfiguration);
- persons.put(1, new DenseVector(new Serializable[]{"Mike", 10, 1}));
- persons.put(1, new DenseVector(new Serializable[]{"John", 20, 2}));
- persons.put(1, new DenseVector(new Serializable[]{"George", 15, 1}));
- persons.put(1, new DenseVector(new Serializable[]{"Piter", 25, Double.NaN}));
- persons.put(1, new DenseVector(new Serializable[]{"Karl", Double.NaN, 1}));
- persons.put(1, new DenseVector(new Serializable[]{"Gustaw", 20, 2}));
- persons.put(1, new DenseVector(new Serializable[]{"Alex", 20, 2}));
+ persons.put(1, new DenseVector(new Serializable[] {"Mike", 10, 1}));
+ persons.put(1, new DenseVector(new Serializable[] {"John", 20, 2}));
+ persons.put(1, new DenseVector(new Serializable[] {"George", 15, 1}));
+ persons.put(1, new DenseVector(new Serializable[] {"Piter", 25, Double.NaN}));
+ persons.put(1, new DenseVector(new Serializable[] {"Karl", Double.NaN, 1}));
+ persons.put(1, new DenseVector(new Serializable[] {"Gustaw", 20, 2}));
+ persons.put(1, new DenseVector(new Serializable[] {"Alex", 20, 2}));
return persons;
}
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/preprocessing/MaxAbsScalerExample.java b/examples/src/main/java/org/apache/ignite/examples/ml/preprocessing/MaxAbsScalerExample.java
index 9adc36d..b563a481 100644
--- a/examples/src/main/java/org/apache/ignite/examples/ml/preprocessing/MaxAbsScalerExample.java
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/preprocessing/MaxAbsScalerExample.java
@@ -35,13 +35,15 @@ import org.apache.ignite.ml.preprocessing.maxabsscaling.MaxAbsScalerTrainer;
/**
* Example that shows how to use MaxAbsScaler preprocessor to scale the given data.
- *
+ * <p>
* Machine learning preprocessors are built as a chain. Most often a first preprocessor is a feature extractor as shown
* in this example. The second preprocessor here is a MinMaxScaler preprocessor which is built on top of the feature
* extractor and represents a chain of itself and the underlying feature extractor.
*/
public class MaxAbsScalerExample {
- /** Run example. */
+ /**
+ * Run example.
+ */
public static void main(String[] args) throws Exception {
try (Ignite ignite = Ignition.start("examples/config/example-ignite.xml")) {
System.out.println(">>> Max abs example started.");
@@ -63,15 +65,19 @@ public class MaxAbsScalerExample {
}
System.out.println(">>> Max abs example completed.");
- } finally {
+ }
+ finally {
data.destroy();
}
- } finally {
+ }
+ finally {
System.out.flush();
}
}
- /** */
+ /**
+ *
+ */
private static IgniteCache<Integer, Vector> createCache(Ignite ignite) {
CacheConfiguration<Integer, Vector> cacheConfiguration = new CacheConfiguration<>();
@@ -80,10 +86,10 @@ public class MaxAbsScalerExample {
IgniteCache<Integer, Vector> persons = ignite.createCache(cacheConfiguration);
- persons.put(1, new DenseVector(new Serializable[]{"Mike", 42, 10000}));
- persons.put(2, new DenseVector(new Serializable[]{"John", 32, 64000}));
- persons.put(3, new DenseVector(new Serializable[]{"George", 53, 120000}));
- persons.put(4, new DenseVector(new Serializable[]{"Karl", 24, 70000}));
+ persons.put(1, new DenseVector(new Serializable[] {"Mike", 42, 10000}));
+ persons.put(2, new DenseVector(new Serializable[] {"John", 32, 64000}));
+ persons.put(3, new DenseVector(new Serializable[] {"George", 53, 120000}));
+ persons.put(4, new DenseVector(new Serializable[] {"Karl", 24, 70000}));
return persons;
}
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/preprocessing/MinMaxScalerExample.java b/examples/src/main/java/org/apache/ignite/examples/ml/preprocessing/MinMaxScalerExample.java
index e725918..89cf8da 100644
--- a/examples/src/main/java/org/apache/ignite/examples/ml/preprocessing/MinMaxScalerExample.java
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/preprocessing/MinMaxScalerExample.java
@@ -50,7 +50,9 @@ import org.apache.ignite.ml.preprocessing.minmaxscaling.MinMaxScalerTrainer;
* You can change the test data used in this example and re-run it to explore this functionality further.</p>
*/
public class MinMaxScalerExample {
- /** Run example. */
+ /**
+ * Run example.
+ */
public static void main(String[] args) throws Exception {
try (Ignite ignite = Ignition.start("examples/config/example-ignite.xml")) {
System.out.println(">>> MinMax preprocessing example started.");
@@ -72,15 +74,19 @@ public class MinMaxScalerExample {
}
System.out.println(">>> MinMax preprocessing example completed.");
- } finally {
+ }
+ finally {
data.destroy();
}
- } finally {
+ }
+ finally {
System.out.flush();
}
}
- /** */
+ /**
+ *
+ */
private static IgniteCache<Integer, Vector> createCache(Ignite ignite) {
CacheConfiguration<Integer, Vector> cacheConfiguration = new CacheConfiguration<>();
@@ -89,10 +95,10 @@ public class MinMaxScalerExample {
IgniteCache<Integer, Vector> persons = ignite.createCache(cacheConfiguration);
- persons.put(1, new DenseVector(new Serializable[]{"Mike", 42, 10000}));
- persons.put(2, new DenseVector(new Serializable[]{"John", 32, 64000}));
- persons.put(3, new DenseVector(new Serializable[]{"George", 53, 120000}));
- persons.put(4, new DenseVector(new Serializable[]{"Karl", 24, 70000}));
+ persons.put(1, new DenseVector(new Serializable[] {"Mike", 42, 10000}));
+ persons.put(2, new DenseVector(new Serializable[] {"John", 32, 64000}));
+ persons.put(3, new DenseVector(new Serializable[] {"George", 53, 120000}));
+ persons.put(4, new DenseVector(new Serializable[] {"Karl", 24, 70000}));
return persons;
}
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/preprocessing/NormalizationExample.java b/examples/src/main/java/org/apache/ignite/examples/ml/preprocessing/NormalizationExample.java
index 488e93d..d2eb546 100644
--- a/examples/src/main/java/org/apache/ignite/examples/ml/preprocessing/NormalizationExample.java
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/preprocessing/NormalizationExample.java
@@ -40,13 +40,15 @@ import org.apache.ignite.ml.preprocessing.normalization.NormalizationTrainer;
* <p>
* After that it defines preprocessors that extract features from an upstream data and normalize their values.</p>
* <p>
- * Finally, it creates the dataset based on the processed data and uses Dataset API to find and output
- * various statistical metrics of the data.</p>
+ * Finally, it creates the dataset based on the processed data and uses Dataset API to find and output various
+ * statistical metrics of the data.</p>
* <p>
* You can change the test data used in this example and re-run it to explore this functionality further.</p>
*/
public class NormalizationExample {
- /** Run example. */
+ /**
+ * Run example.
+ */
public static void main(String[] args) throws Exception {
try (Ignite ignite = Ignition.start("examples/config/example-ignite.xml")) {
System.out.println(">>> Normalization example started.");
@@ -69,15 +71,19 @@ public class NormalizationExample {
}
System.out.println(">>> Normalization example completed.");
- } finally {
+ }
+ finally {
data.destroy();
}
- } finally {
+ }
+ finally {
System.out.flush();
}
}
- /** */
+ /**
+ *
+ */
private static IgniteCache<Integer, Vector> createCache(Ignite ignite) {
CacheConfiguration<Integer, Vector> cacheConfiguration = new CacheConfiguration<>();
@@ -86,10 +92,10 @@ public class NormalizationExample {
IgniteCache<Integer, Vector> persons = ignite.createCache(cacheConfiguration);
- persons.put(1, new DenseVector(new Serializable[]{"Mike", 10, 20}));
- persons.put(2, new DenseVector(new Serializable[]{"John", 20, 10}));
- persons.put(3, new DenseVector(new Serializable[]{"George", 30, 0}));
- persons.put(4, new DenseVector(new Serializable[]{"Karl", 25, 15}));
+ persons.put(1, new DenseVector(new Serializable[] {"Mike", 10, 20}));
+ persons.put(2, new DenseVector(new Serializable[] {"John", 20, 10}));
+ persons.put(3, new DenseVector(new Serializable[] {"George", 30, 0}));
+ persons.put(4, new DenseVector(new Serializable[] {"Karl", 25, 15}));
return persons;
}
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/preprocessing/StandardScalerExample.java b/examples/src/main/java/org/apache/ignite/examples/ml/preprocessing/StandardScalerExample.java
index 280b6de..3ae0b9f 100644
--- a/examples/src/main/java/org/apache/ignite/examples/ml/preprocessing/StandardScalerExample.java
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/preprocessing/StandardScalerExample.java
@@ -35,13 +35,15 @@ import org.apache.ignite.ml.preprocessing.standardscaling.StandardScalerTrainer;
/**
* Example that shows how to use StandardScaler preprocessor to scale the given data.
- *
+ * <p>
* Machine learning preprocessors are built as a chain. Most often the first preprocessor is a feature extractor as
* shown in this example. The second preprocessor here is a {@code StandardScaler} preprocessor which is built on top of
* the feature extractor and represents a chain of itself and the underlying feature extractor.
*/
public class StandardScalerExample {
- /** Run example. */
+ /**
+ * Run example.
+ */
public static void main(String[] args) throws Exception {
try (Ignite ignite = Ignition.start("examples/config/example-ignite.xml")) {
System.out.println(">>> Standard scaler example started.");
@@ -63,15 +65,19 @@ public class StandardScalerExample {
}
System.out.println(">>> Standard scaler example completed.");
- } finally {
+ }
+ finally {
data.destroy();
}
- } finally {
+ }
+ finally {
System.out.flush();
}
}
- /** */
+ /**
+ *
+ */
private static IgniteCache<Integer, Vector> createCache(Ignite ignite) {
CacheConfiguration<Integer, Vector> cacheConfiguration = new CacheConfiguration<>();
@@ -80,10 +86,10 @@ public class StandardScalerExample {
IgniteCache<Integer, Vector> persons = ignite.createCache(cacheConfiguration);
- persons.put(1, new DenseVector(new Serializable[]{"Mike", 42, 10000}));
- persons.put(2, new DenseVector(new Serializable[]{"John", 32, 64000}));
- persons.put(3, new DenseVector(new Serializable[]{"George", 53, 120000}));
- persons.put(4, new DenseVector(new Serializable[]{"Karl", 24, 70000}));
+ persons.put(1, new DenseVector(new Serializable[] {"Mike", 42, 10000}));
+ persons.put(2, new DenseVector(new Serializable[] {"John", 32, 64000}));
+ persons.put(3, new DenseVector(new Serializable[] {"George", 53, 120000}));
+ persons.put(4, new DenseVector(new Serializable[] {"Karl", 24, 70000}));
return persons;
}
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/preprocessing/package-info.java b/examples/src/main/java/org/apache/ignite/examples/ml/preprocessing/package-info.java
index 5124132..8a643ac 100644
--- a/examples/src/main/java/org/apache/ignite/examples/ml/preprocessing/package-info.java
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/preprocessing/package-info.java
@@ -16,8 +16,7 @@
*/
/**
- * <!-- Package description. -->
- * Machine learning preprocessing examples.
+ * <!-- Package description. --> Machine learning preprocessing examples.
*/
package org.apache.ignite.examples.ml.preprocessing;
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/regression/linear/BostonHousePricesPredictionExample.java b/examples/src/main/java/org/apache/ignite/examples/ml/regression/linear/BostonHousePricesPredictionExample.java
index c4d13ea..b8bb6e5 100644
--- a/examples/src/main/java/org/apache/ignite/examples/ml/regression/linear/BostonHousePricesPredictionExample.java
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/regression/linear/BostonHousePricesPredictionExample.java
@@ -29,8 +29,7 @@ import org.apache.ignite.ml.math.primitives.vector.Vector;
import org.apache.ignite.ml.regressions.linear.LinearRegressionLSQRTrainer;
import org.apache.ignite.ml.regressions.linear.LinearRegressionModel;
import org.apache.ignite.ml.selection.scoring.evaluator.Evaluator;
-import org.apache.ignite.ml.selection.scoring.metric.regression.RegressionMetricValues;
-import org.apache.ignite.ml.selection.scoring.metric.regression.RegressionMetrics;
+import org.apache.ignite.ml.selection.scoring.metric.MetricName;
import org.apache.ignite.ml.selection.split.TrainTestDatasetSplitter;
import org.apache.ignite.ml.selection.split.TrainTestSplit;
import org.apache.ignite.ml.trainers.DatasetTrainer;
@@ -39,15 +38,17 @@ import org.apache.ignite.ml.util.SandboxMLCache;
/**
* Example of using Linear Regression model in Apache Ignite for house prices prediction.
- *
- * Description of model can be found in: https://en.wikipedia.org/wiki/Linear_regression .
- * Original dataset can be downloaded from: https://archive.ics.uci.edu/ml/machine-learning-databases/housing/ .
- * Copy of dataset are stored in: modules/ml/src/main/resources/datasets/boston_housing_dataset.txt .
- * Score for regression estimation: R^2 (coefficient of determination).
- * Description of score evaluation can be found in: https://stattrek.com/statistics/dictionary.aspx?definition=coefficient_of_determination .
+ * <p>
+ * Description of model can be found in: https://en.wikipedia.org/wiki/Linear_regression . Original dataset can be
+ * downloaded from: https://archive.ics.uci.edu/ml/machine-learning-databases/housing/ . Copy of dataset are stored in:
+ * modules/ml/src/main/resources/datasets/boston_housing_dataset.txt . Score for regression estimation: R^2 (coefficient
+ * of determination). Description of score evaluation can be found in: https://stattrek.com/statistics/dictionary.aspx?definition=coefficient_of_determination
+ * .
*/
public class BostonHousePricesPredictionExample {
- /** Runs example. */
+ /**
+ * Runs example.
+ */
public static void main(String[] args) throws IOException {
try (Ignite ignite = Ignition.start("examples/config/example-ignite.xml")) {
System.out.println(">>> Ignite grid started.");
@@ -79,22 +80,25 @@ public class BostonHousePricesPredictionExample {
split.getTestFilter(),
mdl,
vectorizer,
- new RegressionMetrics().withMetric(RegressionMetricValues::r2)
+ MetricName.R2
);
System.out.println(">>> Model: " + toString(mdl));
System.out.println(">>> R^2 score: " + score);
- } finally {
+ }
+ finally {
if (dataCache != null)
dataCache.destroy();
}
- } finally {
+ }
+ finally {
System.out.flush();
}
}
/**
* Prepare pretty string for model.
+ *
* @param mdl Model.
* @return String representation of model.
*/
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/regression/linear/LinearRegressionLSQRTrainerExample.java b/examples/src/main/java/org/apache/ignite/examples/ml/regression/linear/LinearRegressionLSQRTrainerExample.java
index 3bc3885..523400a 100644
--- a/examples/src/main/java/org/apache/ignite/examples/ml/regression/linear/LinearRegressionLSQRTrainerExample.java
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/regression/linear/LinearRegressionLSQRTrainerExample.java
@@ -27,7 +27,7 @@ import org.apache.ignite.ml.math.primitives.vector.Vector;
import org.apache.ignite.ml.regressions.linear.LinearRegressionLSQRTrainer;
import org.apache.ignite.ml.regressions.linear.LinearRegressionModel;
import org.apache.ignite.ml.selection.scoring.evaluator.Evaluator;
-import org.apache.ignite.ml.selection.scoring.metric.regression.RegressionMetrics;
+import org.apache.ignite.ml.selection.scoring.metric.MetricName;
import org.apache.ignite.ml.util.MLSandboxDatasets;
import org.apache.ignite.ml.util.SandboxMLCache;
@@ -45,7 +45,9 @@ import org.apache.ignite.ml.util.SandboxMLCache;
* You can change the test data used in this example and re-run it to explore this algorithm further.</p>
*/
public class LinearRegressionLSQRTrainerExample {
- /** Run example. */
+ /**
+ * Run example.
+ */
public static void main(String[] args) throws IOException {
System.out.println();
System.out.println(">>> Linear regression model over cache based dataset usage example started.");
@@ -75,20 +77,20 @@ public class LinearRegressionLSQRTrainerExample {
.labeled(Vectorizer.LabelCoordinate.FIRST));
double rmse = Evaluator.evaluate(
- dataCache,
- mdl,
- new DummyVectorizer<Integer>()
- .labeled(Vectorizer.LabelCoordinate.FIRST),
- new RegressionMetrics()
+ dataCache, mdl,
+ new DummyVectorizer<Integer>().labeled(Vectorizer.LabelCoordinate.FIRST),
+ MetricName.RMSE
);
System.out.println("\n>>> Rmse = " + rmse);
System.out.println(">>> Linear regression model over cache based dataset usage example completed.");
- } finally {
+ }
+ finally {
dataCache.destroy();
}
- } finally {
+ }
+ finally {
System.out.flush();
}
}
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/regression/linear/LinearRegressionLSQRTrainerWithMinMaxScalerExample.java b/examples/src/main/java/org/apache/ignite/examples/ml/regression/linear/LinearRegressionLSQRTrainerWithMinMaxScalerExample.java
index ef40fe6..94c94b1 100644
--- a/examples/src/main/java/org/apache/ignite/examples/ml/regression/linear/LinearRegressionLSQRTrainerWithMinMaxScalerExample.java
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/regression/linear/LinearRegressionLSQRTrainerWithMinMaxScalerExample.java
@@ -30,20 +30,20 @@ import org.apache.ignite.ml.preprocessing.minmaxscaling.MinMaxScalerTrainer;
import org.apache.ignite.ml.regressions.linear.LinearRegressionLSQRTrainer;
import org.apache.ignite.ml.regressions.linear.LinearRegressionModel;
import org.apache.ignite.ml.selection.scoring.evaluator.Evaluator;
-import org.apache.ignite.ml.selection.scoring.metric.regression.RegressionMetrics;
+import org.apache.ignite.ml.selection.scoring.metric.MetricName;
import org.apache.ignite.ml.util.MLSandboxDatasets;
import org.apache.ignite.ml.util.SandboxMLCache;
/**
* Run linear regression model based on <a href="http://web.stanford.edu/group/SOL/software/lsqr/">LSQR algorithm</a>
- * ({@link LinearRegressionLSQRTrainer}) over cached dataset that was created using
- * a minmaxscaling preprocessor ({@link MinMaxScalerTrainer}, {@link MinMaxScalerPreprocessor}).
+ * ({@link LinearRegressionLSQRTrainer}) over cached dataset that was created using a minmaxscaling preprocessor ({@link
+ * MinMaxScalerTrainer}, {@link MinMaxScalerPreprocessor}).
* <p>
- * Code in this example launches Ignite grid, fills the cache with simple test data, and defines minmaxscaling
- * trainer and preprocessor.</p>
+ * Code in this example launches Ignite grid, fills the cache with simple test data, and defines minmaxscaling trainer
+ * and preprocessor.</p>
* <p>
- * After that it trains the linear regression model based on the specified data that has been processed
- * using minmaxscaling.</p>
+ * After that it trains the linear regression model based on the specified data that has been processed using
+ * minmaxscaling.</p>
* <p>
* Finally, this example loops over the test set of data points, applies the trained model to predict predict the target
* value and compares prediction to expected outcome (ground truth).</p>
@@ -51,7 +51,9 @@ import org.apache.ignite.ml.util.SandboxMLCache;
* You can change the test data used in this example and re-run it to explore this algorithm further.</p>
*/
public class LinearRegressionLSQRTrainerWithMinMaxScalerExample {
- /** Run example. */
+ /**
+ * Run example.
+ */
public static void main(String[] args) throws IOException {
System.out.println();
System.out.println(">>> Linear regression model with Min Max Scaling preprocessor over cached dataset usage example started.");
@@ -85,22 +87,19 @@ public class LinearRegressionLSQRTrainerWithMinMaxScalerExample {
System.out.println(">>> Linear regression model: " + mdl);
- double rmse = Evaluator.evaluate(
- dataCache,
- mdl,
- preprocessor,
- new RegressionMetrics()
- );
+ double rmse = Evaluator.evaluate(dataCache, mdl, preprocessor, MetricName.RMSE);
System.out.println("\n>>> Rmse = " + rmse);
System.out.println(">>> ---------------------------------");
System.out.println(">>> Linear regression model with MinMaxScaler preprocessor over cache based dataset usage example completed.");
- } finally {
+ }
+ finally {
if (dataCache != null)
dataCache.destroy();
}
- } finally {
+ }
+ finally {
System.out.flush();
}
}
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/regression/linear/LinearRegressionSGDTrainerExample.java b/examples/src/main/java/org/apache/ignite/examples/ml/regression/linear/LinearRegressionSGDTrainerExample.java
index b7a3f31..2b59d6a 100644
--- a/examples/src/main/java/org/apache/ignite/examples/ml/regression/linear/LinearRegressionSGDTrainerExample.java
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/regression/linear/LinearRegressionSGDTrainerExample.java
@@ -30,7 +30,7 @@ import org.apache.ignite.ml.optimization.updatecalculators.RPropUpdateCalculator
import org.apache.ignite.ml.regressions.linear.LinearRegressionModel;
import org.apache.ignite.ml.regressions.linear.LinearRegressionSGDTrainer;
import org.apache.ignite.ml.selection.scoring.evaluator.Evaluator;
-import org.apache.ignite.ml.selection.scoring.metric.regression.RegressionMetrics;
+import org.apache.ignite.ml.selection.scoring.metric.MetricName;
import org.apache.ignite.ml.util.MLSandboxDatasets;
import org.apache.ignite.ml.util.SandboxMLCache;
@@ -41,8 +41,8 @@ import org.apache.ignite.ml.util.SandboxMLCache;
* <p>
* Code in this example launches Ignite grid and fills the cache with simple test data.</p>
* <p>
- * After that it trains the linear regression model based on stochastic gradient descent algorithm using
- * the specified data.</p>
+ * After that it trains the linear regression model based on stochastic gradient descent algorithm using the specified
+ * data.</p>
* <p>
* Finally, this example loops over the test set of data points, applies the trained model to predict the target value
* and compares prediction to expected outcome (ground truth).</p>
@@ -50,7 +50,9 @@ import org.apache.ignite.ml.util.SandboxMLCache;
* You can change the test data used in this example and re-run it to explore this algorithm further.</p>
*/
public class LinearRegressionSGDTrainerExample {
- /** Run example. */
+ /**
+ * Run example.
+ */
public static void main(String[] args) throws IOException {
System.out.println();
System.out.println(">>> Linear regression model over sparse distributed matrix API usage example started.");
@@ -78,21 +80,18 @@ public class LinearRegressionSGDTrainerExample {
System.out.println(">>> Linear regression model: " + mdl);
- double rmse = Evaluator.evaluate(
- dataCache,
- mdl,
- vectorizer,
- new RegressionMetrics()
- );
+ double rmse = Evaluator.evaluate(dataCache, mdl, vectorizer, MetricName.RMSE);
System.out.println("\n>>> Rmse = " + rmse);
System.out.println(">>> ---------------------------------");
System.out.println(">>> Linear regression model over cache based dataset usage example completed.");
- } finally {
+ }
+ finally {
dataCache.destroy();
}
- } finally {
+ }
+ finally {
System.out.flush();
}
}
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/regression/linear/package-info.java b/examples/src/main/java/org/apache/ignite/examples/ml/regression/linear/package-info.java
index d0441a4..330f8c1 100644
--- a/examples/src/main/java/org/apache/ignite/examples/ml/regression/linear/package-info.java
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/regression/linear/package-info.java
@@ -16,7 +16,6 @@
*/
/**
- * <!-- Package description. -->
- * ML linear regression examples.
+ * <!-- Package description. --> ML linear regression examples.
*/
package org.apache.ignite.examples.ml.regression.linear;
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/regression/logistic/bagged/BaggedLogisticRegressionSGDTrainerExample.java b/examples/src/main/java/org/apache/ignite/examples/ml/regression/logistic/bagged/BaggedLogisticRegressionSGDTrainerExample.java
index 935c54b..daa0c15 100644
--- a/examples/src/main/java/org/apache/ignite/examples/ml/regression/logistic/bagged/BaggedLogisticRegressionSGDTrainerExample.java
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/regression/logistic/bagged/BaggedLogisticRegressionSGDTrainerExample.java
@@ -18,11 +18,9 @@
package org.apache.ignite.examples.ml.regression.logistic.bagged;
import java.io.IOException;
-import java.util.Arrays;
import org.apache.ignite.Ignite;
import org.apache.ignite.IgniteCache;
import org.apache.ignite.Ignition;
-import org.apache.ignite.ml.composition.bagging.BaggedModel;
import org.apache.ignite.ml.composition.bagging.BaggedTrainer;
import org.apache.ignite.ml.composition.predictionsaggregator.OnMajorityPredictionsAggregator;
import org.apache.ignite.ml.dataset.feature.extractor.Vectorizer;
@@ -33,27 +31,29 @@ import org.apache.ignite.ml.nn.UpdatesStrategy;
import org.apache.ignite.ml.optimization.updatecalculators.SimpleGDParameterUpdate;
import org.apache.ignite.ml.optimization.updatecalculators.SimpleGDUpdateCalculator;
import org.apache.ignite.ml.regressions.logistic.LogisticRegressionSGDTrainer;
-import org.apache.ignite.ml.selection.cv.CrossValidation;
-import org.apache.ignite.ml.selection.scoring.metric.classification.Accuracy;
+import org.apache.ignite.ml.selection.scoring.evaluator.Evaluator;
+import org.apache.ignite.ml.selection.scoring.metric.MetricName;
import org.apache.ignite.ml.trainers.TrainerTransformers;
import org.apache.ignite.ml.util.MLSandboxDatasets;
import org.apache.ignite.ml.util.SandboxMLCache;
/**
- * This example shows how bagging technique may be applied to arbitrary trainer.
- * As an example (a bit synthetic) logistic regression is considered.
+ * This example shows how bagging technique may be applied to arbitrary trainer. As an example (a bit synthetic)
+ * logistic regression is considered.
* <p>
* Code in this example launches Ignite grid and fills the cache with test data points (based on the
* <a href="https://en.wikipedia.org/wiki/Iris_flower_data_set"></a>Iris dataset</a>).</p>
* <p>
- * After that it trains bootstrapped (or bagged) version of logistic regression trainer. Bootstrapping is done
- * on both samples and features (<a href="https://en.wikipedia.org/wiki/Bootstrap_aggregating"></a>Samples bagging</a>,
+ * After that it trains bootstrapped (or bagged) version of logistic regression trainer. Bootstrapping is done on both
+ * samples and features (<a href="https://en.wikipedia.org/wiki/Bootstrap_aggregating"></a>Samples bagging</a>,
* <a href="https://en.wikipedia.org/wiki/Random_subspace_method"></a>Features bagging</a>).</p>
* <p>
* Finally, this example applies cross-validation to resulted model and prints accuracy if each fold.</p>
*/
public class BaggedLogisticRegressionSGDTrainerExample {
- /** Run example. */
+ /**
+ * Run example.
+ */
public static void main(String[] args) throws IOException {
System.out.println();
System.out.println(">>> Logistic regression model over partitioned dataset usage example started.");
@@ -72,8 +72,8 @@ public class BaggedLogisticRegressionSGDTrainerExample {
SimpleGDParameterUpdate.SUM_LOCAL,
SimpleGDParameterUpdate.AVG
))
- .withMaxIterations(100000)
- .withLocIterations(100)
+ .withMaxIterations(100)
+ .withLocIterations(10)
.withBatchSize(10)
.withSeed(123L);
@@ -93,26 +93,24 @@ public class BaggedLogisticRegressionSGDTrainerExample {
Vectorizer<Integer, Vector, Integer, Double> vectorizer = new DummyVectorizer<Integer>()
.labeled(Vectorizer.LabelCoordinate.FIRST);
- double[] score = new CrossValidation<BaggedModel, Double, Integer, Vector>()
- .withIgnite(ignite)
- .withUpstreamCache(dataCache)
- .withTrainer(baggedTrainer)
- .withMetric(new Accuracy<>())
- .withPreprocessor(vectorizer)
- .withAmountOfFolds(3)
- .isRunningOnPipeline(false)
- .scoreByFolds();
+ double accuracy = Evaluator.evaluate(dataCache,
+ baggedTrainer.fit(ignite, dataCache, vectorizer),
+ vectorizer,
+ MetricName.ACCURACY
+ );
System.out.println(">>> ---------------------------------");
- Arrays.stream(score).forEach(sc -> System.out.println("\n>>> Accuracy " + sc));
+ System.out.println("\n>>> Accuracy " + accuracy);
System.out.println(">>> Bagged logistic regression model over partitioned dataset usage example completed.");
- } finally {
+ }
+ finally {
if (dataCache != null)
dataCache.destroy();
}
- } finally {
+ }
+ finally {
System.out.flush();
}
}
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/regression/logistic/bagged/package-info.java b/examples/src/main/java/org/apache/ignite/examples/ml/regression/logistic/bagged/package-info.java
index ea0d19e..ecef02a 100644
--- a/examples/src/main/java/org/apache/ignite/examples/ml/regression/logistic/bagged/package-info.java
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/regression/logistic/bagged/package-info.java
@@ -16,7 +16,6 @@
*/
/**
- * <!-- Package description. -->
- * ML bagged logistic regression examples.
+ * <!-- Package description. --> ML bagged logistic regression examples.
*/
package org.apache.ignite.examples.ml.regression.logistic.bagged;
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/regression/logistic/binary/LogisticRegressionSGDTrainerExample.java b/examples/src/main/java/org/apache/ignite/examples/ml/regression/logistic/binary/LogisticRegressionSGDTrainerExample.java
index e3441ec..f6a4b09 100644
--- a/examples/src/main/java/org/apache/ignite/examples/ml/regression/logistic/binary/LogisticRegressionSGDTrainerExample.java
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/regression/logistic/binary/LogisticRegressionSGDTrainerExample.java
@@ -30,6 +30,7 @@ import org.apache.ignite.ml.optimization.updatecalculators.SimpleGDUpdateCalcula
import org.apache.ignite.ml.regressions.logistic.LogisticRegressionModel;
import org.apache.ignite.ml.regressions.logistic.LogisticRegressionSGDTrainer;
import org.apache.ignite.ml.selection.scoring.evaluator.Evaluator;
+import org.apache.ignite.ml.selection.scoring.metric.MetricName;
import org.apache.ignite.ml.util.MLSandboxDatasets;
import org.apache.ignite.ml.util.SandboxMLCache;
@@ -49,7 +50,9 @@ import org.apache.ignite.ml.util.SandboxMLCache;
* You can change the test data used in this example and re-run it to explore this algorithm further.</p>
*/
public class LogisticRegressionSGDTrainerExample {
- /** Run example. */
+ /**
+ * Run example.
+ */
public static void main(String[] args) throws IOException {
System.out.println();
System.out.println(">>> Logistic regression model over partitioned dataset usage example started.");
@@ -81,20 +84,20 @@ public class LogisticRegressionSGDTrainerExample {
System.out.println(">>> Logistic regression model: " + mdl);
- double accuracy = Evaluator.evaluate(
- dataCache,
- mdl,
- vectorizer
- ).accuracy();
+ double accuracy = Evaluator.evaluate(dataCache,
+ mdl, vectorizer, MetricName.ACCURACY
+ );
System.out.println("\n>>> Accuracy " + accuracy);
System.out.println(">>> Logistic regression model over partitioned dataset usage example completed.");
- } finally {
+ }
+ finally {
if (dataCache != null)
dataCache.destroy();
}
- } finally {
+ }
+ finally {
System.out.flush();
}
}
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/regression/logistic/binary/package-info.java b/examples/src/main/java/org/apache/ignite/examples/ml/regression/logistic/binary/package-info.java
index 6ea42e7..b18c502a 100644
--- a/examples/src/main/java/org/apache/ignite/examples/ml/regression/logistic/binary/package-info.java
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/regression/logistic/binary/package-info.java
@@ -16,7 +16,6 @@
*/
/**
- * <!-- Package description. -->
- * ML binary logistic regression examples.
+ * <!-- Package description. --> ML binary logistic regression examples.
*/
package org.apache.ignite.examples.ml.regression.logistic.binary;
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/regression/logistic/package-info.java b/examples/src/main/java/org/apache/ignite/examples/ml/regression/logistic/package-info.java
index cf27a94..f069eb3 100644
--- a/examples/src/main/java/org/apache/ignite/examples/ml/regression/logistic/package-info.java
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/regression/logistic/package-info.java
@@ -16,7 +16,6 @@
*/
/**
- * <!-- Package description. -->
- * ML logistic regression examples.
+ * <!-- Package description. --> ML logistic regression examples.
*/
package org.apache.ignite.examples.ml.regression.logistic;
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/regression/package-info.java b/examples/src/main/java/org/apache/ignite/examples/ml/regression/package-info.java
index c89c80c..c2cc55f 100644
--- a/examples/src/main/java/org/apache/ignite/examples/ml/regression/package-info.java
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/regression/package-info.java
@@ -16,7 +16,6 @@
*/
/**
- * <!-- Package description. -->
- * ML regression examples.
+ * <!-- Package description. --> ML regression examples.
*/
package org.apache.ignite.examples.ml.regression;
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/selection/cv/CrossValidationExample.java b/examples/src/main/java/org/apache/ignite/examples/ml/selection/cv/CrossValidationExample.java
index 514ed6b..e6a4461 100644
--- a/examples/src/main/java/org/apache/ignite/examples/ml/selection/cv/CrossValidationExample.java
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/selection/cv/CrossValidationExample.java
@@ -27,9 +27,7 @@ import org.apache.ignite.configuration.CacheConfiguration;
import org.apache.ignite.ml.dataset.feature.extractor.impl.LabeledDummyVectorizer;
import org.apache.ignite.ml.math.primitives.vector.VectorUtils;
import org.apache.ignite.ml.selection.cv.CrossValidation;
-import org.apache.ignite.ml.selection.scoring.metric.classification.Accuracy;
-import org.apache.ignite.ml.selection.scoring.metric.classification.BinaryClassificationMetricValues;
-import org.apache.ignite.ml.selection.scoring.metric.classification.BinaryClassificationMetrics;
+import org.apache.ignite.ml.selection.scoring.metric.MetricName;
import org.apache.ignite.ml.structures.LabeledVector;
import org.apache.ignite.ml.tree.DecisionTreeClassificationTrainer;
import org.apache.ignite.ml.tree.DecisionTreeNode;
@@ -77,14 +75,14 @@ public class CrossValidationExample {
LabeledDummyVectorizer<Integer, Double> vectorizer = new LabeledDummyVectorizer<>();
- CrossValidation<DecisionTreeNode, Double, Integer, LabeledVector<Double>> scoreCalculator
+ CrossValidation<DecisionTreeNode, Integer, LabeledVector<Double>> scoreCalculator
= new CrossValidation<>();
double[] accuracyScores = scoreCalculator
.withIgnite(ignite)
.withUpstreamCache(trainingSet)
.withTrainer(trainer)
- .withMetric(new Accuracy<>())
+ .withMetric(MetricName.ACCURACY)
.withPreprocessor(vectorizer)
.withAmountOfFolds(4)
.isRunningOnPipeline(false)
@@ -92,22 +90,19 @@ public class CrossValidationExample {
System.out.println(">>> Accuracy: " + Arrays.toString(accuracyScores));
- BinaryClassificationMetrics metrics = (BinaryClassificationMetrics)new BinaryClassificationMetrics()
- .withNegativeClsLb(0.0)
- .withPositiveClsLb(1.0)
- .withMetric(BinaryClassificationMetricValues::balancedAccuracy);
-
double[] balancedAccuracyScores = scoreCalculator
- .withMetric(metrics)
+ .withMetric(MetricName.ACCURACY)
.scoreByFolds();
System.out.println(">>> Balanced Accuracy: " + Arrays.toString(balancedAccuracyScores));
System.out.println(">>> Cross validation score calculator example completed.");
- } finally {
+ }
+ finally {
trainingSet.destroy();
}
- } finally {
+ }
+ finally {
System.out.flush();
}
}
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/selection/cv/package-info.java b/examples/src/main/java/org/apache/ignite/examples/ml/selection/cv/package-info.java
index 249d8b8..92005aa 100644
--- a/examples/src/main/java/org/apache/ignite/examples/ml/selection/cv/package-info.java
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/selection/cv/package-info.java
@@ -16,7 +16,6 @@
*/
/**
- * <!-- Package description. -->
- * ML cross validation examples.
+ * <!-- Package description. --> ML cross validation examples.
*/
package org.apache.ignite.examples.ml.selection.cv;
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/selection/package-info.java b/examples/src/main/java/org/apache/ignite/examples/ml/selection/package-info.java
index c3a264a..f1adde8 100644
--- a/examples/src/main/java/org/apache/ignite/examples/ml/selection/package-info.java
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/selection/package-info.java
@@ -16,7 +16,6 @@
*/
/**
- * <!-- Package description. -->
- * ML model selection examples.
+ * <!-- Package description. --> ML model selection examples.
*/
package org.apache.ignite.examples.ml.selection;
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/selection/scoring/EvaluatorExample.java b/examples/src/main/java/org/apache/ignite/examples/ml/selection/scoring/EvaluatorExample.java
index b9638ca..bf23fc3 100644
--- a/examples/src/main/java/org/apache/ignite/examples/ml/selection/scoring/EvaluatorExample.java
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/selection/scoring/EvaluatorExample.java
@@ -25,7 +25,6 @@ import org.apache.ignite.ml.dataset.feature.extractor.Vectorizer;
import org.apache.ignite.ml.dataset.feature.extractor.impl.DummyVectorizer;
import org.apache.ignite.ml.math.primitives.vector.Vector;
import org.apache.ignite.ml.selection.scoring.evaluator.Evaluator;
-import org.apache.ignite.ml.selection.scoring.metric.classification.Accuracy;
import org.apache.ignite.ml.svm.SVMLinearClassificationModel;
import org.apache.ignite.ml.svm.SVMLinearClassificationTrainer;
import org.apache.ignite.ml.util.MLSandboxDatasets;
@@ -40,13 +39,15 @@ import org.apache.ignite.ml.util.SandboxMLCache;
* After that it trains the model based on the specified data using
* <a href="https://en.wikipedia.org/wiki/K-nearest_neighbors_algorithm">kNN</a> algorithm.</p>
* <p>
- * Finally, this example loops over the test set of data points, applies the trained model to predict what cluster
- * does this point belong to, and compares prediction to expected outcome (ground truth).</p>
+ * Finally, this example loops over the test set of data points, applies the trained model to predict what cluster does
+ * this point belong to, and compares prediction to expected outcome (ground truth).</p>
* <p>
* You can change the test data used in this example and re-run it to explore this algorithm further.</p>
*/
public class EvaluatorExample {
- /** Run example. */
+ /**
+ * Run example.
+ */
public static void main(String[] args) throws IOException {
System.out.println();
System.out.println(">>> kNN multi-class classification algorithm over cached dataset usage example started.");
@@ -65,26 +66,13 @@ public class EvaluatorExample {
SVMLinearClassificationModel mdl = trainer.fit(ignite, dataCache, vectorizer);
- double accuracy = Evaluator.evaluate(
- dataCache,
- mdl,
- vectorizer,
- new Accuracy<>()
- );
-
- System.out.println("\n>>> Accuracy " + accuracy);
-
- double f1Score = Evaluator.evaluate(
- dataCache,
- mdl,
- vectorizer
- ).f1Score();
-
- System.out.println("\n>>> F1-Score " + f1Score);
- } finally {
+ System.out.println(Evaluator.evaluateBinaryClassification(dataCache, mdl, vectorizer));
+ }
+ finally {
dataCache.destroy();
}
- } finally {
+ }
+ finally {
System.out.flush();
}
}
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/selection/scoring/MultipleMetricsExample.java b/examples/src/main/java/org/apache/ignite/examples/ml/selection/scoring/MultipleMetricsExample.java
index e213bb0..7d24afd 100644
--- a/examples/src/main/java/org/apache/ignite/examples/ml/selection/scoring/MultipleMetricsExample.java
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/selection/scoring/MultipleMetricsExample.java
@@ -18,7 +18,6 @@
package org.apache.ignite.examples.ml.selection.scoring;
import java.io.IOException;
-import java.util.Map;
import org.apache.ignite.Ignite;
import org.apache.ignite.IgniteCache;
import org.apache.ignite.Ignition;
@@ -41,13 +40,15 @@ import org.apache.ignite.ml.util.SandboxMLCache;
* After that it trains the model based on the specified data using
* <a href="https://en.wikipedia.org/wiki/K-nearest_neighbors_algorithm">kNN</a> algorithm.</p>
* <p>
- * Finally, this example loops over the test set of data points, applies the trained model to predict what cluster
- * does this point belong to, and compares prediction to expected outcome (ground truth).</p>
+ * Finally, this example loops over the test set of data points, applies the trained model to predict what cluster does
+ * this point belong to, and compares prediction to expected outcome (ground truth).</p>
* <p>
* You can change the test data used in this example and re-run it to explore this algorithm further.</p>
*/
public class MultipleMetricsExample {
- /** Run example. */
+ /**
+ * Run example.
+ */
public static void main(String[] args) throws IOException {
// Start ignite grid.
try (Ignite ignite = Ignition.start("examples/config/example-ignite.xml")) {
@@ -64,19 +65,13 @@ public class MultipleMetricsExample {
SVMLinearClassificationModel mdl = trainer.fit(ignite, dataCache, vectorizer);
- Map<String, Double> scores = Evaluator.evaluate(
- dataCache,
- mdl,
- vectorizer
- ).toMap();
-
- scores.forEach(
- (metricName, score) -> System.out.println("\n>>>" + metricName + ": " + score)
- );
- } finally {
+ System.out.println(Evaluator.evaluateBinaryClassification(dataCache, mdl, vectorizer));
+ }
+ finally {
dataCache.destroy();
}
- } finally {
+ }
+ finally {
System.out.flush();
}
}
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/selection/scoring/RegressionMetricExample.java b/examples/src/main/java/org/apache/ignite/examples/ml/selection/scoring/RegressionMetricExample.java
index 7e4f36f..5523d9a 100644
--- a/examples/src/main/java/org/apache/ignite/examples/ml/selection/scoring/RegressionMetricExample.java
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/selection/scoring/RegressionMetricExample.java
@@ -29,8 +29,7 @@ import org.apache.ignite.ml.knn.utils.indices.SpatialIndexType;
import org.apache.ignite.ml.math.distances.ManhattanDistance;
import org.apache.ignite.ml.math.primitives.vector.Vector;
import org.apache.ignite.ml.selection.scoring.evaluator.Evaluator;
-import org.apache.ignite.ml.selection.scoring.metric.regression.RegressionMetricValues;
-import org.apache.ignite.ml.selection.scoring.metric.regression.RegressionMetrics;
+import org.apache.ignite.ml.selection.scoring.metric.MetricName;
import org.apache.ignite.ml.util.MLSandboxDatasets;
import org.apache.ignite.ml.util.SandboxMLCache;
@@ -47,7 +46,9 @@ import org.apache.ignite.ml.util.SandboxMLCache;
* further.</p>
*/
public class RegressionMetricExample {
- /** Run example. */
+ /**
+ * Run example.
+ */
public static void main(String[] args) throws IOException {
System.out.println();
System.out.println(">>> kNN regression over cached dataset usage example started.");
@@ -70,18 +71,17 @@ public class RegressionMetricExample {
KNNRegressionModel knnMdl = (KNNRegressionModel)trainer.fit(ignite, dataCache, vectorizer);
- double mae = Evaluator.evaluate(
- dataCache,
- knnMdl,
- vectorizer,
- new RegressionMetrics().withMetric(RegressionMetricValues::mae)
+ double mae = Evaluator.evaluate(dataCache,
+ knnMdl, vectorizer, MetricName.MAE
);
System.out.println("\n>>> Mae " + mae);
- } finally {
+ }
+ finally {
dataCache.destroy();
}
- } finally {
+ }
+ finally {
System.out.flush();
}
}
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/selection/split/TrainTestDatasetSplitterExample.java b/examples/src/main/java/org/apache/ignite/examples/ml/selection/split/TrainTestDatasetSplitterExample.java
index 17f53e3..04fe5e0 100644
--- a/examples/src/main/java/org/apache/ignite/examples/ml/selection/split/TrainTestDatasetSplitterExample.java
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/selection/split/TrainTestDatasetSplitterExample.java
@@ -39,8 +39,8 @@ import org.apache.ignite.ml.util.SandboxMLCache;
* <p>
* Code in this example launches Ignite grid and fills the cache with simple test data.</p>
* <p>
- * After that it creates dataset splitter and trains the linear regression model based on the specified data using
- * this splitter.</p>
+ * After that it creates dataset splitter and trains the linear regression model based on the specified data using this
+ * splitter.</p>
* <p>
* Finally, this example loops over the test set of data points, applies the trained model to predict the target value
* and compares prediction to expected outcome (ground truth).</p>
@@ -49,7 +49,9 @@ import org.apache.ignite.ml.util.SandboxMLCache;
* further.</p>
*/
public class TrainTestDatasetSplitterExample {
- /** Run example. */
+ /**
+ * Run example.
+ */
public static void main(String[] args) throws IOException {
System.out.println();
System.out.println(">>> Linear regression model over cache based dataset usage example started.");
@@ -96,10 +98,12 @@ public class TrainTestDatasetSplitterExample {
System.out.println(">>> ---------------------------------");
System.out.println(">>> Linear regression model over cache based dataset usage example completed.");
- } finally {
+ }
+ finally {
dataCache.destroy();
}
- } finally {
+ }
+ finally {
System.out.flush();
}
}
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/selection/split/package-info.java b/examples/src/main/java/org/apache/ignite/examples/ml/selection/split/package-info.java
index 55bfaeb..f479435 100644
--- a/examples/src/main/java/org/apache/ignite/examples/ml/selection/split/package-info.java
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/selection/split/package-info.java
@@ -16,7 +16,6 @@
*/
/**
- * <!-- Package description. -->
- * ML dataset split examples.
+ * <!-- Package description. --> ML dataset split examples.
*/
package org.apache.ignite.examples.ml.selection.split;
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/sql/DecisionTreeClassificationTrainerSQLInferenceExample.java b/examples/src/main/java/org/apache/ignite/examples/ml/sql/DecisionTreeClassificationTrainerSQLInferenceExample.java
index 7bf6d1d..fcb8cc8 100644
--- a/examples/src/main/java/org/apache/ignite/examples/ml/sql/DecisionTreeClassificationTrainerSQLInferenceExample.java
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/sql/DecisionTreeClassificationTrainerSQLInferenceExample.java
@@ -37,16 +37,24 @@ import org.apache.ignite.ml.tree.DecisionTreeNode;
* made as SQL select query.
*/
public class DecisionTreeClassificationTrainerSQLInferenceExample {
- /** Dummy cache name. */
+ /**
+ * Dummy cache name.
+ */
private static final String DUMMY_CACHE_NAME = "dummy_cache";
- /** Training data. */
+ /**
+ * Training data.
+ */
private static final String TRAIN_DATA_RES = "examples/src/main/resources/datasets/titanik_train.csv";
- /** Test data. */
+ /**
+ * Test data.
+ */
private static final String TEST_DATA_RES = "examples/src/main/resources/datasets/titanik_test.csv";
- /** Run example. */
+ /**
+ * Run example.
+ */
public static void main(String[] args) {
System.out.println(">>> Decision tree classification trainer example started.");
@@ -133,12 +141,14 @@ public class DecisionTreeClassificationTrainerSQLInferenceExample {
}
IgniteModelStorageUtil.removeModel(ignite, "titanik_model_tree");
- } finally {
+ }
+ finally {
cache.query(new SqlFieldsQuery("DROP TABLE titanik_train"));
cache.query(new SqlFieldsQuery("DROP TABLE titanik_test"));
cache.destroy();
}
- } finally {
+ }
+ finally {
System.out.flush();
}
}
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/sql/DecisionTreeClassificationTrainerSQLTableExample.java b/examples/src/main/java/org/apache/ignite/examples/ml/sql/DecisionTreeClassificationTrainerSQLTableExample.java
index 93e02ba..bcf041d 100644
--- a/examples/src/main/java/org/apache/ignite/examples/ml/sql/DecisionTreeClassificationTrainerSQLTableExample.java
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/sql/DecisionTreeClassificationTrainerSQLTableExample.java
@@ -36,16 +36,24 @@ import org.apache.ignite.ml.tree.DecisionTreeNode;
* Example of using distributed {@link DecisionTreeClassificationTrainer} on a data stored in SQL table.
*/
public class DecisionTreeClassificationTrainerSQLTableExample {
- /** Dummy cache name. */
+ /**
+ * Dummy cache name.
+ */
private static final String DUMMY_CACHE_NAME = "dummy_cache";
- /** Training data. */
+ /**
+ * Training data.
+ */
private static final String TRAIN_DATA_RES = "examples/src/main/resources/datasets/titanik_train.csv";
- /** Test data. */
+ /**
+ * Test data.
+ */
private static final String TEST_DATA_RES = "examples/src/main/resources/datasets/titanik_test.csv";
- /** Run example. */
+ /**
+ * Run example.
+ */
public static void main(String[] args) {
System.out.println(">>> Decision tree classification trainer example started.");
@@ -136,12 +144,14 @@ public class DecisionTreeClassificationTrainerSQLTableExample {
}
System.out.println(">>> Example completed.");
- } finally {
+ }
+ finally {
cache.query(new SqlFieldsQuery("DROP TABLE titanik_train"));
cache.query(new SqlFieldsQuery("DROP TABLE titanik_test"));
cache.destroy();
}
- } finally {
+ }
+ finally {
System.out.flush();
}
}
@@ -158,7 +168,7 @@ public class DecisionTreeClassificationTrainerSQLTableExample {
return null;
if (obj instanceof Number) {
- Number num = (Number) obj;
+ Number num = (Number)obj;
return num.doubleValue();
}
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/sql/package-info.java b/examples/src/main/java/org/apache/ignite/examples/ml/sql/package-info.java
index 8db862e..874fae8 100644
--- a/examples/src/main/java/org/apache/ignite/examples/ml/sql/package-info.java
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/sql/package-info.java
@@ -16,7 +16,6 @@
*/
/**
- * <!-- Package description. -->
- * Example of using ML and SQL functionality togeter.
+ * <!-- Package description. --> Example of using ML and SQL functionality togeter.
*/
package org.apache.ignite.examples.ml.sql;
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/svm/SVMBinaryClassificationExample.java b/examples/src/main/java/org/apache/ignite/examples/ml/svm/SVMBinaryClassificationExample.java
index 78422d4..3850749 100644
--- a/examples/src/main/java/org/apache/ignite/examples/ml/svm/SVMBinaryClassificationExample.java
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/svm/SVMBinaryClassificationExample.java
@@ -25,6 +25,7 @@ import org.apache.ignite.ml.dataset.feature.extractor.Vectorizer;
import org.apache.ignite.ml.dataset.feature.extractor.impl.DummyVectorizer;
import org.apache.ignite.ml.math.primitives.vector.Vector;
import org.apache.ignite.ml.selection.scoring.evaluator.Evaluator;
+import org.apache.ignite.ml.selection.scoring.metric.MetricName;
import org.apache.ignite.ml.svm.SVMLinearClassificationModel;
import org.apache.ignite.ml.svm.SVMLinearClassificationTrainer;
import org.apache.ignite.ml.util.MLSandboxDatasets;
@@ -38,14 +39,16 @@ import org.apache.ignite.ml.util.SandboxMLCache;
* <p>
* After that it trains the model based on the specified data using KMeans algorithm.</p>
* <p>
- * Finally, this example loops over the test set of data points, applies the trained model to predict what cluster
- * does this point belong to, compares prediction to expected outcome (ground truth), and builds
+ * Finally, this example loops over the test set of data points, applies the trained model to predict what cluster does
+ * this point belong to, compares prediction to expected outcome (ground truth), and builds
* <a href="https://en.wikipedia.org/wiki/Confusion_matrix">confusion matrix</a>.</p>
* <p>
* You can change the test data used in this example and re-run it to explore this algorithm further.</p>
*/
public class SVMBinaryClassificationExample {
- /** Run example. */
+ /**
+ * Run example.
+ */
public static void main(String[] args) throws IOException {
System.out.println();
System.out.println(">>> SVM Binary classification model over cached dataset usage example started.");
@@ -66,19 +69,19 @@ public class SVMBinaryClassificationExample {
System.out.println(">>> SVM model " + mdl);
- double accuracy = Evaluator.evaluate(
- dataCache,
- mdl,
- vectorizer
- ).accuracy();
+ double accuracy = Evaluator.evaluate(dataCache,
+ mdl, vectorizer, MetricName.ACCURACY
+ );
System.out.println("\n>>> Accuracy " + accuracy);
System.out.println(">>> SVM Binary classification model over cache based dataset usage example completed.");
- } finally {
+ }
+ finally {
dataCache.destroy();
}
- } finally {
+ }
+ finally {
System.out.flush();
}
}
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/svm/package-info.java b/examples/src/main/java/org/apache/ignite/examples/ml/svm/package-info.java
index cab9fe5..b2dc066 100644
--- a/examples/src/main/java/org/apache/ignite/examples/ml/svm/package-info.java
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/svm/package-info.java
@@ -16,8 +16,7 @@
*/
/**
- * <!-- Package description. -->
- * SVM examples.
+ * <!-- Package description. --> SVM examples.
*/
package org.apache.ignite.examples.ml.svm;
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/tree/DecisionTreeClassificationTrainerExample.java b/examples/src/main/java/org/apache/ignite/examples/ml/tree/DecisionTreeClassificationTrainerExample.java
index a049703..600f4a5 100644
--- a/examples/src/main/java/org/apache/ignite/examples/ml/tree/DecisionTreeClassificationTrainerExample.java
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/tree/DecisionTreeClassificationTrainerExample.java
@@ -100,10 +100,12 @@ public class DecisionTreeClassificationTrainerExample {
System.out.println(">>> Accuracy: " + correctPredictions / 10.0 + "%");
System.out.println(">>> Decision tree classification trainer example completed.");
- } finally {
+ }
+ finally {
trainingSet.destroy();
}
- } finally {
+ }
+ finally {
System.out.flush();
}
}
@@ -120,6 +122,6 @@ public class DecisionTreeClassificationTrainerExample {
double x = rnd.nextDouble() - 0.5;
double y = rnd.nextDouble() - 0.5;
- return new LabeledVector<>(VectorUtils.of(x,y), x * y > 0 ? 1. : 0.);
+ return new LabeledVector<>(VectorUtils.of(x, y), x * y > 0 ? 1. : 0.);
}
}
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/tree/DecisionTreeRegressionTrainerExample.java b/examples/src/main/java/org/apache/ignite/examples/ml/tree/DecisionTreeRegressionTrainerExample.java
index e7a3c6a..1a19771 100644
--- a/examples/src/main/java/org/apache/ignite/examples/ml/tree/DecisionTreeRegressionTrainerExample.java
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/tree/DecisionTreeRegressionTrainerExample.java
@@ -31,13 +31,13 @@ import org.apache.ignite.ml.tree.DecisionTreeRegressionTrainer;
/**
* Example of using distributed {@link DecisionTreeRegressionTrainer}.
* <p>
- * Code in this example launches Ignite grid and fills the cache with generated test data points ({@code sin(x)}
- * on interval {@code [0, 10)}).</p>
+ * Code in this example launches Ignite grid and fills the cache with generated test data points ({@code sin(x)} on
+ * interval {@code [0, 10)}).</p>
* <p>
* After that it creates classification trainer and uses it to train the model on the training set.</p>
* <p>
- * Finally, this example loops over the test data points, applies the trained model, and compares prediction
- * to expected outcome (ground truth).</p>
+ * Finally, this example loops over the test data points, applies the trained model, and compares prediction to expected
+ * outcome (ground truth).</p>
* <p>
* You can change the test data used in this example and re-run it to explore this algorithm further.</p>
*/
@@ -88,10 +88,12 @@ public class DecisionTreeRegressionTrainerExample {
System.out.println(">>> ---------------------------------");
System.out.println(">>> Decision tree regression trainer example completed.");
- } finally {
+ }
+ finally {
trainingSet.destroy();
}
- } finally {
+ }
+ finally {
System.out.flush();
}
}
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/tree/FraudDetectionExample.java b/examples/src/main/java/org/apache/ignite/examples/ml/tree/FraudDetectionExample.java
index 4d38ebf..689e056 100644
--- a/examples/src/main/java/org/apache/ignite/examples/ml/tree/FraudDetectionExample.java
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/tree/FraudDetectionExample.java
@@ -28,7 +28,6 @@ import org.apache.ignite.ml.environment.LearningEnvironmentBuilder;
import org.apache.ignite.ml.math.primitives.vector.Vector;
import org.apache.ignite.ml.regressions.logistic.LogisticRegressionSGDTrainer;
import org.apache.ignite.ml.selection.scoring.evaluator.Evaluator;
-import org.apache.ignite.ml.selection.scoring.metric.classification.BinaryClassificationMetricValues;
import org.apache.ignite.ml.selection.split.TrainTestDatasetSplitter;
import org.apache.ignite.ml.selection.split.TrainTestSplit;
import org.apache.ignite.ml.trainers.DatasetTrainer;
@@ -38,14 +37,13 @@ import org.apache.ignite.ml.util.SandboxMLCache;
/**
* Example of using classification algorithms for fraud detection problem.
- *
- * Description of models can be found in:
- * https://en.wikipedia.org/wiki/Logistic_regression and
- * https://en.wikipedia.org/wiki/Decision_tree_learning .
- * Original dataset can be downloaded from: https://www.kaggle.com/mlg-ulb/creditcardfraud/ .
- * Copy of dataset are stored in: modules/ml/src/main/resources/datasets/fraud_detection.csv .
- * Score for clusterizer estimation: accuracy, recall, precision, f1-score .
- * Description of entropy can be found in: https://en.wikipedia.org/wiki/Evaluation_of_binary_classifiers .
+ * <p>
+ * Description of models can be found in: https://en.wikipedia.org/wiki/Logistic_regression and
+ * https://en.wikipedia.org/wiki/Decision_tree_learning . Original dataset can be downloaded from:
+ * https://www.kaggle.com/mlg-ulb/creditcardfraud/ . Copy of dataset are stored in:
+ * modules/ml/src/main/resources/datasets/fraud_detection.csv . Score for clusterizer estimation: accuracy, recall,
+ * precision, f1-score . Description of entropy can be found in: https://en.wikipedia.org/wiki/Evaluation_of_binary_classifiers
+ * .
*/
public class FraudDetectionExample {
public static void main(String[] args) throws IOException {
@@ -78,10 +76,12 @@ public class FraudDetectionExample {
.withEnvironmentBuilder(LearningEnvironmentBuilder.defaultBuilder().withRNGSeed(0)),
vectorizer, split
);
- } finally {
+ }
+ finally {
dataCache.destroy();
}
- } finally {
+ }
+ finally {
System.out.flush();
}
}
@@ -89,11 +89,11 @@ public class FraudDetectionExample {
/**
* Train model and estimate it.
*
- * @param ignite Ignite
- * @param dataCache Data set cache.
- * @param trainer Trainer.
+ * @param ignite Ignite
+ * @param dataCache Data set cache.
+ * @param trainer Trainer.
* @param vectorizer Upstream vectorizer.
- * @param splitter Train test splitter.
+ * @param splitter Train test splitter.
*/
private static void trainAndEstimateModel(Ignite ignite,
IgniteCache<Integer, Vector> dataCache,
@@ -107,20 +107,6 @@ public class FraudDetectionExample {
);
System.out.println(">>> Perform scoring.");
- BinaryClassificationMetricValues metricValues = Evaluator.evaluate(
- dataCache,
- splitter.getTestFilter(),
- mdl,
- vectorizer
- );
-
- System.out.println(String.format(">> Model accuracy: %.2f", metricValues.accuracy()));
- System.out.println(String.format(">> Model precision: %.2f", metricValues.precision()));
- System.out.println(String.format(">> Model recall: %.2f", metricValues.recall()));
- System.out.println(String.format(">> Model f1-score: %.2f", metricValues.f1Score()));
- System.out.println(">> Confusion matrix:");
- System.out.println(">> fraud (ans) | not fraud (ans)");
- System.out.println(String.format(">> fraud (pred) | %1$11.2f | %2$15.2f ", metricValues.tp(), metricValues.fp()));
- System.out.println(String.format(">> not fraud (pred) | %1$11.2f | %2$15.2f ", metricValues.fn(), metricValues.tn()));
+ System.out.println(Evaluator.evaluateBinaryClassification(dataCache, splitter.getTestFilter(), mdl, vectorizer));
}
}
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/tree/boosting/GDBOnTreesClassificationTrainerExample.java b/examples/src/main/java/org/apache/ignite/examples/ml/tree/boosting/GDBOnTreesClassificationTrainerExample.java
index 3fd0f41..cc57baf 100644
--- a/examples/src/main/java/org/apache/ignite/examples/ml/tree/boosting/GDBOnTreesClassificationTrainerExample.java
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/tree/boosting/GDBOnTreesClassificationTrainerExample.java
@@ -32,9 +32,9 @@ import org.apache.ignite.ml.tree.boosting.GDBBinaryClassifierOnTreesTrainer;
import org.jetbrains.annotations.NotNull;
/**
- * Example represents a solution for the task of classification learning based on
- * Gradient Boosting on trees implementation. It shows an initialization of {@link GDBBinaryClassifierOnTreesTrainer},
- * initialization of Ignite Cache, learning step and comparing of predicted and real values.
+ * Example represents a solution for the task of classification learning based on Gradient Boosting on trees
+ * implementation. It shows an initialization of {@link GDBBinaryClassifierOnTreesTrainer}, initialization of Ignite
+ * Cache, learning step and comparing of predicted and real values.
* <p>
* In this example dataset is created automatically by meander function {@code f(x) = [sin(x) > 0]}.</p>
*/
@@ -84,10 +84,12 @@ public class GDBOnTreesClassificationTrainerExample {
System.out.println(">>> ---------------------------------");
System.out.println(">>> GDB classification trainer example completed.");
- } finally {
+ }
+ finally {
trainingSet.destroy();
}
- } finally {
+ }
+ finally {
System.out.flush();
}
}
@@ -105,13 +107,13 @@ public class GDBOnTreesClassificationTrainerExample {
/**
* Fill meander-like training data.
*
- * @param ignite Ignite instance.
+ * @param ignite Ignite instance.
* @param trainingSetCfg Training set config.
*/
@NotNull private static IgniteCache<Integer, double[]> fillTrainingData(Ignite ignite,
CacheConfiguration<Integer, double[]> trainingSetCfg) {
IgniteCache<Integer, double[]> trainingSet = ignite.getOrCreateCache(trainingSetCfg);
- for(int i = -50; i <= 50; i++) {
+ for (int i = -50; i <= 50; i++) {
double x = ((double)i) / 10.0;
double y = Math.sin(x) < 0 ? 0.0 : 1.0;
trainingSet.put(i, new double[] {x, y});
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/tree/boosting/GDBOnTreesRegressionTrainerExample.java b/examples/src/main/java/org/apache/ignite/examples/ml/tree/boosting/GDBOnTreesRegressionTrainerExample.java
index a2b7ed5..09dd708 100644
--- a/examples/src/main/java/org/apache/ignite/examples/ml/tree/boosting/GDBOnTreesRegressionTrainerExample.java
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/tree/boosting/GDBOnTreesRegressionTrainerExample.java
@@ -34,9 +34,9 @@ import org.apache.ignite.ml.tree.boosting.GDBRegressionOnTreesTrainer;
import org.jetbrains.annotations.NotNull;
/**
- * Example represents a solution for the task of regression learning based on
- * Gradient Boosting on trees implementation. It shows an initialization of {@link GDBRegressionOnTreesTrainer},
- * initialization of Ignite Cache, learning step and comparing of predicted and real values.
+ * Example represents a solution for the task of regression learning based on Gradient Boosting on trees implementation.
+ * It shows an initialization of {@link GDBRegressionOnTreesTrainer}, initialization of Ignite Cache, learning step and
+ * comparing of predicted and real values.
* <p>
* In this example dataset is created automatically by parabolic function {@code f(x) = x^2}.</p>
*/
@@ -83,10 +83,12 @@ public class GDBOnTreesRegressionTrainerExample {
System.out.println(">>> ---------------------------------");
System.out.println(">>> GDB regression trainer example completed.");
- } finally {
+ }
+ finally {
trainingSet.destroy();
}
- } finally {
+ }
+ finally {
System.out.flush();
}
}
@@ -104,13 +106,13 @@ public class GDBOnTreesRegressionTrainerExample {
/**
* Fill parabolic training data.
*
- * @param ignite Ignite instance.
+ * @param ignite Ignite instance.
* @param trainingSetCfg Training set config.
*/
@NotNull private static IgniteCache<Integer, double[]> fillTrainingData(Ignite ignite,
CacheConfiguration<Integer, double[]> trainingSetCfg) {
IgniteCache<Integer, double[]> trainingSet = ignite.getOrCreateCache(trainingSetCfg);
- for(int i = -50; i <= 50; i++) {
+ for (int i = -50; i <= 50; i++) {
double x = ((double)i) / 10.0;
double y = Math.pow(x, 2);
trainingSet.put(i, new double[] {x, y});
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/tree/boosting/package-info.java b/examples/src/main/java/org/apache/ignite/examples/ml/tree/boosting/package-info.java
index 899af35..97bbaa8 100644
--- a/examples/src/main/java/org/apache/ignite/examples/ml/tree/boosting/package-info.java
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/tree/boosting/package-info.java
@@ -16,7 +16,6 @@
*/
/**
- * <!-- Package description. -->
- * Gradient Boosting On Trees examples.
+ * <!-- Package description. --> Gradient Boosting On Trees examples.
*/
package org.apache.ignite.examples.ml.tree.boosting;
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/tree/package-info.java b/examples/src/main/java/org/apache/ignite/examples/ml/tree/package-info.java
index d8d9de6..52325cc 100644
--- a/examples/src/main/java/org/apache/ignite/examples/ml/tree/package-info.java
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/tree/package-info.java
@@ -16,7 +16,6 @@
*/
/**
- * <!-- Package description. -->
- * Decision trees examples.
+ * <!-- Package description. --> Decision trees examples.
*/
package org.apache.ignite.examples.ml.tree;
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/tree/randomforest/RandomForestClassificationExample.java b/examples/src/main/java/org/apache/ignite/examples/ml/tree/randomforest/RandomForestClassificationExample.java
index e2488aa..15cc5d4 100644
--- a/examples/src/main/java/org/apache/ignite/examples/ml/tree/randomforest/RandomForestClassificationExample.java
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/tree/randomforest/RandomForestClassificationExample.java
@@ -40,14 +40,14 @@ import org.apache.ignite.ml.util.SandboxMLCache;
/**
* Example represents a solution for the task of wine classification based on a
- * <a href ="https://en.wikipedia.org/wiki/Random_forest">Random Forest</a> implementation for
+ * <a href ="https://en.wikipedia.org/wiki/Random_forest">Random Forest</a> implementation for
* multi-classification.
* <p>
* Code in this example launches Ignite grid and fills the cache with test data points (based on the
* <a href="https://archive.ics.uci.edu/ml/machine-learning-databases/wine/">Wine recognition dataset</a>).</p>
* <p>
- * After that it initializes the {@link RandomForestClassifierTrainer} with thread pool for multi-thread learning
- * and trains the model based on the specified data using random forest regression algorithm.</p>
+ * After that it initializes the {@link RandomForestClassifierTrainer} with thread pool for multi-thread learning and
+ * trains the model based on the specified data using random forest regression algorithm.</p>
* <p>
* Finally, this example loops over the test set of data points, compares prediction of the trained model to the
* expected outcome (ground truth), and evaluates accuracy of the model.</p>
@@ -111,11 +111,13 @@ public class RandomForestClassificationExample {
System.out.println(">>> Random Forest multi-class classification algorithm over cached dataset usage example completed.");
}
- } finally {
+ }
+ finally {
if (dataCache != null)
dataCache.destroy();
}
- } finally {
+ }
+ finally {
System.out.flush();
}
}
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/tree/randomforest/RandomForestRegressionExample.java b/examples/src/main/java/org/apache/ignite/examples/ml/tree/randomforest/RandomForestRegressionExample.java
index 4f27b85..b86462c 100644
--- a/examples/src/main/java/org/apache/ignite/examples/ml/tree/randomforest/RandomForestRegressionExample.java
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/tree/randomforest/RandomForestRegressionExample.java
@@ -51,8 +51,8 @@ import org.apache.ignite.ml.util.SandboxMLCache;
* using random forest regression algorithm.</p>
* <p>
* Finally, this example loops over the test set of data points, compares prediction of the trained model to the
- * expected outcome (ground truth), and evaluates model quality in terms of Mean Squared Error (MSE) and
- * Mean Absolute Error (MAE).</p>
+ * expected outcome (ground truth), and evaluates model quality in terms of Mean Squared Error (MSE) and Mean Absolute
+ * Error (MAE).</p>
* <p>
* You can change the test data used in this example and re-run it to explore this algorithm further.</p>
*/
@@ -123,10 +123,12 @@ public class RandomForestRegressionExample {
System.out.println(">>> Random Forest regression algorithm over cached dataset usage example completed.");
}
- } finally {
+ }
+ finally {
dataCache.destroy();
}
- } finally {
+ }
+ finally {
System.out.flush();
}
}
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/tree/randomforest/package-info.java b/examples/src/main/java/org/apache/ignite/examples/ml/tree/randomforest/package-info.java
index 2ae1457..09fa73c 100644
--- a/examples/src/main/java/org/apache/ignite/examples/ml/tree/randomforest/package-info.java
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/tree/randomforest/package-info.java
@@ -16,7 +16,6 @@
*/
/**
- * <!-- Package description. -->
- * Random forest examples.
+ * <!-- Package description. --> Random forest examples.
*/
package org.apache.ignite.examples.ml.tree.randomforest;
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/tutorial/Step_1_Read_and_Learn.java b/examples/src/main/java/org/apache/ignite/examples/ml/tutorial/Step_1_Read_and_Learn.java
index cd9cff6..b6df5d6 100644
--- a/examples/src/main/java/org/apache/ignite/examples/ml/tutorial/Step_1_Read_and_Learn.java
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/tutorial/Step_1_Read_and_Learn.java
@@ -41,7 +41,9 @@ import org.apache.ignite.ml.tree.DecisionTreeNode;
* Finally, this example uses {@link Evaluator} functionality to compute metrics from predictions.</p>
*/
public class Step_1_Read_and_Learn {
- /** Run example. */
+ /**
+ * Run example.
+ */
public static void main(String[] args) {
System.out.println();
System.out.println(">>> Tutorial step 1 (read and learn) example started.");
@@ -73,10 +75,12 @@ public class Step_1_Read_and_Learn {
System.out.println("\n>>> Test Error " + (1 - accuracy));
System.out.println(">>> Tutorial step 1 (read and learn) example completed.");
- } catch (FileNotFoundException e) {
+ }
+ catch (FileNotFoundException e) {
e.printStackTrace();
}
- } finally {
+ }
+ finally {
System.out.flush();
}
}
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/tutorial/Step_2_Imputing.java b/examples/src/main/java/org/apache/ignite/examples/ml/tutorial/Step_2_Imputing.java
index ef5f5d3..094a966 100644
--- a/examples/src/main/java/org/apache/ignite/examples/ml/tutorial/Step_2_Imputing.java
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/tutorial/Step_2_Imputing.java
@@ -44,7 +44,9 @@ import org.apache.ignite.ml.tree.DecisionTreeNode;
* Finally, this example uses {@link Evaluator} functionality to compute metrics from predictions.</p>
*/
public class Step_2_Imputing {
- /** Run example. */
+ /**
+ * Run example.
+ */
public static void main(String[] args) {
System.out.println();
System.out.println(">>> Tutorial step 2 (imputing) example started.");
@@ -83,10 +85,12 @@ public class Step_2_Imputing {
System.out.println("\n>>> Test Error " + (1 - accuracy));
System.out.println(">>> Tutorial step 2 (imputing) example completed.");
- } catch (FileNotFoundException e) {
+ }
+ catch (FileNotFoundException e) {
e.printStackTrace();
}
- } finally {
+ }
+ finally {
System.out.flush();
}
}
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/tutorial/Step_3_Categorial.java b/examples/src/main/java/org/apache/ignite/examples/ml/tutorial/Step_3_Categorial.java
index 9ac3290..68b05a4 100644
--- a/examples/src/main/java/org/apache/ignite/examples/ml/tutorial/Step_3_Categorial.java
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/tutorial/Step_3_Categorial.java
@@ -48,7 +48,9 @@ import org.apache.ignite.ml.tree.DecisionTreeNode;
* Finally, this example uses {@link Evaluator} functionality to compute metrics from predictions.</p>
*/
public class Step_3_Categorial {
- /** Run example. */
+ /**
+ * Run example.
+ */
public static void main(String[] args) {
System.out.println();
System.out.println(">>> Tutorial step 3 (categorial) example started.");
@@ -97,10 +99,12 @@ public class Step_3_Categorial {
System.out.println("\n>>> Test Error " + (1 - accuracy));
System.out.println(">>> Tutorial step 3 (categorial) example completed.");
- } catch (FileNotFoundException e) {
+ }
+ catch (FileNotFoundException e) {
e.printStackTrace();
}
- } finally {
+ }
+ finally {
System.out.flush();
}
}
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/tutorial/Step_3_Categorial_with_One_Hot_Encoder.java b/examples/src/main/java/org/apache/ignite/examples/ml/tutorial/Step_3_Categorial_with_One_Hot_Encoder.java
index 29e45a4..206d2dc 100644
--- a/examples/src/main/java/org/apache/ignite/examples/ml/tutorial/Step_3_Categorial_with_One_Hot_Encoder.java
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/tutorial/Step_3_Categorial_with_One_Hot_Encoder.java
@@ -34,7 +34,8 @@ import org.apache.ignite.ml.tree.DecisionTreeClassificationTrainer;
import org.apache.ignite.ml.tree.DecisionTreeNode;
/**
- * Let's add two categorial features "sex", "embarked" to predict more precisely than in {@link Step_1_Read_and_Learn}..
+ * Let's add two categorial features "sex", "embarked" to predict more precisely than in {@link
+ * Step_1_Read_and_Learn}..
* <p>
* To encode categorial features the {@link EncoderTrainer} of the
* <a href="https://en.wikipedia.org/wiki/One-hot">One-hot</a> type will be used.</p>
@@ -49,7 +50,9 @@ import org.apache.ignite.ml.tree.DecisionTreeNode;
* Finally, this example uses {@link Evaluator} functionality to compute metrics from predictions.</p>
*/
public class Step_3_Categorial_with_One_Hot_Encoder {
- /** Run example. */
+ /**
+ * Run example.
+ */
public static void main(String[] args) {
System.out.println();
System.out.println(">>> Tutorial step 3 (categorial with One-hot encoder) example started.");
@@ -100,10 +103,12 @@ public class Step_3_Categorial_with_One_Hot_Encoder {
System.out.println(">>> Tutorial step 3 (categorial with One-hot encoder) example started.");
- } catch (FileNotFoundException e) {
+ }
+ catch (FileNotFoundException e) {
e.printStackTrace();
}
- } finally {
+ }
+ finally {
System.out.flush();
}
}
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/tutorial/Step_4_Add_age_fare.java b/examples/src/main/java/org/apache/ignite/examples/ml/tutorial/Step_4_Add_age_fare.java
index 3975056..1d85a14 100644
--- a/examples/src/main/java/org/apache/ignite/examples/ml/tutorial/Step_4_Add_age_fare.java
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/tutorial/Step_4_Add_age_fare.java
@@ -46,7 +46,9 @@ import org.apache.ignite.ml.tree.DecisionTreeNode;
* Finally, this example uses {@link Evaluator} functionality to compute metrics from predictions.</p>
*/
public class Step_4_Add_age_fare {
- /** Run example. */
+ /**
+ * Run example.
+ */
public static void main(String[] args) {
System.out.println();
System.out.println(">>> Tutorial step 4 (add age and fare) example started.");
@@ -96,10 +98,12 @@ public class Step_4_Add_age_fare {
System.out.println("\n>>> Test Error " + (1 - accuracy));
System.out.println(">>> Tutorial step 4 (add age and fare) example completed.");
- } catch (FileNotFoundException e) {
+ }
+ catch (FileNotFoundException e) {
e.printStackTrace();
}
- } finally {
+ }
+ finally {
System.out.flush();
}
}
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/tutorial/Step_5_Scaling.java b/examples/src/main/java/org/apache/ignite/examples/ml/tutorial/Step_5_Scaling.java
index a40acfb..dfb6de0 100644
--- a/examples/src/main/java/org/apache/ignite/examples/ml/tutorial/Step_5_Scaling.java
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/tutorial/Step_5_Scaling.java
@@ -49,7 +49,9 @@ import org.apache.ignite.ml.tree.DecisionTreeNode;
* Finally, this example uses {@link Evaluator} functionality to compute metrics from predictions.</p>
*/
public class Step_5_Scaling {
- /** Run example. */
+ /**
+ * Run example.
+ */
public static void main(String[] args) {
System.out.println();
System.out.println(">>> Tutorial step 5 (scaling) example started.");
@@ -114,10 +116,12 @@ public class Step_5_Scaling {
System.out.println("\n>>> Test Error " + (1 - accuracy));
System.out.println(">>> Tutorial step 5 (scaling) example completed.");
- } catch (FileNotFoundException e) {
+ }
+ catch (FileNotFoundException e) {
e.printStackTrace();
}
- } finally {
+ }
+ finally {
System.out.flush();
}
}
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/tutorial/Step_5_Scaling_with_Pipeline.java b/examples/src/main/java/org/apache/ignite/examples/ml/tutorial/Step_5_Scaling_with_Pipeline.java
index f62a244..5989032 100644
--- a/examples/src/main/java/org/apache/ignite/examples/ml/tutorial/Step_5_Scaling_with_Pipeline.java
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/tutorial/Step_5_Scaling_with_Pipeline.java
@@ -49,7 +49,9 @@ import org.apache.ignite.ml.tree.DecisionTreeClassificationTrainer;
* Finally, this example uses {@link Evaluator} functionality to compute metrics from predictions.</p>
*/
public class Step_5_Scaling_with_Pipeline {
- /** Run example. */
+ /**
+ * Run example.
+ */
public static void main(String[] args) {
System.out.println();
System.out.println(">>> Tutorial step 5 (scaling) via Pipeline example started.");
@@ -77,10 +79,8 @@ public class Step_5_Scaling_with_Pipeline {
System.out.println("\n>>> Trained model: " + mdl);
- double accuracy = Evaluator.evaluate(
- dataCache,
- mdl,
- mdl.getPreprocessor(),
+ double accuracy = Evaluator.evaluate(dataCache,
+ mdl, mdl.getPreprocessor(),
new Accuracy<>()
);
@@ -88,10 +88,12 @@ public class Step_5_Scaling_with_Pipeline {
System.out.println("\n>>> Test Error " + (1 - accuracy));
System.out.println(">>> Tutorial step 5 (scaling) via Pipeline example completed.");
- } catch (FileNotFoundException e) {
+ }
+ catch (FileNotFoundException e) {
e.printStackTrace();
}
- } finally {
+ }
+ finally {
System.out.flush();
}
}
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/tutorial/Step_6_KNN.java b/examples/src/main/java/org/apache/ignite/examples/ml/tutorial/Step_6_KNN.java
index 5bf28c8..59b5969 100644
--- a/examples/src/main/java/org/apache/ignite/examples/ml/tutorial/Step_6_KNN.java
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/tutorial/Step_6_KNN.java
@@ -36,8 +36,8 @@ import org.apache.ignite.ml.selection.scoring.evaluator.Evaluator;
import org.apache.ignite.ml.selection.scoring.metric.classification.Accuracy;
/**
- * Change classification algorithm that was used in {@link Step_5_Scaling} from decision tree to kNN
- * ({@link KNNClassificationTrainer}) because sometimes this can be beneficial.
+ * Change classification algorithm that was used in {@link Step_5_Scaling} from decision tree to kNN ({@link
+ * KNNClassificationTrainer}) because sometimes this can be beneficial.
* <p>
* Code in this example launches Ignite grid and fills the cache with test data (based on Titanic passengers data).</p>
* <p>
@@ -49,7 +49,9 @@ import org.apache.ignite.ml.selection.scoring.metric.classification.Accuracy;
* Finally, this example uses {@link Evaluator} functionality to compute metrics from predictions.</p>
*/
public class Step_6_KNN {
- /** Run example. */
+ /**
+ * Run example.
+ */
public static void main(String[] args) {
System.out.println();
System.out.println(">>> Tutorial step 6 (kNN) example started.");
@@ -116,10 +118,12 @@ public class Step_6_KNN {
System.out.println("\n>>> Test Error " + (1 - accuracy));
System.out.println(">>> Tutorial step 6 (kNN) example completed.");
- } catch (FileNotFoundException e) {
+ }
+ catch (FileNotFoundException e) {
e.printStackTrace();
}
- } finally {
+ }
+ finally {
System.out.flush();
}
}
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/tutorial/Step_7_Split_train_test.java b/examples/src/main/java/org/apache/ignite/examples/ml/tutorial/Step_7_Split_train_test.java
index 4bbce7b..e104c51 100644
--- a/examples/src/main/java/org/apache/ignite/examples/ml/tutorial/Step_7_Split_train_test.java
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/tutorial/Step_7_Split_train_test.java
@@ -44,15 +44,17 @@ import org.apache.ignite.ml.tree.DecisionTreeNode;
* <p>
* Code in this example launches Ignite grid and fills the cache with test data (based on Titanic passengers data).</p>
* <p>
- * After that it defines how to split the data to train and test sets and configures preprocessors that extract
- * features from an upstream data and perform other desired changes over the extracted data.</p>
+ * After that it defines how to split the data to train and test sets and configures preprocessors that extract features
+ * from an upstream data and perform other desired changes over the extracted data.</p>
* <p>
* Then, it trains the model based on the processed data using decision tree classification.</p>
* <p>
* Finally, this example uses {@link Evaluator} functionality to compute metrics from predictions.</p>
*/
public class Step_7_Split_train_test {
- /** Run example. */
+ /**
+ * Run example.
+ */
public static void main(String[] args) {
System.out.println();
System.out.println(">>> Tutorial step 7 (split to train and test) example started.");
@@ -122,10 +124,12 @@ public class Step_7_Split_train_test {
System.out.println("\n>>> Test Error " + (1 - accuracy));
System.out.println(">>> Tutorial step 7 (split to train and test) example completed.");
- } catch (FileNotFoundException e) {
+ }
+ catch (FileNotFoundException e) {
e.printStackTrace();
}
- } finally {
+ }
+ finally {
System.out.flush();
}
}
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/tutorial/Step_8_CV.java b/examples/src/main/java/org/apache/ignite/examples/ml/tutorial/Step_8_CV.java
index e2aac53..acb3c0b 100644
--- a/examples/src/main/java/org/apache/ignite/examples/ml/tutorial/Step_8_CV.java
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/tutorial/Step_8_CV.java
@@ -33,6 +33,7 @@ import org.apache.ignite.ml.preprocessing.minmaxscaling.MinMaxScalerTrainer;
import org.apache.ignite.ml.preprocessing.normalization.NormalizationTrainer;
import org.apache.ignite.ml.selection.cv.CrossValidation;
import org.apache.ignite.ml.selection.scoring.evaluator.Evaluator;
+import org.apache.ignite.ml.selection.scoring.metric.MetricName;
import org.apache.ignite.ml.selection.scoring.metric.classification.Accuracy;
import org.apache.ignite.ml.selection.split.TrainTestDatasetSplitter;
import org.apache.ignite.ml.selection.split.TrainTestSplit;
@@ -44,11 +45,11 @@ import org.apache.ignite.ml.tree.DecisionTreeNode;
* <p>
* Code in this example launches Ignite grid and fills the cache with test data (based on Titanic passengers data).</p>
* <p>
- * After that it defines how to split the data to train and test sets and configures preprocessors that extract
- * features from an upstream data and perform other desired changes over the extracted data.</p>
+ * After that it defines how to split the data to train and test sets and configures preprocessors that extract features
+ * from an upstream data and perform other desired changes over the extracted data.</p>
* <p>
- * Then, it tunes hyperparams with K-fold Cross-Validation on the split training set and trains the model based on
- * the processed data using decision tree classification and the obtained hyperparams.</p>
+ * Then, it tunes hyperparams with K-fold Cross-Validation on the split training set and trains the model based on the
+ * processed data using decision tree classification and the obtained hyperparams.</p>
* <p>
* Finally, this example uses {@link Evaluator} functionality to compute metrics from predictions.</p>
* <p>
@@ -58,13 +59,15 @@ import org.apache.ignite.ml.tree.DecisionTreeNode;
* <p>
* They differ in that {@code 1/(k-1)}th of the training data is exchanged against other cases.</p>
* <p>
- * These models are sometimes called surrogate models because the (average) performance measured for these models
- * is taken as a surrogate of the performance of the model trained on all cases.</p>
+ * These models are sometimes called surrogate models because the (average) performance measured for these models is
+ * taken as a surrogate of the performance of the model trained on all cases.</p>
* <p>
* All scenarios are described there: https://sebastianraschka.com/faq/docs/evaluate-a-model.html</p>
*/
public class Step_8_CV {
- /** Run example. */
+ /**
+ * Run example.
+ */
public static void main(String[] args) {
System.out.println();
System.out.println(">>> Tutorial step 8 (cross-validation) example started.");
@@ -103,14 +106,14 @@ public class Step_8_CV {
);
// Tune hyperparams with K-fold Cross-Validation on the split training set.
- int[] pSet = new int[]{1, 2};
- int[] maxDeepSet = new int[]{1, 2, 3, 4, 5, 10, 20};
+ int[] pSet = new int[] {1, 2};
+ int[] maxDeepSet = new int[] {1, 2, 3, 4, 5, 10, 20};
int bestP = 1;
int bestMaxDeep = 1;
double avg = Double.MIN_VALUE;
- for(int p: pSet){
- for(int maxDeep: maxDeepSet){
+ for (int p : pSet) {
+ for (int maxDeep : maxDeepSet) {
Preprocessor<Integer, Vector> normalizationPreprocessor = new NormalizationTrainer<Integer, Vector>()
.withP(p)
@@ -123,14 +126,14 @@ public class Step_8_CV {
DecisionTreeClassificationTrainer trainer
= new DecisionTreeClassificationTrainer(maxDeep, 0);
- CrossValidation<DecisionTreeNode, Double, Integer, Vector> scoreCalculator
+ CrossValidation<DecisionTreeNode, Integer, Vector> scoreCalculator
= new CrossValidation<>();
double[] scores = scoreCalculator
.withIgnite(ignite)
.withUpstreamCache(dataCache)
.withTrainer(trainer)
- .withMetric(new Accuracy<>())
+ .withMetric(MetricName.ACCURACY)
.withFilter(split.getTrainFilter())
.withPreprocessor(normalizationPreprocessor)
.withAmountOfFolds(3)
@@ -141,7 +144,7 @@ public class Step_8_CV {
final double currAvg = Arrays.stream(scores).average().orElse(Double.MIN_VALUE);
- if(currAvg > avg) {
+ if (currAvg > avg) {
avg = currAvg;
bestP = p;
bestMaxDeep = maxDeep;
@@ -174,8 +177,7 @@ public class Step_8_CV {
System.out.println("\n>>> Trained model: " + bestMdl);
double accuracy = Evaluator.evaluate(
- dataCache,
- split.getTestFilter(),
+ dataCache, split.getTestFilter(),
bestMdl,
normalizationPreprocessor,
new Accuracy<>()
@@ -185,10 +187,12 @@ public class Step_8_CV {
System.out.println("\n>>> Test Error " + (1 - accuracy));
System.out.println(">>> Tutorial step 8 (cross-validation) example completed.");
- } catch (FileNotFoundException e) {
+ }
+ catch (FileNotFoundException e) {
e.printStackTrace();
}
- } finally {
+ }
+ finally {
System.out.flush();
}
}
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/tutorial/Step_8_CV_with_Param_Grid.java b/examples/src/main/java/org/apache/ignite/examples/ml/tutorial/Step_8_CV_with_Param_Grid.java
index b7bc03d..60ae408 100644
--- a/examples/src/main/java/org/apache/ignite/examples/ml/tutorial/Step_8_CV_with_Param_Grid.java
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/tutorial/Step_8_CV_with_Param_Grid.java
@@ -35,6 +35,7 @@ import org.apache.ignite.ml.selection.cv.CrossValidation;
import org.apache.ignite.ml.selection.cv.CrossValidationResult;
import org.apache.ignite.ml.selection.paramgrid.ParamGrid;
import org.apache.ignite.ml.selection.scoring.evaluator.Evaluator;
+import org.apache.ignite.ml.selection.scoring.metric.MetricName;
import org.apache.ignite.ml.selection.scoring.metric.classification.Accuracy;
import org.apache.ignite.ml.selection.split.TrainTestDatasetSplitter;
import org.apache.ignite.ml.selection.split.TrainTestSplit;
@@ -46,11 +47,11 @@ import org.apache.ignite.ml.tree.DecisionTreeNode;
* <p>
* Code in this example launches Ignite grid and fills the cache with test data (based on Titanic passengers data).</p>
* <p>
- * After that it defines how to split the data to train and test sets and configures preprocessors that extract
- * features from an upstream data and perform other desired changes over the extracted data.</p>
+ * After that it defines how to split the data to train and test sets and configures preprocessors that extract features
+ * from an upstream data and perform other desired changes over the extracted data.</p>
* <p>
- * Then, it tunes hyperparams with K-fold Cross-Validation on the split training set and trains the model based on
- * the processed data using decision tree classification and the obtained hyperparams.</p>
+ * Then, it tunes hyperparams with K-fold Cross-Validation on the split training set and trains the model based on the
+ * processed data using decision tree classification and the obtained hyperparams.</p>
* <p>
* Finally, this example uses {@link Evaluator} functionality to compute metrics from predictions.</p>
* <p>
@@ -60,13 +61,15 @@ import org.apache.ignite.ml.tree.DecisionTreeNode;
* <p>
* They differ in that {@code 1/(k-1)}th of the training data is exchanged against other cases.</p>
* <p>
- * These models are sometimes called surrogate models because the (average) performance measured for these models
- * is taken as a surrogate of the performance of the model trained on all cases.</p>
+ * These models are sometimes called surrogate models because the (average) performance measured for these models is
+ * taken as a surrogate of the performance of the model trained on all cases.</p>
* <p>
* All scenarios are described there: https://sebastianraschka.com/faq/docs/evaluate-a-model.html</p>
*/
public class Step_8_CV_with_Param_Grid {
- /** Run example. */
+ /**
+ * Run example.
+ */
public static void main(String[] args) {
System.out.println();
System.out.println(">>> Tutorial step 8 (cross-validation with param grid) example started.");
@@ -116,18 +119,18 @@ public class Step_8_CV_with_Param_Grid {
DecisionTreeClassificationTrainer trainerCV = new DecisionTreeClassificationTrainer();
- CrossValidation<DecisionTreeNode, Double, Integer, Vector> scoreCalculator
+ CrossValidation<DecisionTreeNode, Integer, Vector> scoreCalculator
= new CrossValidation<>();
ParamGrid paramGrid = new ParamGrid()
- .addHyperParam("maxDeep", trainerCV::withMaxDeep, new Double[]{1.0, 2.0, 3.0, 4.0, 5.0, 10.0, 10.0})
- .addHyperParam("minImpurityDecrease", trainerCV::withMinImpurityDecrease, new Double[]{0.0, 0.25, 0.5});
+ .addHyperParam("maxDeep", trainerCV::withMaxDeep, new Double[] {1.0, 2.0, 3.0, 4.0, 5.0, 10.0, 10.0})
+ .addHyperParam("minImpurityDecrease", trainerCV::withMinImpurityDecrease, new Double[] {0.0, 0.25, 0.5});
scoreCalculator
.withIgnite(ignite)
.withUpstreamCache(dataCache)
.withTrainer(trainerCV)
- .withMetric(new Accuracy<>())
+ .withMetric(MetricName.ACCURACY)
.withFilter(split.getTrainFilter())
.isRunningOnPipeline(false)
.withPreprocessor(normalizationPreprocessor)
@@ -163,8 +166,7 @@ public class Step_8_CV_with_Param_Grid {
System.out.println("\n>>> Trained model: " + bestMdl);
double accuracy = Evaluator.evaluate(
- dataCache,
- split.getTestFilter(),
+ dataCache, split.getTestFilter(),
bestMdl,
normalizationPreprocessor,
new Accuracy<>()
@@ -174,10 +176,12 @@ public class Step_8_CV_with_Param_Grid {
System.out.println("\n>>> Test Error " + (1 - accuracy));
System.out.println(">>> Tutorial step 8 (cross-validation with param grid) example started.");
- } catch (FileNotFoundException e) {
+ }
+ catch (FileNotFoundException e) {
e.printStackTrace();
}
- } finally {
+ }
+ finally {
System.out.flush();
}
}
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/tutorial/Step_8_CV_with_Param_Grid_and_metrics.java b/examples/src/main/java/org/apache/ignite/examples/ml/tutorial/Step_8_CV_with_Param_Grid_and_metrics.java
index 80d166e..1e7e97e 100644
--- a/examples/src/main/java/org/apache/ignite/examples/ml/tutorial/Step_8_CV_with_Param_Grid_and_metrics.java
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/tutorial/Step_8_CV_with_Param_Grid_and_metrics.java
@@ -35,9 +35,8 @@ import org.apache.ignite.ml.selection.cv.CrossValidation;
import org.apache.ignite.ml.selection.cv.CrossValidationResult;
import org.apache.ignite.ml.selection.paramgrid.ParamGrid;
import org.apache.ignite.ml.selection.scoring.evaluator.Evaluator;
+import org.apache.ignite.ml.selection.scoring.metric.MetricName;
import org.apache.ignite.ml.selection.scoring.metric.classification.Accuracy;
-import org.apache.ignite.ml.selection.scoring.metric.classification.BinaryClassificationMetricValues;
-import org.apache.ignite.ml.selection.scoring.metric.classification.BinaryClassificationMetrics;
import org.apache.ignite.ml.selection.split.TrainTestDatasetSplitter;
import org.apache.ignite.ml.selection.split.TrainTestSplit;
import org.apache.ignite.ml.tree.DecisionTreeClassificationTrainer;
@@ -48,11 +47,11 @@ import org.apache.ignite.ml.tree.DecisionTreeNode;
* <p>
* Code in this example launches Ignite grid and fills the cache with test data (based on Titanic passengers data).</p>
* <p>
- * After that it defines how to split the data to train and test sets and configures preprocessors that extract
- * features from an upstream data and perform other desired changes over the extracted data.</p>
+ * After that it defines how to split the data to train and test sets and configures preprocessors that extract features
+ * from an upstream data and perform other desired changes over the extracted data.</p>
* <p>
- * Then, it tunes hyperparams with K-fold Cross-Validation on the split training set and trains the model based on
- * the processed data using decision tree classification and the obtained hyperparams.</p>
+ * Then, it tunes hyperparams with K-fold Cross-Validation on the split training set and trains the model based on the
+ * processed data using decision tree classification and the obtained hyperparams.</p>
* <p>
* Finally, this example uses {@link Evaluator} functionality to compute metrics from predictions.</p>
* <p>
@@ -62,13 +61,15 @@ import org.apache.ignite.ml.tree.DecisionTreeNode;
* <p>
* They differ in that {@code 1/(k-1)}th of the training data is exchanged against other cases.</p>
* <p>
- * These models are sometimes called surrogate models because the (average) performance measured for these models
- * is taken as a surrogate of the performance of the model trained on all cases.</p>
+ * These models are sometimes called surrogate models because the (average) performance measured for these models is
+ * taken as a surrogate of the performance of the model trained on all cases.</p>
* <p>
* All scenarios are described there: https://sebastianraschka.com/faq/docs/evaluate-a-model.html</p>
*/
public class Step_8_CV_with_Param_Grid_and_metrics {
- /** Run example. */
+ /**
+ * Run example.
+ */
public static void main(String[] args) {
System.out.println();
System.out.println(">>> Tutorial step 8 (cross-validation with param grid) example started.");
@@ -118,23 +119,18 @@ public class Step_8_CV_with_Param_Grid_and_metrics {
DecisionTreeClassificationTrainer trainerCV = new DecisionTreeClassificationTrainer();
- CrossValidation<DecisionTreeNode, Double, Integer, Vector> scoreCalculator
+ CrossValidation<DecisionTreeNode, Integer, Vector> scoreCalculator
= new CrossValidation<>();
ParamGrid paramGrid = new ParamGrid()
- .addHyperParam("maxDeep", trainerCV::withMaxDeep, new Double[]{1.0, 2.0, 3.0, 4.0, 5.0, 10.0})
- .addHyperParam("minImpurityDecrease", trainerCV::withMinImpurityDecrease, new Double[]{0.0, 0.25, 0.5});
-
- BinaryClassificationMetrics metrics = (BinaryClassificationMetrics) new BinaryClassificationMetrics()
- .withNegativeClsLb(0.0)
- .withPositiveClsLb(1.0)
- .withMetric(BinaryClassificationMetricValues::accuracy);
+ .addHyperParam("maxDeep", trainerCV::withMaxDeep, new Double[] {1.0, 2.0, 3.0, 4.0, 5.0, 10.0})
+ .addHyperParam("minImpurityDecrease", trainerCV::withMinImpurityDecrease, new Double[] {0.0, 0.25, 0.5});
scoreCalculator
.withIgnite(ignite)
.withUpstreamCache(dataCache)
.withTrainer(trainerCV)
- .withMetric(metrics)
+ .withMetric(MetricName.ACCURACY)
.withFilter(split.getTrainFilter())
.isRunningOnPipeline(false)
.withPreprocessor(normalizationPreprocessor)
@@ -170,8 +166,7 @@ public class Step_8_CV_with_Param_Grid_and_metrics {
System.out.println("\n>>> Trained model: " + bestMdl);
double accuracy = Evaluator.evaluate(
- dataCache,
- split.getTestFilter(),
+ dataCache, split.getTestFilter(),
bestMdl,
normalizationPreprocessor,
new Accuracy<>()
@@ -181,10 +176,12 @@ public class Step_8_CV_with_Param_Grid_and_metrics {
System.out.println("\n>>> Test Error " + (1 - accuracy));
System.out.println(">>> Tutorial step 8 (cross-validation with param grid) example started.");
- } catch (FileNotFoundException e) {
+ }
+ catch (FileNotFoundException e) {
e.printStackTrace();
}
- } finally {
+ }
+ finally {
System.out.flush();
}
}
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/tutorial/Step_8_CV_with_Param_Grid_and_metrics_and_pipeline.java b/examples/src/main/java/org/apache/ignite/examples/ml/tutorial/Step_8_CV_with_Param_Grid_and_metrics_and_pipeline.java
index 62c6737..1eddcb9 100644
--- a/examples/src/main/java/org/apache/ignite/examples/ml/tutorial/Step_8_CV_with_Param_Grid_and_metrics_and_pipeline.java
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/tutorial/Step_8_CV_with_Param_Grid_and_metrics_and_pipeline.java
@@ -32,8 +32,7 @@ import org.apache.ignite.ml.selection.cv.CrossValidation;
import org.apache.ignite.ml.selection.cv.CrossValidationResult;
import org.apache.ignite.ml.selection.paramgrid.ParamGrid;
import org.apache.ignite.ml.selection.scoring.evaluator.Evaluator;
-import org.apache.ignite.ml.selection.scoring.metric.classification.BinaryClassificationMetricValues;
-import org.apache.ignite.ml.selection.scoring.metric.classification.BinaryClassificationMetrics;
+import org.apache.ignite.ml.selection.scoring.metric.MetricName;
import org.apache.ignite.ml.selection.split.TrainTestDatasetSplitter;
import org.apache.ignite.ml.selection.split.TrainTestSplit;
import org.apache.ignite.ml.tree.DecisionTreeClassificationTrainer;
@@ -44,11 +43,11 @@ import org.apache.ignite.ml.tree.DecisionTreeNode;
* <p>
* Code in this example launches Ignite grid and fills the cache with test data (based on Titanic passengers data).</p>
* <p>
- * After that it defines how to split the data to train and test sets and configures preprocessors that extract
- * features from an upstream data and perform other desired changes over the extracted data.</p>
+ * After that it defines how to split the data to train and test sets and configures preprocessors that extract features
+ * from an upstream data and perform other desired changes over the extracted data.</p>
* <p>
- * Then, it tunes hyperparams with K-fold Cross-Validation on the split training set and trains the model based on
- * the processed data using decision tree classification and the obtained hyperparams.</p>
+ * Then, it tunes hyperparams with K-fold Cross-Validation on the split training set and trains the model based on the
+ * processed data using decision tree classification and the obtained hyperparams.</p>
* <p>
* Finally, this example uses {@link Evaluator} functionality to compute metrics from predictions.</p>
* <p>
@@ -58,13 +57,15 @@ import org.apache.ignite.ml.tree.DecisionTreeNode;
* <p>
* They differ in that {@code 1/(k-1)}th of the training data is exchanged against other cases.</p>
* <p>
- * These models are sometimes called surrogate models because the (average) performance measured for these models
- * is taken as a surrogate of the performance of the model trained on all cases.</p>
+ * These models are sometimes called surrogate models because the (average) performance measured for these models is
+ * taken as a surrogate of the performance of the model trained on all cases.</p>
* <p>
* All scenarios are described there: https://sebastianraschka.com/faq/docs/evaluate-a-model.html</p>
*/
public class Step_8_CV_with_Param_Grid_and_metrics_and_pipeline {
- /** Run example. */
+ /**
+ * Run example.
+ */
public static void main(String[] args) {
System.out.println();
System.out.println(">>> Tutorial step 8 (cross-validation with param grid) example started.");
@@ -90,23 +91,18 @@ public class Step_8_CV_with_Param_Grid_and_metrics_and_pipeline {
// Tune hyperparams with K-fold Cross-Validation on the split training set.
- CrossValidation<DecisionTreeNode, Double, Integer, Vector> scoreCalculator
+ CrossValidation<DecisionTreeNode, Integer, Vector> scoreCalculator
= new CrossValidation<>();
ParamGrid paramGrid = new ParamGrid()
- .addHyperParam("maxDeep", trainer::withMaxDeep, new Double[]{1.0, 2.0, 3.0, 4.0, 5.0, 10.0})
- .addHyperParam("minImpurityDecrease", trainer::withMinImpurityDecrease, new Double[]{0.0, 0.25, 0.5});
-
- BinaryClassificationMetrics metrics = (BinaryClassificationMetrics) new BinaryClassificationMetrics()
- .withNegativeClsLb(0.0)
- .withPositiveClsLb(1.0)
- .withMetric(BinaryClassificationMetricValues::accuracy);
+ .addHyperParam("maxDeep", trainer::withMaxDeep, new Double[] {1.0, 2.0, 3.0, 4.0, 5.0, 10.0})
+ .addHyperParam("minImpurityDecrease", trainer::withMinImpurityDecrease, new Double[] {0.0, 0.25, 0.5});
scoreCalculator
.withIgnite(ignite)
.withUpstreamCache(dataCache)
.withPipeline(pipeline)
- .withMetric(metrics)
+ .withMetric(MetricName.ACCURACY)
.withFilter(split.getTrainFilter())
.withPreprocessor(vectorizer)
.withAmountOfFolds(3)
@@ -126,10 +122,12 @@ public class Step_8_CV_with_Param_Grid_and_metrics_and_pipeline {
crossValidationRes.getScoringBoard().forEach((hyperParams, score)
-> System.out.println("Score " + Arrays.toString(score) + " for hyper params " + hyperParams));
- } catch (FileNotFoundException e) {
+ }
+ catch (FileNotFoundException e) {
e.printStackTrace();
}
- } finally {
+ }
+ finally {
System.out.flush();
}
}
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/tutorial/Step_9_Scaling_With_Stacking.java b/examples/src/main/java/org/apache/ignite/examples/ml/tutorial/Step_9_Scaling_With_Stacking.java
index babef3b..6e88a2f 100644
--- a/examples/src/main/java/org/apache/ignite/examples/ml/tutorial/Step_9_Scaling_With_Stacking.java
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/tutorial/Step_9_Scaling_With_Stacking.java
@@ -55,7 +55,9 @@ import org.apache.ignite.ml.tree.DecisionTreeClassificationTrainer;
* Finally, this example uses {@link Evaluator} functionality to compute metrics from predictions.</p>
*/
public class Step_9_Scaling_With_Stacking {
- /** Run example. */
+ /**
+ * Run example.
+ */
public static void main(String[] args) {
System.out.println();
System.out.println(">>> Tutorial step 5 (scaling) example started.");
@@ -130,10 +132,12 @@ public class Step_9_Scaling_With_Stacking {
System.out.println("\n>>> Test Error " + (1 - accuracy));
System.out.println(">>> Tutorial step 5 (scaling) example completed.");
- } catch (FileNotFoundException e) {
+ }
+ catch (FileNotFoundException e) {
e.printStackTrace();
}
- } finally {
+ }
+ finally {
System.out.flush();
}
}
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/tutorial/TitanicUtils.java b/examples/src/main/java/org/apache/ignite/examples/ml/tutorial/TitanicUtils.java
index 1de7059..3f177f0 100644
--- a/examples/src/main/java/org/apache/ignite/examples/ml/tutorial/TitanicUtils.java
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/tutorial/TitanicUtils.java
@@ -51,7 +51,7 @@ public class TitanicUtils {
int cnt = 0;
while (scanner.hasNextLine()) {
String row = scanner.nextLine();
- if(cnt == 0) {
+ if (cnt == 0) {
cnt++;
continue;
}
@@ -60,9 +60,10 @@ public class TitanicUtils {
NumberFormat format = NumberFormat.getInstance(Locale.FRANCE);
for (int i = 0; i < cells.length; i++)
- try{
+ try {
data[i] = "".equals(cells[i]) ? Double.NaN : Double.valueOf(cells[i]);
- } catch (java.lang.NumberFormatException e) {
+ }
+ catch (java.lang.NumberFormatException e) {
try {
data[i] = format.parse(cells[i]).doubleValue();
@@ -91,7 +92,7 @@ public class TitanicUtils {
int cnt = 0;
while (scanner.hasNextLine()) {
String row = scanner.nextLine();
- if(cnt == 0) {
+ if (cnt == 0) {
cnt++;
continue;
}
@@ -100,9 +101,10 @@ public class TitanicUtils {
NumberFormat format = NumberFormat.getInstance(Locale.FRANCE);
for (int i = 0; i < cells.length; i++)
- try{
+ try {
data[i] = "".equals(cells[i]) ? Double.NaN : Double.valueOf(cells[i]);
- } catch (java.lang.NumberFormatException e) {
+ }
+ catch (java.lang.NumberFormatException e) {
try {
data[i] = format.parse(cells[i]).doubleValue();
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/tutorial/TutorialStepByStepExample.java b/examples/src/main/java/org/apache/ignite/examples/ml/tutorial/TutorialStepByStepExample.java
index 0c96a0f..4da159d 100644
--- a/examples/src/main/java/org/apache/ignite/examples/ml/tutorial/TutorialStepByStepExample.java
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/tutorial/TutorialStepByStepExample.java
@@ -24,11 +24,13 @@ import org.apache.ignite.examples.ml.tutorial.hyperparametertuning.Step_13_Genet
import org.apache.ignite.examples.ml.tutorial.hyperparametertuning.Step_14_Parallel_Genetic_Programming_Search;
/**
- * Run all the tutorial examples step by step with primary purpose to provide
- * automatic execution from {@code IgniteExamplesMLTestSuite}.
+ * Run all the tutorial examples step by step with primary purpose to provide automatic execution from {@code
+ * IgniteExamplesMLTestSuite}.
*/
public class TutorialStepByStepExample {
- /** Run examples with default settings. */
+ /**
+ * Run examples with default settings.
+ */
public static void main(String[] args) {
Step_1_Read_and_Learn.main(args);
Step_2_Imputing.main(args);
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/tutorial/hyperparametertuning/Step_10_RandomSearch.java b/examples/src/main/java/org/apache/ignite/examples/ml/tutorial/hyperparametertuning/Step_10_RandomSearch.java
index 77a2724..65c166e 100644
--- a/examples/src/main/java/org/apache/ignite/examples/ml/tutorial/hyperparametertuning/Step_10_RandomSearch.java
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/tutorial/hyperparametertuning/Step_10_RandomSearch.java
@@ -37,9 +37,8 @@ import org.apache.ignite.ml.selection.cv.CrossValidationResult;
import org.apache.ignite.ml.selection.paramgrid.ParamGrid;
import org.apache.ignite.ml.selection.paramgrid.RandomStrategy;
import org.apache.ignite.ml.selection.scoring.evaluator.Evaluator;
+import org.apache.ignite.ml.selection.scoring.metric.MetricName;
import org.apache.ignite.ml.selection.scoring.metric.classification.Accuracy;
-import org.apache.ignite.ml.selection.scoring.metric.classification.BinaryClassificationMetricValues;
-import org.apache.ignite.ml.selection.scoring.metric.classification.BinaryClassificationMetrics;
import org.apache.ignite.ml.selection.split.TrainTestDatasetSplitter;
import org.apache.ignite.ml.selection.split.TrainTestSplit;
import org.apache.ignite.ml.tree.DecisionTreeClassificationTrainer;
@@ -50,11 +49,11 @@ import org.apache.ignite.ml.tree.DecisionTreeNode;
* <p>
* Code in this example launches Ignite grid and fills the cache with test data (based on Titanic passengers data).</p>
* <p>
- * After that it defines how to split the data to train and test sets and configures preprocessors that extract
- * features from an upstream data and perform other desired changes over the extracted data.</p>
+ * After that it defines how to split the data to train and test sets and configures preprocessors that extract features
+ * from an upstream data and perform other desired changes over the extracted data.</p>
* <p>
- * Then, it tunes hyperparams with K-fold Cross-Validation on the split training set and trains the model based on
- * the processed data using decision tree classification and the obtained hyperparams.</p>
+ * Then, it tunes hyperparams with K-fold Cross-Validation on the split training set and trains the model based on the
+ * processed data using decision tree classification and the obtained hyperparams.</p>
* <p>
* Finally, this example uses {@link Evaluator} functionality to compute metrics from predictions.</p>
* <p>
@@ -64,13 +63,15 @@ import org.apache.ignite.ml.tree.DecisionTreeNode;
* <p>
* They differ in that {@code 1/(k-1)}th of the training data is exchanged against other cases.</p>
* <p>
- * These models are sometimes called surrogate models because the (average) performance measured for these models
- * is taken as a surrogate of the performance of the model trained on all cases.</p>
+ * These models are sometimes called surrogate models because the (average) performance measured for these models is
+ * taken as a surrogate of the performance of the model trained on all cases.</p>
* <p>
* All scenarios are described there: https://sebastianraschka.com/faq/docs/evaluate-a-model.html</p>
*/
public class Step_10_RandomSearch {
- /** Run example. */
+ /**
+ * Run example.
+ */
public static void main(String[] args) {
try (Ignite ignite = Ignition.start("examples/config/example-ignite.xml")) {
try {
@@ -119,7 +120,7 @@ public class Step_10_RandomSearch {
DecisionTreeClassificationTrainer trainerCV = new DecisionTreeClassificationTrainer();
- CrossValidation<DecisionTreeNode, Double, Integer, Vector> scoreCalculator
+ CrossValidation<DecisionTreeNode, Integer, Vector> scoreCalculator
= new CrossValidation<>();
ParamGrid paramGrid = new ParamGrid()
@@ -128,20 +129,15 @@ public class Step_10_RandomSearch {
.withMaxTries(10)
.withSeed(12L)
)
- .addHyperParam("p", normalizationTrainer::withP, new Double[]{1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0})
- .addHyperParam("maxDeep", trainerCV::withMaxDeep, new Double[]{1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0})
- .addHyperParam("minImpurityDecrease", trainerCV::withMinImpurityDecrease, new Double[]{0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0});
-
- BinaryClassificationMetrics metrics = (BinaryClassificationMetrics) new BinaryClassificationMetrics()
- .withNegativeClsLb(0.0)
- .withPositiveClsLb(1.0)
- .withMetric(BinaryClassificationMetricValues::accuracy);
+ .addHyperParam("p", normalizationTrainer::withP, new Double[] {1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0})
+ .addHyperParam("maxDeep", trainerCV::withMaxDeep, new Double[] {1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0})
+ .addHyperParam("minImpurityDecrease", trainerCV::withMinImpurityDecrease, new Double[] {0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0});
scoreCalculator
.withIgnite(ignite)
.withUpstreamCache(dataCache)
.withTrainer(trainerCV)
- .withMetric(metrics)
+ .withMetric(MetricName.ACCURACY)
.withFilter(split.getTrainFilter())
.isRunningOnPipeline(false)
.withPreprocessor(normalizationPreprocessor)
@@ -177,8 +173,7 @@ public class Step_10_RandomSearch {
System.out.println("\n>>> Trained model: " + bestMdl);
double accuracy = Evaluator.evaluate(
- dataCache,
- split.getTestFilter(),
+ dataCache, split.getTestFilter(),
bestMdl,
normalizationPreprocessor,
new Accuracy<>()
@@ -188,10 +183,12 @@ public class Step_10_RandomSearch {
System.out.println("\n>>> Test Error " + (1 - accuracy));
System.out.println(">>> Tutorial step 8 (cross-validation with param grid) example started.");
- } catch (FileNotFoundException e) {
+ }
+ catch (FileNotFoundException e) {
e.printStackTrace();
}
- } finally {
+ }
+ finally {
System.out.flush();
}
}
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/tutorial/hyperparametertuning/Step_11_Parallel_BrutForce_Search.java b/examples/src/main/java/org/apache/ignite/examples/ml/tutorial/hyperparametertuning/Step_11_Parallel_BrutForce_Search.java
index 9c8cff4..9e92535 100644
--- a/examples/src/main/java/org/apache/ignite/examples/ml/tutorial/hyperparametertuning/Step_11_Parallel_BrutForce_Search.java
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/tutorial/hyperparametertuning/Step_11_Parallel_BrutForce_Search.java
@@ -40,9 +40,8 @@ import org.apache.ignite.ml.selection.cv.CrossValidationResult;
import org.apache.ignite.ml.selection.paramgrid.BruteForceStrategy;
import org.apache.ignite.ml.selection.paramgrid.ParamGrid;
import org.apache.ignite.ml.selection.scoring.evaluator.Evaluator;
+import org.apache.ignite.ml.selection.scoring.metric.MetricName;
import org.apache.ignite.ml.selection.scoring.metric.classification.Accuracy;
-import org.apache.ignite.ml.selection.scoring.metric.classification.BinaryClassificationMetricValues;
-import org.apache.ignite.ml.selection.scoring.metric.classification.BinaryClassificationMetrics;
import org.apache.ignite.ml.selection.split.TrainTestDatasetSplitter;
import org.apache.ignite.ml.selection.split.TrainTestSplit;
import org.apache.ignite.ml.tree.DecisionTreeClassificationTrainer;
@@ -53,11 +52,11 @@ import org.apache.ignite.ml.tree.DecisionTreeNode;
* <p>
* Code in this example launches Ignite grid and fills the cache with test data (based on Titanic passengers data).</p>
* <p>
- * After that it defines how to split the data to train and test sets and configures preprocessors that extract
- * features from an upstream data and perform other desired changes over the extracted data.</p>
+ * After that it defines how to split the data to train and test sets and configures preprocessors that extract features
+ * from an upstream data and perform other desired changes over the extracted data.</p>
* <p>
- * Then, it tunes hyperparams with K-fold Cross-Validation on the split training set and trains the model based on
- * the processed data using decision tree classification and the obtained hyperparams.</p>
+ * Then, it tunes hyperparams with K-fold Cross-Validation on the split training set and trains the model based on the
+ * processed data using decision tree classification and the obtained hyperparams.</p>
* <p>
* Finally, this example uses {@link Evaluator} functionality to compute metrics from predictions.</p>
* <p>
@@ -67,13 +66,15 @@ import org.apache.ignite.ml.tree.DecisionTreeNode;
* <p>
* They differ in that {@code 1/(k-1)}th of the training data is exchanged against other cases.</p>
* <p>
- * These models are sometimes called surrogate models because the (average) performance measured for these models
- * is taken as a surrogate of the performance of the model trained on all cases.</p>
+ * These models are sometimes called surrogate models because the (average) performance measured for these models is
+ * taken as a surrogate of the performance of the model trained on all cases.</p>
* <p>
* All scenarios are described there: https://sebastianraschka.com/faq/docs/evaluate-a-model.html</p>
*/
public class Step_11_Parallel_BrutForce_Search {
- /** Run example. */
+ /**
+ * Run example.
+ */
public static void main(String[] args) {
try (Ignite ignite = Ignition.start("examples/config/example-ignite.xml")) {
try {
@@ -122,19 +123,14 @@ public class Step_11_Parallel_BrutForce_Search {
DecisionTreeClassificationTrainer trainerCV = new DecisionTreeClassificationTrainer();
- CrossValidation<DecisionTreeNode, Double, Integer, Vector> scoreCalculator
+ CrossValidation<DecisionTreeNode, Integer, Vector> scoreCalculator
= new CrossValidation<>();
ParamGrid paramGrid = new ParamGrid()
.withParameterSearchStrategy(new BruteForceStrategy())
- .addHyperParam("p", normalizationTrainer::withP, new Double[]{1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0})
- .addHyperParam("maxDeep", trainerCV::withMaxDeep, new Double[]{1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0})
- .addHyperParam("minImpurityDecrease", trainerCV::withMinImpurityDecrease, new Double[]{0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0});
-
- BinaryClassificationMetrics metrics = (BinaryClassificationMetrics) new BinaryClassificationMetrics()
- .withNegativeClsLb(0.0)
- .withPositiveClsLb(1.0)
- .withMetric(BinaryClassificationMetricValues::accuracy);
+ .addHyperParam("p", normalizationTrainer::withP, new Double[] {1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0})
+ .addHyperParam("maxDeep", trainerCV::withMaxDeep, new Double[] {1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0})
+ .addHyperParam("minImpurityDecrease", trainerCV::withMinImpurityDecrease, new Double[] {0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0});
scoreCalculator
.withIgnite(ignite)
@@ -144,7 +140,7 @@ public class Step_11_Parallel_BrutForce_Search {
.withLoggingFactoryDependency(ConsoleLogger.Factory.LOW))
.withTrainer(trainerCV)
.isRunningOnPipeline(false)
- .withMetric(metrics)
+ .withMetric(MetricName.ACCURACY)
.withFilter(split.getTrainFilter())
.withPreprocessor(normalizationPreprocessor)
.withAmountOfFolds(3)
@@ -179,8 +175,7 @@ public class Step_11_Parallel_BrutForce_Search {
System.out.println("\n>>> Trained model: " + bestMdl);
double accuracy = Evaluator.evaluate(
- dataCache,
- split.getTestFilter(),
+ dataCache, split.getTestFilter(),
bestMdl,
normalizationPreprocessor,
new Accuracy<>()
@@ -190,10 +185,12 @@ public class Step_11_Parallel_BrutForce_Search {
System.out.println("\n>>> Test Error " + (1 - accuracy));
System.out.println(">>> Tutorial step 8 (cross-validation with param grid) example started.");
- } catch (FileNotFoundException e) {
+ }
+ catch (FileNotFoundException e) {
e.printStackTrace();
}
- } finally {
+ }
+ finally {
System.out.flush();
}
}
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/tutorial/hyperparametertuning/Step_12_Parallel_Random_Search.java b/examples/src/main/java/org/apache/ignite/examples/ml/tutorial/hyperparametertuning/Step_12_Parallel_Random_Search.java
index c3d8747..e65c85a 100644
--- a/examples/src/main/java/org/apache/ignite/examples/ml/tutorial/hyperparametertuning/Step_12_Parallel_Random_Search.java
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/tutorial/hyperparametertuning/Step_12_Parallel_Random_Search.java
@@ -40,9 +40,8 @@ import org.apache.ignite.ml.selection.cv.CrossValidationResult;
import org.apache.ignite.ml.selection.paramgrid.ParamGrid;
import org.apache.ignite.ml.selection.paramgrid.RandomStrategy;
import org.apache.ignite.ml.selection.scoring.evaluator.Evaluator;
+import org.apache.ignite.ml.selection.scoring.metric.MetricName;
import org.apache.ignite.ml.selection.scoring.metric.classification.Accuracy;
-import org.apache.ignite.ml.selection.scoring.metric.classification.BinaryClassificationMetricValues;
-import org.apache.ignite.ml.selection.scoring.metric.classification.BinaryClassificationMetrics;
import org.apache.ignite.ml.selection.split.TrainTestDatasetSplitter;
import org.apache.ignite.ml.selection.split.TrainTestSplit;
import org.apache.ignite.ml.tree.DecisionTreeClassificationTrainer;
@@ -53,11 +52,11 @@ import org.apache.ignite.ml.tree.DecisionTreeNode;
* <p>
* Code in this example launches Ignite grid and fills the cache with test data (based on Titanic passengers data).</p>
* <p>
- * After that it defines how to split the data to train and test sets and configures preprocessors that extract
- * features from an upstream data and perform other desired changes over the extracted data.</p>
+ * After that it defines how to split the data to train and test sets and configures preprocessors that extract features
+ * from an upstream data and perform other desired changes over the extracted data.</p>
* <p>
- * Then, it tunes hyperparams with K-fold Cross-Validation on the split training set and trains the model based on
- * the processed data using decision tree classification and the obtained hyperparams.</p>
+ * Then, it tunes hyperparams with K-fold Cross-Validation on the split training set and trains the model based on the
+ * processed data using decision tree classification and the obtained hyperparams.</p>
* <p>
* Finally, this example uses {@link Evaluator} functionality to compute metrics from predictions.</p>
* <p>
@@ -67,13 +66,15 @@ import org.apache.ignite.ml.tree.DecisionTreeNode;
* <p>
* They differ in that {@code 1/(k-1)}th of the training data is exchanged against other cases.</p>
* <p>
- * These models are sometimes called surrogate models because the (average) performance measured for these models
- * is taken as a surrogate of the performance of the model trained on all cases.</p>
+ * These models are sometimes called surrogate models because the (average) performance measured for these models is
+ * taken as a surrogate of the performance of the model trained on all cases.</p>
* <p>
* All scenarios are described there: https://sebastianraschka.com/faq/docs/evaluate-a-model.html</p>
*/
public class Step_12_Parallel_Random_Search {
- /** Run example. */
+ /**
+ * Run example.
+ */
public static void main(String[] args) {
try (Ignite ignite = Ignition.start("examples/config/example-ignite.xml")) {
try {
@@ -121,7 +122,7 @@ public class Step_12_Parallel_Random_Search {
// Tune hyperparams with K-fold Cross-Validation on the split training set.
DecisionTreeClassificationTrainer trainerCV = new DecisionTreeClassificationTrainer();
- CrossValidation<DecisionTreeNode, Double, Integer, Vector> scoreCalculator
+ CrossValidation<DecisionTreeNode, Integer, Vector> scoreCalculator
= new CrossValidation<>();
ParamGrid paramGrid = new ParamGrid()
@@ -130,14 +131,9 @@ public class Step_12_Parallel_Random_Search {
.withMaxTries(10)
.withSeed(12L)
)
- .addHyperParam("p", normalizationTrainer::withP, new Double[]{1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0})
- .addHyperParam("maxDeep", trainerCV::withMaxDeep, new Double[]{1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0})
- .addHyperParam("minImpurityDecrease", trainerCV::withMinImpurityDecrease, new Double[]{0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0});
-
- BinaryClassificationMetrics metrics = (BinaryClassificationMetrics) new BinaryClassificationMetrics()
- .withNegativeClsLb(0.0)
- .withPositiveClsLb(1.0)
- .withMetric(BinaryClassificationMetricValues::accuracy);
+ .addHyperParam("p", normalizationTrainer::withP, new Double[] {1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0})
+ .addHyperParam("maxDeep", trainerCV::withMaxDeep, new Double[] {1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0})
+ .addHyperParam("minImpurityDecrease", trainerCV::withMinImpurityDecrease, new Double[] {0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0});
scoreCalculator
.withIgnite(ignite)
@@ -147,7 +143,7 @@ public class Step_12_Parallel_Random_Search {
.withLoggingFactoryDependency(ConsoleLogger.Factory.LOW))
.withTrainer(trainerCV)
.isRunningOnPipeline(false)
- .withMetric(metrics)
+ .withMetric(MetricName.ACCURACY)
.withFilter(split.getTrainFilter())
.withPreprocessor(normalizationPreprocessor)
.withAmountOfFolds(3)
@@ -182,8 +178,7 @@ public class Step_12_Parallel_Random_Search {
System.out.println("\n>>> Trained model: " + bestMdl);
double accuracy = Evaluator.evaluate(
- dataCache,
- split.getTestFilter(),
+ dataCache, split.getTestFilter(),
bestMdl,
normalizationPreprocessor,
new Accuracy<>()
@@ -193,10 +188,12 @@ public class Step_12_Parallel_Random_Search {
System.out.println("\n>>> Test Error " + (1 - accuracy));
System.out.println(">>> Tutorial step 8 (cross-validation with param grid) example started.");
- } catch (FileNotFoundException e) {
+ }
+ catch (FileNotFoundException e) {
e.printStackTrace();
}
- } finally {
+ }
+ finally {
System.out.flush();
}
}
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/tutorial/hyperparametertuning/Step_13_Genetic_Programming_Search.java b/examples/src/main/java/org/apache/ignite/examples/ml/tutorial/hyperparametertuning/Step_13_Genetic_Programming_Search.java
index 248aba6..ba791ed 100644
--- a/examples/src/main/java/org/apache/ignite/examples/ml/tutorial/hyperparametertuning/Step_13_Genetic_Programming_Search.java
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/tutorial/hyperparametertuning/Step_13_Genetic_Programming_Search.java
@@ -37,9 +37,8 @@ import org.apache.ignite.ml.selection.cv.CrossValidationResult;
import org.apache.ignite.ml.selection.paramgrid.EvolutionOptimizationStrategy;
import org.apache.ignite.ml.selection.paramgrid.ParamGrid;
import org.apache.ignite.ml.selection.scoring.evaluator.Evaluator;
+import org.apache.ignite.ml.selection.scoring.metric.MetricName;
import org.apache.ignite.ml.selection.scoring.metric.classification.Accuracy;
-import org.apache.ignite.ml.selection.scoring.metric.classification.BinaryClassificationMetricValues;
-import org.apache.ignite.ml.selection.scoring.metric.classification.BinaryClassificationMetrics;
import org.apache.ignite.ml.selection.split.TrainTestDatasetSplitter;
import org.apache.ignite.ml.selection.split.TrainTestSplit;
import org.apache.ignite.ml.tree.DecisionTreeClassificationTrainer;
@@ -50,11 +49,11 @@ import org.apache.ignite.ml.tree.DecisionTreeNode;
* <p>
* Code in this example launches Ignite grid and fills the cache with test data (based on Titanic passengers data).</p>
* <p>
- * After that it defines how to split the data to train and test sets and configures preprocessors that extract
- * features from an upstream data and perform other desired changes over the extracted data.</p>
+ * After that it defines how to split the data to train and test sets and configures preprocessors that extract features
+ * from an upstream data and perform other desired changes over the extracted data.</p>
* <p>
- * Then, it tunes hyperparams with K-fold Cross-Validation on the split training set and trains the model based on
- * the processed data using decision tree classification and the obtained hyperparams.</p>
+ * Then, it tunes hyperparams with K-fold Cross-Validation on the split training set and trains the model based on the
+ * processed data using decision tree classification and the obtained hyperparams.</p>
* <p>
* Finally, this example uses {@link Evaluator} functionality to compute metrics from predictions.</p>
* <p>
@@ -64,13 +63,15 @@ import org.apache.ignite.ml.tree.DecisionTreeNode;
* <p>
* They differ in that {@code 1/(k-1)}th of the training data is exchanged against other cases.</p>
* <p>
- * These models are sometimes called surrogate models because the (average) performance measured for these models
- * is taken as a surrogate of the performance of the model trained on all cases.</p>
+ * These models are sometimes called surrogate models because the (average) performance measured for these models is
+ * taken as a surrogate of the performance of the model trained on all cases.</p>
* <p>
* All scenarios are described there: https://sebastianraschka.com/faq/docs/evaluate-a-model.html</p>
*/
public class Step_13_Genetic_Programming_Search {
- /** Run example. */
+ /**
+ * Run example.
+ */
public static void main(String[] args) {
try (Ignite ignite = Ignition.start("examples/config/example-ignite.xml")) {
try {
@@ -119,25 +120,20 @@ public class Step_13_Genetic_Programming_Search {
DecisionTreeClassificationTrainer trainerCV = new DecisionTreeClassificationTrainer();
- CrossValidation<DecisionTreeNode, Double, Integer, Vector> scoreCalculator
+ CrossValidation<DecisionTreeNode, Integer, Vector> scoreCalculator
= new CrossValidation<>();
ParamGrid paramGrid = new ParamGrid()
.withParameterSearchStrategy(new EvolutionOptimizationStrategy())
- .addHyperParam("p", normalizationTrainer::withP, new Double[]{1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0})
- .addHyperParam("maxDeep", trainerCV::withMaxDeep, new Double[]{1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0})
- .addHyperParam("minImpurityDecrease", trainerCV::withMinImpurityDecrease, new Double[]{0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0});
-
- BinaryClassificationMetrics metrics = (BinaryClassificationMetrics) new BinaryClassificationMetrics()
- .withNegativeClsLb(0.0)
- .withPositiveClsLb(1.0)
- .withMetric(BinaryClassificationMetricValues::accuracy);
+ .addHyperParam("p", normalizationTrainer::withP, new Double[] {1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0})
+ .addHyperParam("maxDeep", trainerCV::withMaxDeep, new Double[] {1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0})
+ .addHyperParam("minImpurityDecrease", trainerCV::withMinImpurityDecrease, new Double[] {0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0});
scoreCalculator
.withIgnite(ignite)
.withUpstreamCache(dataCache)
.withTrainer(trainerCV)
- .withMetric(metrics)
+ .withMetric(MetricName.ACCURACY)
.withFilter(split.getTrainFilter())
.isRunningOnPipeline(false)
.withPreprocessor(normalizationPreprocessor)
@@ -173,8 +169,7 @@ public class Step_13_Genetic_Programming_Search {
System.out.println("\n>>> Trained model: " + bestMdl);
double accuracy = Evaluator.evaluate(
- dataCache,
- split.getTestFilter(),
+ dataCache, split.getTestFilter(),
bestMdl,
normalizationPreprocessor,
new Accuracy<>()
@@ -184,10 +179,12 @@ public class Step_13_Genetic_Programming_Search {
System.out.println("\n>>> Test Error " + (1 - accuracy));
System.out.println(">>> Tutorial step 8 (cross-validation with param grid) example started.");
- } catch (FileNotFoundException e) {
+ }
+ catch (FileNotFoundException e) {
e.printStackTrace();
}
- } finally {
+ }
+ finally {
System.out.flush();
}
}
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/tutorial/hyperparametertuning/Step_14_Parallel_Genetic_Programming_Search.java b/examples/src/main/java/org/apache/ignite/examples/ml/tutorial/hyperparametertuning/Step_14_Parallel_Genetic_Programming_Search.java
index e262a03..79e3abd 100644
--- a/examples/src/main/java/org/apache/ignite/examples/ml/tutorial/hyperparametertuning/Step_14_Parallel_Genetic_Programming_Search.java
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/tutorial/hyperparametertuning/Step_14_Parallel_Genetic_Programming_Search.java
@@ -40,9 +40,8 @@ import org.apache.ignite.ml.selection.cv.CrossValidationResult;
import org.apache.ignite.ml.selection.paramgrid.EvolutionOptimizationStrategy;
import org.apache.ignite.ml.selection.paramgrid.ParamGrid;
import org.apache.ignite.ml.selection.scoring.evaluator.Evaluator;
+import org.apache.ignite.ml.selection.scoring.metric.MetricName;
import org.apache.ignite.ml.selection.scoring.metric.classification.Accuracy;
-import org.apache.ignite.ml.selection.scoring.metric.classification.BinaryClassificationMetricValues;
-import org.apache.ignite.ml.selection.scoring.metric.classification.BinaryClassificationMetrics;
import org.apache.ignite.ml.selection.split.TrainTestDatasetSplitter;
import org.apache.ignite.ml.selection.split.TrainTestSplit;
import org.apache.ignite.ml.tree.DecisionTreeClassificationTrainer;
@@ -53,11 +52,11 @@ import org.apache.ignite.ml.tree.DecisionTreeNode;
* <p>
* Code in this example launches Ignite grid and fills the cache with test data (based on Titanic passengers data).</p>
* <p>
- * After that it defines how to split the data to train and test sets and configures preprocessors that extract
- * features from an upstream data and perform other desired changes over the extracted data.</p>
+ * After that it defines how to split the data to train and test sets and configures preprocessors that extract features
+ * from an upstream data and perform other desired changes over the extracted data.</p>
* <p>
- * Then, it tunes hyperparams with K-fold Cross-Validation on the split training set and trains the model based on
- * the processed data using decision tree classification and the obtained hyperparams.</p>
+ * Then, it tunes hyperparams with K-fold Cross-Validation on the split training set and trains the model based on the
+ * processed data using decision tree classification and the obtained hyperparams.</p>
* <p>
* Finally, this example uses {@link Evaluator} functionality to compute metrics from predictions.</p>
* <p>
@@ -67,13 +66,15 @@ import org.apache.ignite.ml.tree.DecisionTreeNode;
* <p>
* They differ in that {@code 1/(k-1)}th of the training data is exchanged against other cases.</p>
* <p>
- * These models are sometimes called surrogate models because the (average) performance measured for these models
- * is taken as a surrogate of the performance of the model trained on all cases.</p>
+ * These models are sometimes called surrogate models because the (average) performance measured for these models is
+ * taken as a surrogate of the performance of the model trained on all cases.</p>
* <p>
* All scenarios are described there: https://sebastianraschka.com/faq/docs/evaluate-a-model.html</p>
*/
public class Step_14_Parallel_Genetic_Programming_Search {
- /** Run example. */
+ /**
+ * Run example.
+ */
public static void main(String[] args) {
try (Ignite ignite = Ignition.start("examples/config/example-ignite.xml")) {
try {
@@ -122,19 +123,14 @@ public class Step_14_Parallel_Genetic_Programming_Search {
DecisionTreeClassificationTrainer trainerCV = new DecisionTreeClassificationTrainer();
- CrossValidation<DecisionTreeNode, Double, Integer, Vector> scoreCalculator
+ CrossValidation<DecisionTreeNode, Integer, Vector> scoreCalculator
= new CrossValidation<>();
ParamGrid paramGrid = new ParamGrid()
.withParameterSearchStrategy(new EvolutionOptimizationStrategy())
- .addHyperParam("p", normalizationTrainer::withP, new Double[]{1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0})
- .addHyperParam("maxDeep", trainerCV::withMaxDeep, new Double[]{1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0})
- .addHyperParam("minImpurityDecrease", trainerCV::withMinImpurityDecrease, new Double[]{0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0});
-
- BinaryClassificationMetrics metrics = (BinaryClassificationMetrics) new BinaryClassificationMetrics()
- .withNegativeClsLb(0.0)
- .withPositiveClsLb(1.0)
- .withMetric(BinaryClassificationMetricValues::accuracy);
+ .addHyperParam("p", normalizationTrainer::withP, new Double[] {1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0})
+ .addHyperParam("maxDeep", trainerCV::withMaxDeep, new Double[] {1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0})
+ .addHyperParam("minImpurityDecrease", trainerCV::withMinImpurityDecrease, new Double[] {0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0});
scoreCalculator
.withIgnite(ignite)
@@ -143,7 +139,7 @@ public class Step_14_Parallel_Genetic_Programming_Search {
.withParallelismStrategyTypeDependency(ParallelismStrategy.ON_DEFAULT_POOL)
.withLoggingFactoryDependency(ConsoleLogger.Factory.LOW))
.withTrainer(trainerCV)
- .withMetric(metrics)
+ .withMetric(MetricName.ACCURACY)
.withFilter(split.getTrainFilter())
.isRunningOnPipeline(false)
.withPreprocessor(normalizationPreprocessor)
@@ -179,8 +175,7 @@ public class Step_14_Parallel_Genetic_Programming_Search {
System.out.println("\n>>> Trained model: " + bestMdl);
double accuracy = Evaluator.evaluate(
- dataCache,
- split.getTestFilter(),
+ dataCache, split.getTestFilter(),
bestMdl,
normalizationPreprocessor,
new Accuracy<>()
@@ -190,10 +185,12 @@ public class Step_14_Parallel_Genetic_Programming_Search {
System.out.println("\n>>> Test Error " + (1 - accuracy));
System.out.println(">>> Tutorial step 8 (cross-validation with param grid) example started.");
- } catch (FileNotFoundException e) {
+ }
+ catch (FileNotFoundException e) {
e.printStackTrace();
}
- } finally {
+ }
+ finally {
System.out.flush();
}
}
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/tutorial/package-info.java b/examples/src/main/java/org/apache/ignite/examples/ml/tutorial/package-info.java
index 067637d..275cdb4 100644
--- a/examples/src/main/java/org/apache/ignite/examples/ml/tutorial/package-info.java
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/tutorial/package-info.java
@@ -16,7 +16,6 @@
*/
/**
- * <!-- Package description. -->
- * Full ML Tutorial.
+ * <!-- Package description. --> Full ML Tutorial.
*/
package org.apache.ignite.examples.ml.tutorial;
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/util/DatasetHelper.java b/examples/src/main/java/org/apache/ignite/examples/ml/util/DatasetHelper.java
index c904c27..a963191 100644
--- a/examples/src/main/java/org/apache/ignite/examples/ml/util/DatasetHelper.java
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/util/DatasetHelper.java
@@ -24,15 +24,21 @@ import org.apache.ignite.ml.dataset.primitive.SimpleDataset;
* Common utility code used in some ML examples to report some statistic metrics of the dataset.
*/
public class DatasetHelper {
- /** */
+ /**
+ *
+ */
private final SimpleDataset dataset;
- /** */
+ /**
+ *
+ */
public DatasetHelper(SimpleDataset dataset) {
this.dataset = dataset;
}
- /** */
+ /**
+ *
+ */
public void describe() {
// Calculation of the mean value. This calculation will be performed in map-reduce manner.
double[] mean = dataset.mean();
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/util/MLExamplesCommonArgs.java b/examples/src/main/java/org/apache/ignite/examples/ml/util/MLExamplesCommonArgs.java
index 2f4e8c8..c84f112 100644
--- a/examples/src/main/java/org/apache/ignite/examples/ml/util/MLExamplesCommonArgs.java
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/util/MLExamplesCommonArgs.java
@@ -26,6 +26,8 @@ public class MLExamplesCommonArgs {
*/
public static final String UNATTENDED = "unattended";
- /** Empty args for ML examples. */
+ /**
+ * Empty args for ML examples.
+ */
public static final String[] EMPTY_ARGS_ML = new String[] {"--" + UNATTENDED};
}
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/util/generators/ParametricVectorGeneratorExample.java b/examples/src/main/java/org/apache/ignite/examples/ml/util/generators/ParametricVectorGeneratorExample.java
index fb35b8a..6a735cc 100644
--- a/examples/src/main/java/org/apache/ignite/examples/ml/util/generators/ParametricVectorGeneratorExample.java
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/util/generators/ParametricVectorGeneratorExample.java
@@ -24,10 +24,9 @@ import org.apache.ignite.ml.util.generators.primitives.scalar.UniformRandomProdu
import org.apache.ignite.ml.util.generators.primitives.vector.ParametricVectorGenerator;
/**
- * Examples of using {@link ParametricVectorGenerator} for generating two dimensional data.
- * {@link ParametricVectorGenerator} allows to create surfaces in N-dinensional spaces where each
- * dimension depends on one parameter 't'. In such generator just one random producer is used, it
- * defines a set of values for parameter 't'.
+ * Examples of using {@link ParametricVectorGenerator} for generating two dimensional data. {@link
+ * ParametricVectorGenerator} allows to create surfaces in N-dinensional spaces where each dimension depends on one
+ * parameter 't'. In such generator just one random producer is used, it defines a set of values for parameter 't'.
*/
public class ParametricVectorGeneratorExample {
/**
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/util/generators/StandardGeneratorsExample.java b/examples/src/main/java/org/apache/ignite/examples/ml/util/generators/StandardGeneratorsExample.java
index 621ebc4..96d1d8e 100644
--- a/examples/src/main/java/org/apache/ignite/examples/ml/util/generators/StandardGeneratorsExample.java
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/util/generators/StandardGeneratorsExample.java
@@ -26,8 +26,8 @@ import org.apache.ignite.ml.util.generators.standard.RingsDataStream;
import org.apache.ignite.ml.util.generators.standard.TwoSeparableClassesDataStream;
/**
- * Examples of using standard dataset generators. Standard dataset generator represents a
- * toy datasets that can be used for algorithms testing.
+ * Examples of using standard dataset generators. Standard dataset generator represents a toy datasets that can be used
+ * for algorithms testing.
*/
public class StandardGeneratorsExample {
/**
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/util/generators/VectorGeneratorFamilyExample.java b/examples/src/main/java/org/apache/ignite/examples/ml/util/generators/VectorGeneratorFamilyExample.java
index ff71877..4c826e6 100644
--- a/examples/src/main/java/org/apache/ignite/examples/ml/util/generators/VectorGeneratorFamilyExample.java
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/util/generators/VectorGeneratorFamilyExample.java
@@ -24,9 +24,9 @@ import org.apache.ignite.ml.util.generators.primitives.vector.VectorGeneratorPri
import org.apache.ignite.ml.util.generators.primitives.vector.VectorGeneratorsFamily;
/**
- * Example of using distribution families. Each distribution from family represents a class. Distribution family
- * is a distribution hence such family can be used as element of hight-level family where this distribution will
- * represent one class. Such families helps to construct ditributions with complex shape.
+ * Example of using distribution families. Each distribution from family represents a class. Distribution family is a
+ * distribution hence such family can be used as element of hight-level family where this distribution will represent
+ * one class. Such families helps to construct ditributions with complex shape.
*/
public class VectorGeneratorFamilyExample {
/**
@@ -47,7 +47,7 @@ public class VectorGeneratorFamilyExample {
.build();
// Family that constructed by 45 degree rotation from previous family.
- VectorGenerator family2 = family1.rotate(Math.PI/ 4).map(v -> v.times(1.5));
+ VectorGenerator family2 = family1.rotate(Math.PI / 4).map(v -> v.times(1.5));
Tracer.showClassificationDatasetHtml("Family of ring sectors [first family]", family1.asDataStream(),
2000, 0, 1, true);
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/util/generators/package-info.java b/examples/src/main/java/org/apache/ignite/examples/ml/util/generators/package-info.java
index e62b15e..5760d10 100644
--- a/examples/src/main/java/org/apache/ignite/examples/ml/util/generators/package-info.java
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/util/generators/package-info.java
@@ -16,7 +16,6 @@
*/
/**
- * <!-- Package description. -->
- * Examples for data stream generators.
+ * <!-- Package description. --> Examples for data stream generators.
*/
package org.apache.ignite.examples.ml.util.generators;
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/util/package-info.java b/examples/src/main/java/org/apache/ignite/examples/ml/util/package-info.java
index b5dfb62..b82e963 100644
--- a/examples/src/main/java/org/apache/ignite/examples/ml/util/package-info.java
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/util/package-info.java
@@ -16,8 +16,7 @@
*/
/**
- * <!-- Package description. -->
- * Utilities for machine learning examples.
+ * <!-- Package description. --> Utilities for machine learning examples.
*/
package org.apache.ignite.examples.ml.util;
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/xgboost/XGBoostModelParserExample.java b/examples/src/main/java/org/apache/ignite/examples/ml/xgboost/XGBoostModelParserExample.java
index 39162d9..9f9c6f9 100644
--- a/examples/src/main/java/org/apache/ignite/examples/ml/xgboost/XGBoostModelParserExample.java
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/xgboost/XGBoostModelParserExample.java
@@ -40,19 +40,29 @@ import org.apache.ignite.ml.xgboost.parser.XGModelParser;
* Ignite.
*/
public class XGBoostModelParserExample {
- /** Test model resource name. */
+ /**
+ * Test model resource name.
+ */
private static final String TEST_MODEL_RES = "examples/src/main/resources/models/xgboost/agaricus-model.txt";
- /** Test data. */
+ /**
+ * Test data.
+ */
private static final String TEST_DATA_RES = "examples/src/main/resources/datasets/agaricus-test-data.txt";
- /** Test expected results. */
+ /**
+ * Test expected results.
+ */
private static final String TEST_ER_RES = "examples/src/main/resources/datasets/agaricus-test-expected-results.txt";
- /** Parser. */
+ /**
+ * Parser.
+ */
private static final XGModelParser parser = new XGModelParser();
- /** Run example. */
+ /**
+ * Run example.
+ */
public static void main(String... args) throws ExecutionException, InterruptedException, FileNotFoundException {
try (Ignite ignite = Ignition.start("examples/config/example-ignite.xml")) {
File mdlRsrc = IgniteUtils.resolveIgnitePath(TEST_MODEL_RES);
@@ -95,7 +105,8 @@ public class XGBoostModelParserExample {
System.out.println("Expected: " + expPrediction + ", prediction: " + prediction);
}
}
- } finally {
+ }
+ finally {
System.out.flush();
}
}
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/xgboost/package-info.java b/examples/src/main/java/org/apache/ignite/examples/ml/xgboost/package-info.java
index f73550f..f0c8db4 100644
--- a/examples/src/main/java/org/apache/ignite/examples/ml/xgboost/package-info.java
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/xgboost/package-info.java
@@ -16,8 +16,7 @@
*/
/**
- * <!-- Package description. -->
- * XGBoost model inference examples.
+ * <!-- Package description. --> XGBoost model inference examples.
*/
package org.apache.ignite.examples.ml.xgboost;
diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBasicWithPersistenceTestSuite.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBasicWithPersistenceTestSuite.java
index 2e252e5..fc7cb13 100644
--- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBasicWithPersistenceTestSuite.java
+++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBasicWithPersistenceTestSuite.java
@@ -34,8 +34,8 @@ import org.apache.ignite.internal.processors.cache.persistence.CheckpointReadLoc
import org.apache.ignite.internal.processors.cache.persistence.SingleNodePersistenceSslTest;
import org.apache.ignite.marshaller.GridMarshallerMappingConsistencyTest;
import org.apache.ignite.util.GridCommandHandlerClusterByClassTest;
-import org.apache.ignite.util.GridCommandHandlerTest;
import org.apache.ignite.util.GridCommandHandlerSslTest;
+import org.apache.ignite.util.GridCommandHandlerTest;
import org.apache.ignite.util.GridInternalTaskUnusedWalSegmentsTest;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteSpiDiscoverySelfTestSuite.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteSpiDiscoverySelfTestSuite.java
index 626aa3c..00704a5 100644
--- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteSpiDiscoverySelfTestSuite.java
+++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteSpiDiscoverySelfTestSuite.java
@@ -22,8 +22,8 @@ import org.apache.ignite.spi.ExponentialBackoffTimeoutStrategyTest;
import org.apache.ignite.spi.GridTcpSpiForwardingSelfTest;
import org.apache.ignite.spi.discovery.AuthenticationRestartTest;
import org.apache.ignite.spi.discovery.FilterDataForClientNodeDiscoveryTest;
-import org.apache.ignite.spi.discovery.IgniteDiscoveryCacheReuseSelfTest;
import org.apache.ignite.spi.discovery.IgniteClientReconnectEventHandlingTest;
+import org.apache.ignite.spi.discovery.IgniteDiscoveryCacheReuseSelfTest;
import org.apache.ignite.spi.discovery.LongClientConnectToClusterTest;
import org.apache.ignite.spi.discovery.tcp.DiscoveryUnmarshalVulnerabilityTest;
import org.apache.ignite.spi.discovery.tcp.IgniteClientConnectSslTest;
@@ -38,8 +38,8 @@ import org.apache.ignite.spi.discovery.tcp.TcpClientDiscoverySpiMulticastTest;
import org.apache.ignite.spi.discovery.tcp.TcpClientDiscoverySpiSelfTest;
import org.apache.ignite.spi.discovery.tcp.TcpClientDiscoveryUnresolvedHostTest;
import org.apache.ignite.spi.discovery.tcp.TcpDiscoveryClientSuspensionSelfTest;
-import org.apache.ignite.spi.discovery.tcp.TcpDiscoveryFailedJoinTest;
import org.apache.ignite.spi.discovery.tcp.TcpDiscoveryCoordinatorFailureTest;
+import org.apache.ignite.spi.discovery.tcp.TcpDiscoveryFailedJoinTest;
import org.apache.ignite.spi.discovery.tcp.TcpDiscoveryIpFinderCleanerTest;
import org.apache.ignite.spi.discovery.tcp.TcpDiscoveryMarshallerCheckSelfTest;
import org.apache.ignite.spi.discovery.tcp.TcpDiscoveryMultiThreadedTest;
diff --git a/modules/core/src/test/java/org/apache/ignite/util/GridCommandHandlerClusterByClassAbstractTest.java b/modules/core/src/test/java/org/apache/ignite/util/GridCommandHandlerClusterByClassAbstractTest.java
index ddb394e..e926efc 100644
--- a/modules/core/src/test/java/org/apache/ignite/util/GridCommandHandlerClusterByClassAbstractTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/util/GridCommandHandlerClusterByClassAbstractTest.java
@@ -17,13 +17,12 @@
package org.apache.ignite.util;
+import java.util.HashSet;
+import java.util.Set;
import org.apache.ignite.IgniteCache;
import org.apache.ignite.configuration.CacheConfiguration;
import org.apache.ignite.internal.IgniteEx;
-import java.util.HashSet;
-import java.util.Set;
-
import static java.util.stream.Collectors.toSet;
import static java.util.stream.Stream.of;
diff --git a/modules/core/src/test/java/org/apache/ignite/util/GridCommandHandlerClusterByClassTest.java b/modules/core/src/test/java/org/apache/ignite/util/GridCommandHandlerClusterByClassTest.java
index 05dfd7e..008a160 100644
--- a/modules/core/src/test/java/org/apache/ignite/util/GridCommandHandlerClusterByClassTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/util/GridCommandHandlerClusterByClassTest.java
@@ -17,6 +17,24 @@
package org.apache.ignite.util;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeMap;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
import org.apache.ignite.Ignite;
import org.apache.ignite.IgniteCache;
import org.apache.ignite.IgniteCheckedException;
@@ -56,25 +74,6 @@ import org.apache.ignite.transactions.TransactionState;
import org.jetbrains.annotations.NotNull;
import org.junit.Test;
-import java.io.IOException;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.TreeMap;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.atomic.AtomicInteger;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
import static java.util.Arrays.asList;
import static java.util.stream.Collectors.toList;
import static java.util.stream.Stream.of;
diff --git a/modules/core/src/test/java/org/apache/ignite/util/GridCommandHandlerTest.java b/modules/core/src/test/java/org/apache/ignite/util/GridCommandHandlerTest.java
index b501255..8317560 100644
--- a/modules/core/src/test/java/org/apache/ignite/util/GridCommandHandlerTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/util/GridCommandHandlerTest.java
@@ -17,6 +17,31 @@
package org.apache.ignite.util;
+import java.io.File;
+import java.io.IOException;
+import java.io.RandomAccessFile;
+import java.io.Serializable;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeMap;
+import java.util.UUID;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.ThreadLocalRandom;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.concurrent.atomic.LongAdder;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import java.util.stream.Collectors;
+import javax.cache.processor.EntryProcessor;
+import javax.cache.processor.EntryProcessorException;
+import javax.cache.processor.MutableEntry;
import org.apache.ignite.Ignite;
import org.apache.ignite.IgniteAtomicSequence;
import org.apache.ignite.IgniteCache;
@@ -71,32 +96,6 @@ import org.apache.ignite.transactions.TransactionTimeoutException;
import org.jetbrains.annotations.NotNull;
import org.junit.Test;
-import javax.cache.processor.EntryProcessor;
-import javax.cache.processor.EntryProcessorException;
-import javax.cache.processor.MutableEntry;
-import java.io.File;
-import java.io.IOException;
-import java.io.RandomAccessFile;
-import java.io.Serializable;
-import java.nio.file.Files;
-import java.nio.file.Paths;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.TreeMap;
-import java.util.UUID;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.ThreadLocalRandom;
-import java.util.concurrent.atomic.AtomicBoolean;
-import java.util.concurrent.atomic.AtomicInteger;
-import java.util.concurrent.atomic.LongAdder;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-import java.util.stream.Collectors;
-
import static java.io.File.separatorChar;
import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL;
import static org.apache.ignite.cache.CacheMode.PARTITIONED;
diff --git a/modules/indexing/src/test/java/org/apache/ignite/util/GridCommandHandlerIndexingClusterByClassTest.java b/modules/indexing/src/test/java/org/apache/ignite/util/GridCommandHandlerIndexingClusterByClassTest.java
index a8a50cf..8dcac5d 100644
--- a/modules/indexing/src/test/java/org/apache/ignite/util/GridCommandHandlerIndexingClusterByClassTest.java
+++ b/modules/indexing/src/test/java/org/apache/ignite/util/GridCommandHandlerIndexingClusterByClassTest.java
@@ -17,6 +17,8 @@
package org.apache.ignite.util;
+import java.util.Iterator;
+import javax.cache.Cache;
import org.apache.ignite.Ignite;
import org.apache.ignite.IgniteCheckedException;
import org.apache.ignite.cache.query.ScanQuery;
@@ -34,14 +36,11 @@ import org.apache.ignite.internal.util.typedef.internal.CU;
import org.apache.ignite.internal.util.typedef.internal.U;
import org.junit.Test;
-import javax.cache.Cache;
-import java.util.Iterator;
-
import static org.apache.ignite.internal.commandline.CommandHandler.EXIT_CODE_OK;
import static org.apache.ignite.testframework.GridTestUtils.assertContains;
-import static org.apache.ignite.util.GridCommandHandlerIndexingUtils.createAndFillCache;
import static org.apache.ignite.util.GridCommandHandlerIndexingUtils.CACHE_NAME;
import static org.apache.ignite.util.GridCommandHandlerIndexingUtils.GROUP_NAME;
+import static org.apache.ignite.util.GridCommandHandlerIndexingUtils.createAndFillCache;
/**
* You can use this class if you don't need create nodes for each test because
diff --git a/modules/indexing/src/test/java/org/apache/ignite/util/GridCommandHandlerIndexingTest.java b/modules/indexing/src/test/java/org/apache/ignite/util/GridCommandHandlerIndexingTest.java
index c5ddfd7..822d51a 100644
--- a/modules/indexing/src/test/java/org/apache/ignite/util/GridCommandHandlerIndexingTest.java
+++ b/modules/indexing/src/test/java/org/apache/ignite/util/GridCommandHandlerIndexingTest.java
@@ -31,9 +31,9 @@ import org.junit.Test;
import static org.apache.ignite.internal.commandline.CommandHandler.EXIT_CODE_OK;
import static org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager.INDEX_FILE_NAME;
import static org.apache.ignite.testframework.GridTestUtils.assertContains;
-import static org.apache.ignite.util.GridCommandHandlerIndexingUtils.createAndFillCache;
import static org.apache.ignite.util.GridCommandHandlerIndexingUtils.CACHE_NAME;
import static org.apache.ignite.util.GridCommandHandlerIndexingUtils.GROUP_NAME;
+import static org.apache.ignite.util.GridCommandHandlerIndexingUtils.createAndFillCache;
/**
* If you not necessary create nodes for each test you can try use
diff --git a/modules/indexing/src/test/java/org/apache/ignite/util/GridCommandHandlerIndexingUtils.java b/modules/indexing/src/test/java/org/apache/ignite/util/GridCommandHandlerIndexingUtils.java
index 593d6e3..feb2a73 100644
--- a/modules/indexing/src/test/java/org/apache/ignite/util/GridCommandHandlerIndexingUtils.java
+++ b/modules/indexing/src/test/java/org/apache/ignite/util/GridCommandHandlerIndexingUtils.java
@@ -17,6 +17,8 @@
package org.apache.ignite.util;
+import java.io.Serializable;
+import java.util.concurrent.ThreadLocalRandom;
import org.apache.ignite.Ignite;
import org.apache.ignite.IgniteDataStreamer;
import org.apache.ignite.cache.CacheAtomicityMode;
@@ -27,9 +29,6 @@ import org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction;
import org.apache.ignite.configuration.CacheConfiguration;
import org.apache.ignite.internal.util.typedef.F;
-import java.io.Serializable;
-import java.util.concurrent.ThreadLocalRandom;
-
import static java.lang.String.valueOf;
import static java.util.Arrays.asList;
import static java.util.Objects.nonNull;
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/dataset/impl/cache/CacheBasedDatasetBuilder.java b/modules/ml/src/main/java/org/apache/ignite/ml/dataset/impl/cache/CacheBasedDatasetBuilder.java
index 0394ebd..c4b7997 100644
--- a/modules/ml/src/main/java/org/apache/ignite/ml/dataset/impl/cache/CacheBasedDatasetBuilder.java
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/dataset/impl/cache/CacheBasedDatasetBuilder.java
@@ -17,8 +17,6 @@
package org.apache.ignite.ml.dataset.impl.cache;
-import java.io.Serializable;
-import java.util.UUID;
import org.apache.ignite.Ignite;
import org.apache.ignite.IgniteCache;
import org.apache.ignite.cache.affinity.AffinityFunction;
@@ -33,6 +31,9 @@ import org.apache.ignite.ml.dataset.impl.cache.util.DatasetAffinityFunctionWrapp
import org.apache.ignite.ml.environment.LearningEnvironment;
import org.apache.ignite.ml.environment.LearningEnvironmentBuilder;
+import java.io.Serializable;
+import java.util.UUID;
+
/**
* A dataset builder that makes {@link CacheBasedDataset}. Encapsulate logic of building cache based dataset such as
* allocation required data structures and initialization of {@code context} part of partitions.
@@ -196,4 +197,13 @@ public class CacheBasedDatasetBuilder<K, V> implements DatasetBuilder<K, V> {
public CacheBasedDatasetBuilder<K, V> withRetriesNumber(int retries) {
return new CacheBasedDatasetBuilder<K, V>(ignite, upstreamCache, filter, transformerBuilder, upstreamKeepBinary, retries);
}
+
+ /**
+ * Returns upstream cache.
+ *
+ * @return Upstream cache.
+ */
+ public IgniteCache<K, V> getUpstreamCache() {
+ return upstreamCache;
+ }
}
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/selection/cv/AbstractCrossValidation.java b/modules/ml/src/main/java/org/apache/ignite/ml/selection/cv/AbstractCrossValidation.java
index 5f6a239..cc8e1d5 100644
--- a/modules/ml/src/main/java/org/apache/ignite/ml/selection/cv/AbstractCrossValidation.java
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/selection/cv/AbstractCrossValidation.java
@@ -17,17 +17,6 @@
package org.apache.ignite.ml.selection.cv;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Random;
-import java.util.function.BiFunction;
-import java.util.function.DoubleConsumer;
-import java.util.function.Function;
-import java.util.stream.Collectors;
import org.apache.ignite.lang.IgniteBiPredicate;
import org.apache.ignite.ml.IgniteModel;
import org.apache.ignite.ml.dataset.DatasetBuilder;
@@ -39,14 +28,10 @@ import org.apache.ignite.ml.math.primitives.vector.Vector;
import org.apache.ignite.ml.pipeline.Pipeline;
import org.apache.ignite.ml.pipeline.PipelineMdl;
import org.apache.ignite.ml.preprocessing.Preprocessor;
-import org.apache.ignite.ml.selection.paramgrid.BruteForceStrategy;
-import org.apache.ignite.ml.selection.paramgrid.EvolutionOptimizationStrategy;
-import org.apache.ignite.ml.selection.paramgrid.HyperParameterTuningStrategy;
-import org.apache.ignite.ml.selection.paramgrid.ParamGrid;
-import org.apache.ignite.ml.selection.paramgrid.ParameterSetGenerator;
-import org.apache.ignite.ml.selection.paramgrid.RandomStrategy;
-import org.apache.ignite.ml.selection.scoring.cursor.LabelPairCursor;
+import org.apache.ignite.ml.selection.paramgrid.*;
+import org.apache.ignite.ml.selection.scoring.evaluator.Evaluator;
import org.apache.ignite.ml.selection.scoring.metric.Metric;
+import org.apache.ignite.ml.selection.scoring.metric.MetricName;
import org.apache.ignite.ml.selection.split.mapper.SHA256UniformMapper;
import org.apache.ignite.ml.selection.split.mapper.UniformMapper;
import org.apache.ignite.ml.trainers.DatasetTrainer;
@@ -54,6 +39,12 @@ import org.apache.ignite.ml.util.genetic.Chromosome;
import org.apache.ignite.ml.util.genetic.GeneticAlgorithm;
import org.jetbrains.annotations.NotNull;
+import java.util.*;
+import java.util.function.BiFunction;
+import java.util.function.DoubleConsumer;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+
/**
* Cross validation score calculator. Cross validation is an approach that allows to avoid overfitting that is made the
* following way: the training set is split into k smaller sets. The following procedure is followed for each of the k
@@ -65,11 +56,10 @@ import org.jetbrains.annotations.NotNull;
* </ul>
*
* @param <M> Type of model.
- * @param <L> Type of a label (truth or prediction).
* @param <K> Type of a key in {@code upstream} data.
* @param <V> Type of a value in {@code upstream} data.
*/
-public abstract class AbstractCrossValidation<M extends IgniteModel<Vector, L>, L, K, V> {
+public abstract class AbstractCrossValidation<M extends IgniteModel<Vector, Double>, K, V> {
/** Learning environment builder. */
protected LearningEnvironmentBuilder envBuilder = LearningEnvironmentBuilder.defaultBuilder();
@@ -77,13 +67,13 @@ public abstract class AbstractCrossValidation<M extends IgniteModel<Vector, L>,
protected LearningEnvironment environment = envBuilder.buildForTrainer();
/** Trainer. */
- protected DatasetTrainer<M, L> trainer;
+ protected DatasetTrainer<M, Double> trainer;
/** Pipeline. */
protected Pipeline<K, V, Integer, Double> pipeline;
/** Metric. */
- protected Metric<L> metric;
+ protected Metric metric;
/** Preprocessor. */
protected Preprocessor<K, V> preprocessor;
@@ -325,11 +315,9 @@ public abstract class AbstractCrossValidation<M extends IgniteModel<Vector, L>,
* Computes cross-validated metrics.
*
* @param datasetBuilderSupplier Dataset builder supplier.
- * @param testDataIterSupplier Test data iterator supplier.
* @return Array of scores of the estimator for each run of the cross validation.
*/
- protected double[] score(Function<IgniteBiPredicate<K, V>, DatasetBuilder<K, V>> datasetBuilderSupplier,
- BiFunction<IgniteBiPredicate<K, V>, M, LabelPairCursor<L>> testDataIterSupplier) {
+ protected double[] score(Function<IgniteBiPredicate<K, V>, DatasetBuilder<K, V>> datasetBuilderSupplier) {
double[] scores = new double[amountOfFolds];
double foldSize = 1.0 / amountOfFolds;
@@ -342,14 +330,13 @@ public abstract class AbstractCrossValidation<M extends IgniteModel<Vector, L>,
return pnt < from || pnt > to;
};
- DatasetBuilder<K, V> datasetBuilder = datasetBuilderSupplier.apply(trainSetFilter);
- M mdl = trainer.fit(datasetBuilder, preprocessor); //TODO: IGNITE-11580
+ IgniteBiPredicate<K, V> testSetFilter = (k, v) -> !trainSetFilter.apply(k,v);
- try (LabelPairCursor<L> cursor = testDataIterSupplier.apply(trainSetFilter, mdl)) {
- scores[i] = metric.score(cursor.iterator());
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
+ DatasetBuilder<K, V> trainSet = datasetBuilderSupplier.apply(trainSetFilter);
+ M mdl = trainer.fit(trainSet, preprocessor); //TODO: IGNITE-11580
+
+ DatasetBuilder<K, V> testSet = datasetBuilderSupplier.apply(testSetFilter);
+ scores[i] = Evaluator.evaluate(testSet, mdl, preprocessor, metric).getSignle();
}
return scores;
@@ -359,11 +346,9 @@ public abstract class AbstractCrossValidation<M extends IgniteModel<Vector, L>,
* Computes cross-validated metrics.
*
* @param datasetBuilderSupplier Dataset builder supplier.
- * @param testDataIterSupplier Test data iterator supplier.
* @return Array of scores of the estimator for each run of the cross validation.
*/
- protected double[] scorePipeline(Function<IgniteBiPredicate<K, V>, DatasetBuilder<K, V>> datasetBuilderSupplier,
- BiFunction<IgniteBiPredicate<K, V>, M, LabelPairCursor<L>> testDataIterSupplier) {
+ protected double[] scorePipeline(Function<IgniteBiPredicate<K, V>, DatasetBuilder<K, V>> datasetBuilderSupplier) {
double[] scores = new double[amountOfFolds];
double foldSize = 1.0 / amountOfFolds;
@@ -376,14 +361,13 @@ public abstract class AbstractCrossValidation<M extends IgniteModel<Vector, L>,
return pnt < from || pnt > to;
};
+ IgniteBiPredicate<K, V> testSetFilter = (k, v) -> !trainSetFilter.apply(k,v);
+
DatasetBuilder<K, V> datasetBuilder = datasetBuilderSupplier.apply(trainSetFilter);
PipelineMdl<K, V> mdl = pipeline.fit(datasetBuilder);
- try (LabelPairCursor<L> cursor = testDataIterSupplier.apply(trainSetFilter, (M) mdl)) {
- scores[i] = metric.score(cursor.iterator());
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
+ DatasetBuilder<K, V> testSet = datasetBuilderSupplier.apply(testSetFilter);
+ scores[i] = Evaluator.evaluate(testSet, mdl, preprocessor, metric).getSignle();
}
return scores;
@@ -392,7 +376,7 @@ public abstract class AbstractCrossValidation<M extends IgniteModel<Vector, L>,
/**
* @param trainer Trainer.
*/
- public AbstractCrossValidation<M, L, K, V> withTrainer(DatasetTrainer<M, L> trainer) {
+ public AbstractCrossValidation<M, K, V> withTrainer(DatasetTrainer<M, Double> trainer) {
this.trainer = trainer;
return this;
}
@@ -400,15 +384,15 @@ public abstract class AbstractCrossValidation<M extends IgniteModel<Vector, L>,
/**
* @param metric Metric.
*/
- public AbstractCrossValidation<M, L, K, V> withMetric(Metric<L> metric) {
- this.metric = metric;
+ public AbstractCrossValidation<M, K, V> withMetric(MetricName metric) {
+ this.metric = metric.create();
return this;
}
/**
* @param preprocessor Preprocessor.
*/
- public AbstractCrossValidation<M, L, K, V> withPreprocessor(Preprocessor<K, V> preprocessor) {
+ public AbstractCrossValidation<M, K, V> withPreprocessor(Preprocessor<K, V> preprocessor) {
this.preprocessor = preprocessor;
return this;
}
@@ -416,7 +400,7 @@ public abstract class AbstractCrossValidation<M extends IgniteModel<Vector, L>,
/**
* @param filter Filter.
*/
- public AbstractCrossValidation<M, L, K, V> withFilter(IgniteBiPredicate<K, V> filter) {
+ public AbstractCrossValidation<M, K, V> withFilter(IgniteBiPredicate<K, V> filter) {
this.filter = filter;
return this;
}
@@ -424,7 +408,7 @@ public abstract class AbstractCrossValidation<M extends IgniteModel<Vector, L>,
/**
* @param amountOfFolds Amount of folds.
*/
- public AbstractCrossValidation<M, L, K, V> withAmountOfFolds(int amountOfFolds) {
+ public AbstractCrossValidation<M, K, V> withAmountOfFolds(int amountOfFolds) {
this.amountOfFolds = amountOfFolds;
return this;
}
@@ -432,7 +416,7 @@ public abstract class AbstractCrossValidation<M extends IgniteModel<Vector, L>,
/**
* @param paramGrid Parameter grid.
*/
- public AbstractCrossValidation<M, L, K, V> withParamGrid(ParamGrid paramGrid) {
+ public AbstractCrossValidation<M, K, V> withParamGrid(ParamGrid paramGrid) {
this.paramGrid = paramGrid;
return this;
}
@@ -440,7 +424,7 @@ public abstract class AbstractCrossValidation<M extends IgniteModel<Vector, L>,
/**
* @param runningOnPipeline Running on pipeline.
*/
- public AbstractCrossValidation<M, L, K, V> isRunningOnPipeline(boolean runningOnPipeline) {
+ public AbstractCrossValidation<M, K, V> isRunningOnPipeline(boolean runningOnPipeline) {
isRunningOnPipeline = runningOnPipeline;
return this;
}
@@ -451,7 +435,7 @@ public abstract class AbstractCrossValidation<M extends IgniteModel<Vector, L>,
* @param envBuilder Learning environment builder.
*/
// TODO: IGNITE-10441 Think about more elegant ways to perform fluent API.
- public AbstractCrossValidation<M, L, K, V> withEnvironmentBuilder(LearningEnvironmentBuilder envBuilder) {
+ public AbstractCrossValidation<M, K, V> withEnvironmentBuilder(LearningEnvironmentBuilder envBuilder) {
this.envBuilder = envBuilder;
environment = envBuilder.buildForTrainer();
@@ -461,7 +445,7 @@ public abstract class AbstractCrossValidation<M extends IgniteModel<Vector, L>,
/**
* @param pipeline Pipeline.
*/
- public AbstractCrossValidation<M, L, K, V> withPipeline(Pipeline<K, V, Integer, Double> pipeline) {
+ public AbstractCrossValidation<M, K, V> withPipeline(Pipeline<K, V, Integer, Double> pipeline) {
this.pipeline = pipeline;
return this;
}
@@ -469,7 +453,7 @@ public abstract class AbstractCrossValidation<M extends IgniteModel<Vector, L>,
/**
* @param mapper Mapper.
*/
- public AbstractCrossValidation<M, L, K, V> withMapper(UniformMapper<K, V> mapper) {
+ public AbstractCrossValidation<M, K, V> withMapper(UniformMapper<K, V> mapper) {
this.mapper = mapper;
return this;
}
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/selection/cv/CrossValidation.java b/modules/ml/src/main/java/org/apache/ignite/ml/selection/cv/CrossValidation.java
index 159285b..c390012 100644
--- a/modules/ml/src/main/java/org/apache/ignite/ml/selection/cv/CrossValidation.java
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/selection/cv/CrossValidation.java
@@ -22,8 +22,6 @@ import org.apache.ignite.IgniteCache;
import org.apache.ignite.ml.IgniteModel;
import org.apache.ignite.ml.dataset.impl.cache.CacheBasedDatasetBuilder;
import org.apache.ignite.ml.math.primitives.vector.Vector;
-import org.apache.ignite.ml.pipeline.PipelineMdl;
-import org.apache.ignite.ml.selection.scoring.cursor.CacheBasedLabelPairCursor;
/**
* Cross validation score calculator. Cross validation is an approach that allows to avoid overfitting that is made the
@@ -36,11 +34,10 @@ import org.apache.ignite.ml.selection.scoring.cursor.CacheBasedLabelPairCursor;
* </ul>
*
* @param <M> Type of model.
- * @param <L> Type of a label (truth or prediction).
* @param <K> Type of a key in {@code upstream} data.
* @param <V> Type of a value in {@code upstream} data.
*/
-public class CrossValidation<M extends IgniteModel<Vector, L>, L, K, V> extends AbstractCrossValidation<M, L, K, V> {
+public class CrossValidation<M extends IgniteModel<Vector, Double>, K, V> extends AbstractCrossValidation<M, K, V> {
/** Ignite. */
private Ignite ignite;
@@ -69,12 +66,6 @@ public class CrossValidation<M extends IgniteModel<Vector, L>, L, K, V> extends
ignite,
upstreamCache,
(k, v) -> filter.apply(k, v) && predicate.apply(k, v)
- ),
- (predicate, mdl) -> new CacheBasedLabelPairCursor<>(
- upstreamCache,
- (k, v) -> filter.apply(k, v) && !predicate.apply(k, v),
- ((PipelineMdl<K, V>) mdl).getPreprocessor(),
- mdl
)
);
}
@@ -90,12 +81,6 @@ public class CrossValidation<M extends IgniteModel<Vector, L>, L, K, V> extends
ignite,
upstreamCache,
(k, v) -> filter.apply(k, v) && predicate.apply(k, v)
- ),
- (predicate, mdl) -> new CacheBasedLabelPairCursor<>(
- upstreamCache,
- (k, v) -> filter.apply(k, v) && !predicate.apply(k, v),
- preprocessor,
- mdl
)
);
}
@@ -103,7 +88,7 @@ public class CrossValidation<M extends IgniteModel<Vector, L>, L, K, V> extends
/**
* @param ignite Ignite.
*/
- public CrossValidation<M, L, K, V> withIgnite(Ignite ignite) {
+ public CrossValidation<M, K, V> withIgnite(Ignite ignite) {
this.ignite = ignite;
return this;
}
@@ -111,7 +96,7 @@ public class CrossValidation<M extends IgniteModel<Vector, L>, L, K, V> extends
/**
* @param upstreamCache Upstream cache.
*/
- public CrossValidation<M, L, K, V> withUpstreamCache(IgniteCache<K, V> upstreamCache) {
+ public CrossValidation<M, K, V> withUpstreamCache(IgniteCache<K, V> upstreamCache) {
this.upstreamCache = upstreamCache;
return this;
}
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/selection/cv/DebugCrossValidation.java b/modules/ml/src/main/java/org/apache/ignite/ml/selection/cv/DebugCrossValidation.java
index afc1913..6ee2310 100644
--- a/modules/ml/src/main/java/org/apache/ignite/ml/selection/cv/DebugCrossValidation.java
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/selection/cv/DebugCrossValidation.java
@@ -17,11 +17,11 @@
package org.apache.ignite.ml.selection.cv;
-import java.util.Map;
import org.apache.ignite.ml.IgniteModel;
import org.apache.ignite.ml.dataset.impl.local.LocalDatasetBuilder;
import org.apache.ignite.ml.math.primitives.vector.Vector;
-import org.apache.ignite.ml.selection.scoring.cursor.LocalLabelPairCursor;
+
+import java.util.Map;
/**
* Cross validation score calculator. Cross validation is an approach that allows to avoid overfitting that is made the
@@ -34,11 +34,10 @@ import org.apache.ignite.ml.selection.scoring.cursor.LocalLabelPairCursor;
* </ul>
*
* @param <M> Type of model.
- * @param <L> Type of a label (truth or prediction).
* @param <K> Type of a key in {@code upstream} data.
* @param <V> Type of a value in {@code upstream} data.
*/
-public class DebugCrossValidation<M extends IgniteModel<Vector, L>, L, K, V> extends AbstractCrossValidation<M, L, K, V> {
+public class DebugCrossValidation<M extends IgniteModel<Vector, Double>, K, V> extends AbstractCrossValidation<M, K, V> {
/** Upstream map. */
private Map<K, V> upstreamMap;
@@ -67,12 +66,6 @@ public class DebugCrossValidation<M extends IgniteModel<Vector, L>, L, K, V> ext
upstreamMap,
(k, v) -> filter.apply(k, v) && predicate.apply(k, v),
parts
- ),
- (predicate, mdl) -> new LocalLabelPairCursor<>(
- upstreamMap,
- (k, v) -> filter.apply(k, v) && !predicate.apply(k, v),
- preprocessor,
- mdl
)
);
}
@@ -88,12 +81,6 @@ public class DebugCrossValidation<M extends IgniteModel<Vector, L>, L, K, V> ext
upstreamMap,
(k, v) -> filter.apply(k, v) && predicate.apply(k, v),
parts
- ),
- (predicate, mdl) -> new LocalLabelPairCursor<>(
- upstreamMap,
- (k, v) -> filter.apply(k, v) && !predicate.apply(k, v),
- preprocessor,
- mdl
)
);
}
@@ -101,7 +88,7 @@ public class DebugCrossValidation<M extends IgniteModel<Vector, L>, L, K, V> ext
/**
* @param upstreamMap Upstream map.
*/
- public DebugCrossValidation<M, L, K, V> withUpstreamMap(Map<K, V> upstreamMap) {
+ public DebugCrossValidation<M, K, V> withUpstreamMap(Map<K, V> upstreamMap) {
this.upstreamMap = upstreamMap;
return this;
}
@@ -109,7 +96,7 @@ public class DebugCrossValidation<M extends IgniteModel<Vector, L>, L, K, V> ext
/**
* @param parts Parts.
*/
- public DebugCrossValidation<M, L, K, V> withAmountOfParts(int parts) {
+ public DebugCrossValidation<M, K, V> withAmountOfParts(int parts) {
this.parts = parts;
return this;
}
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/selection/scoring/cursor/LocalLabelPairCursor.java b/modules/ml/src/main/java/org/apache/ignite/ml/selection/scoring/cursor/LocalLabelPairCursor.java
index f0be6ca..8c9d038 100644
--- a/modules/ml/src/main/java/org/apache/ignite/ml/selection/scoring/cursor/LocalLabelPairCursor.java
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/selection/scoring/cursor/LocalLabelPairCursor.java
@@ -17,9 +17,6 @@
package org.apache.ignite.ml.selection.scoring.cursor;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.NoSuchElementException;
import org.apache.ignite.lang.IgniteBiPredicate;
import org.apache.ignite.ml.IgniteModel;
import org.apache.ignite.ml.math.primitives.vector.Vector;
@@ -28,6 +25,10 @@ import org.apache.ignite.ml.selection.scoring.LabelPair;
import org.apache.ignite.ml.structures.LabeledVector;
import org.jetbrains.annotations.NotNull;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.NoSuchElementException;
+
/**
* Truth with prediction cursor based on a locally stored data.
*
@@ -57,9 +58,9 @@ public class LocalLabelPairCursor<L, K, V, T> implements LabelPairCursor<L> {
* @param mdl Model for inference.
*/
public LocalLabelPairCursor(Map<K, V> upstreamMap, IgniteBiPredicate<K, V> filter, Preprocessor<K, V> preprocessor,
- IgniteModel<Vector, L> mdl) {
+ IgniteModel<Vector, L> mdl) {
this.upstreamMap = upstreamMap;
- this.filter = filter;
+ this.filter = filter == null ? (k, v) -> true : filter;
this.preprocessor = preprocessor;
this.mdl = mdl;
}
@@ -95,14 +96,7 @@ public class LocalLabelPairCursor<L, K, V, T> implements LabelPairCursor<L> {
/** {@inheritDoc} */
@Override public boolean hasNext() {
- if (filter == null) {
- Map.Entry<K, V> entry = iter.next();
- nextEntry = entry;
- return iter.hasNext();
- }
-
- else
- findNext();
+ findNext();
return nextEntry != null;
}
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/selection/scoring/evaluator/EvaluationResult.java b/modules/ml/src/main/java/org/apache/ignite/ml/selection/scoring/evaluator/EvaluationResult.java
new file mode 100644
index 0000000..af74438
--- /dev/null
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/selection/scoring/evaluator/EvaluationResult.java
@@ -0,0 +1,96 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.selection.scoring.evaluator;
+
+import java.util.Map;
+import org.apache.ignite.internal.util.typedef.internal.A;
+import org.apache.ignite.ml.selection.scoring.metric.MetricName;
+
+/**
+ * Class represents an aggregation of metrics evaluation results.
+ */
+public class EvaluationResult {
+ /**
+ * Default precision.
+ */
+ private static final int DEFAULT_PRECISION = 3;
+
+ /**
+ * Estimated values with metric names.
+ */
+ private final Map<MetricName, Double> values;
+
+ /**
+ * Creates an instance of EvaluationResult class.
+ *
+ * @param values Values.
+ */
+ public EvaluationResult(Map<MetricName, Double> values) {
+ this.values = values;
+ }
+
+ /**
+ * Returns metric value by its name.
+ *
+ * @param name Name.
+ * @return Metric value.
+ */
+ public double get(MetricName name) {
+ return values.getOrDefault(name, Double.NaN);
+ }
+
+ /**
+ * Returns any computed metric value. This method is useful in case of computing just one metric.
+ *
+ * @return Metric value.
+ */
+ public double getSignle() {
+ A.ensure(values.size() == 1, "getSingle expects only one metric");
+ return values.values().stream().findFirst().get();
+ }
+
+ /**
+ * Returns a collection of metric name and value pairs.
+ *
+ * @return Collection of metric name and value pairs.
+ */
+ public Iterable<Map.Entry<MetricName, Double>> getAll() {
+ return values.entrySet();
+ }
+
+ /**
+ * Returns string representation of model estimation.
+ *
+ * @param precition Precition.
+ * @return String representation of model estimation.
+ */
+ public String toString(int precition) {
+ StringBuilder sb = new StringBuilder();
+ values.forEach((k, v) -> {
+ sb.append(String.format("%s = %." + precition + "f\n", k.getPrettyName(), v));
+ });
+ return sb.toString();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override public String toString() {
+ return toString(DEFAULT_PRECISION);
+ }
+}
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/selection/scoring/evaluator/Evaluator.java b/modules/ml/src/main/java/org/apache/ignite/ml/selection/scoring/evaluator/Evaluator.java
index a8787fa..fd2a477 100644
--- a/modules/ml/src/main/java/org/apache/ignite/ml/selection/scoring/evaluator/Evaluator.java
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/selection/scoring/evaluator/Evaluator.java
@@ -17,22 +17,36 @@
package org.apache.ignite.ml.selection.scoring.evaluator;
+import java.util.Arrays;
+import java.util.HashMap;
import java.util.Map;
+import javax.cache.Cache;
import org.apache.ignite.IgniteCache;
+import org.apache.ignite.Ignition;
+import org.apache.ignite.cache.query.QueryCursor;
+import org.apache.ignite.cache.query.ScanQuery;
+import org.apache.ignite.internal.util.typedef.internal.A;
import org.apache.ignite.lang.IgniteBiPredicate;
import org.apache.ignite.ml.IgniteModel;
+import org.apache.ignite.ml.dataset.Dataset;
+import org.apache.ignite.ml.dataset.DatasetBuilder;
+import org.apache.ignite.ml.dataset.impl.cache.CacheBasedDatasetBuilder;
+import org.apache.ignite.ml.dataset.impl.local.LocalDatasetBuilder;
+import org.apache.ignite.ml.dataset.primitive.FeatureMatrixWithLabelsOnHeapData;
+import org.apache.ignite.ml.dataset.primitive.FeatureMatrixWithLabelsOnHeapDataBuilder;
+import org.apache.ignite.ml.dataset.primitive.builder.context.EmptyContextBuilder;
+import org.apache.ignite.ml.dataset.primitive.context.EmptyContext;
+import org.apache.ignite.ml.environment.LearningEnvironment;
+import org.apache.ignite.ml.environment.LearningEnvironmentBuilder;
+import org.apache.ignite.ml.knn.KNNModel;
import org.apache.ignite.ml.math.primitives.vector.Vector;
+import org.apache.ignite.ml.math.primitives.vector.VectorUtils;
import org.apache.ignite.ml.preprocessing.Preprocessor;
-import org.apache.ignite.ml.selection.scoring.cursor.CacheBasedLabelPairCursor;
-import org.apache.ignite.ml.selection.scoring.cursor.LabelPairCursor;
-import org.apache.ignite.ml.selection.scoring.cursor.LocalLabelPairCursor;
-import org.apache.ignite.ml.selection.scoring.metric.AbstractMetrics;
+import org.apache.ignite.ml.selection.scoring.evaluator.aggregator.MetricStatsAggregator;
+import org.apache.ignite.ml.selection.scoring.evaluator.context.EvaluationContext;
import org.apache.ignite.ml.selection.scoring.metric.Metric;
-import org.apache.ignite.ml.selection.scoring.metric.MetricValues;
-import org.apache.ignite.ml.selection.scoring.metric.classification.BinaryClassificationMetricValues;
-import org.apache.ignite.ml.selection.scoring.metric.classification.BinaryClassificationMetrics;
-import org.apache.ignite.ml.selection.scoring.metric.regression.RegressionMetricValues;
-import org.apache.ignite.ml.selection.scoring.metric.regression.RegressionMetrics;
+import org.apache.ignite.ml.selection.scoring.metric.MetricName;
+import org.apache.ignite.ml.structures.LabeledVector;
/**
* Evaluator that computes metrics from predictions and ground truth values.
@@ -44,42 +58,42 @@ public class Evaluator {
* @param dataCache The given cache.
* @param mdl The model.
* @param preprocessor The preprocessor.
- * @param metric The binary classification metric.
+ * @param metric The metric.
* @param <K> The type of cache entry key.
* @param <V> The type of cache entry value.
* @return Computed metric.
*/
- public static <L, K, V> double evaluate(IgniteCache<K, V> dataCache,
- IgniteModel<Vector, L> mdl,
- Preprocessor<K, V> preprocessor,
- Metric<L> metric
+ public static <K, V> double evaluate(IgniteCache<K, V> dataCache,
+ IgniteModel<Vector, Double> mdl,
+ Preprocessor<K, V> preprocessor,
+ Metric metric
) {
-
- return calculateMetric(
- dataCache,
- null,
- mdl,
- preprocessor,
- metric
- );
+ return evaluate(dataCache, (k, v) -> true, mdl, preprocessor, metric);
}
/**
* Computes the given metric on the given cache.
*
- * @param dataCache The given local data.
+ * @param dataCache The given cache.
+ * @param filter The filter.
* @param mdl The model.
* @param preprocessor The preprocessor.
- * @param metric The binary classification metric.
+ * @param metric The metric.
* @param <K> The type of cache entry key.
* @param <V> The type of cache entry value.
* @return Computed metric.
*/
- public static <L, K, V> double evaluate(Map<K, V> dataCache,
- IgniteModel<Vector, L> mdl,
- Preprocessor<K, V> preprocessor,
- Metric<L> metric) {
- return calculateMetric(dataCache, null, mdl, preprocessor, metric);
+ public static <K, V> double evaluate(IgniteCache<K, V> dataCache,
+ IgniteBiPredicate<K, V> filter,
+ IgniteModel<Vector, Double> mdl,
+ Preprocessor<K, V> preprocessor,
+ Metric metric
+ ) {
+
+ return evaluate(
+ new CacheBasedDatasetBuilder<>(Ignition.ignite(), dataCache, filter),
+ mdl, preprocessor, metric
+ ).getSignle();
}
/**
@@ -88,22 +102,18 @@ public class Evaluator {
* @param dataCache The given cache.
* @param mdl The model.
* @param preprocessor The preprocessor.
- * @param metric The binary classification metric.
+ * @param metric The metric name.
* @param <K> The type of cache entry key.
* @param <V> The type of cache entry value.
* @return Computed metric.
*/
- public static <L, K, V> double evaluate(IgniteCache<K, V> dataCache,
- IgniteBiPredicate<K, V> filter,
- IgniteModel<Vector, L> mdl,
- Preprocessor<K, V> preprocessor,
- Metric<L> metric) {
-
- return calculateMetric(
- dataCache, filter, mdl,
- preprocessor,
- metric
- );
+ public static <K, V> double evaluate(IgniteCache<K, V> dataCache,
+ IgniteModel<Vector, Double> mdl,
+ Preprocessor<K, V> preprocessor,
+ MetricName metric
+ ) {
+
+ return evaluate(dataCache, mdl, preprocessor, metric.create());
}
/**
@@ -113,133 +123,165 @@ public class Evaluator {
* @param filter The given filter.
* @param mdl The model.
* @param preprocessor The preprocessor.
+ * @param metric The metric name.
+ * @param <K> The type of cache entry key.
+ * @param <V> The type of cache entry value.
+ * @return Computed metric.
+ */
+ public static <K, V> double evaluate(IgniteCache<K, V> dataCache,
+ IgniteBiPredicate<K, V> filter,
+ IgniteModel<Vector, Double> mdl,
+ Preprocessor<K, V> preprocessor,
+ MetricName metric
+ ) {
+
+ return evaluate(
+ new CacheBasedDatasetBuilder<>(Ignition.ignite(), dataCache, filter),
+ mdl, preprocessor, metric.create()
+ ).getSignle();
+ }
+
+ /**
+ * Computes the given metric on the given cache.
+ *
+ * @param dataCache The given local data.
+ * @param mdl The model.
+ * @param preprocessor The preprocessor.
* @param metric The binary classification metric.
- * @param <L> The type of label.
* @param <K> The type of cache entry key.
* @param <V> The type of cache entry value.
* @return Computed metric.
*/
- public static <L, K, V> double evaluate(Map<K, V> dataCache, IgniteBiPredicate<K, V> filter,
- IgniteModel<Vector, L> mdl,
- Preprocessor<K, V> preprocessor,
- Metric<L> metric) {
- return calculateMetric(dataCache, filter, mdl, preprocessor, metric);
+ public static <K, V> double evaluate(Map<K, V> dataCache,
+ IgniteModel<Vector, Double> mdl,
+ Preprocessor<K, V> preprocessor,
+ Metric metric
+ ) {
+
+ return evaluate(dataCache, (k, v) -> true, mdl, preprocessor, metric);
}
/**
- * Computes the given metrics on the given cache.
+ * Computes the given metric on the given cache.
*
* @param dataCache The given cache.
+ * @param filter The given filter.
* @param mdl The model.
* @param preprocessor The preprocessor.
+ * @param metric The binary classification metric.
* @param <K> The type of cache entry key.
* @param <V> The type of cache entry value.
* @return Computed metric.
*/
- public static <K, V> BinaryClassificationMetricValues evaluate(IgniteCache<K, V> dataCache,
- IgniteModel<Vector, Double> mdl,
- Preprocessor<K, V> preprocessor) {
- return calcMetricValues(dataCache, null, mdl, preprocessor);
+ public static <K, V> double evaluate(Map<K, V> dataCache, IgniteBiPredicate<K, V> filter,
+ IgniteModel<Vector, Double> mdl,
+ Preprocessor<K, V> preprocessor,
+ Metric metric) {
+ return evaluate(new LocalDatasetBuilder<>(dataCache, filter, 1), mdl, preprocessor, metric).getSignle();
}
/**
- * Computes the given metrics on the given cache.
+ * Computes the given metric on the given cache.
*
- * @param dataCache The given cache.
+ * @param dataCache The given local data.
* @param mdl The model.
* @param preprocessor The preprocessor.
+ * @param metric The binary classification metric.
* @param <K> The type of cache entry key.
* @param <V> The type of cache entry value.
* @return Computed metric.
*/
- public static <K, V> BinaryClassificationMetricValues evaluate(Map<K, V> dataCache,
- IgniteModel<Vector, Double> mdl,
- Preprocessor<K, V> preprocessor) {
- return calcMetricValues(dataCache, null, mdl, preprocessor);
+ public static <K, V> double evaluate(Map<K, V> dataCache,
+ IgniteModel<Vector, Double> mdl,
+ Preprocessor<K, V> preprocessor,
+ MetricName metric
+ ) {
+
+ return evaluate(dataCache, (k, v) -> true, mdl, preprocessor, metric.create());
}
/**
- * Computes the given metrics on the given cache.
+ * Computes the given metric on the given cache.
*
* @param dataCache The given cache.
* @param filter The given filter.
* @param mdl The model.
* @param preprocessor The preprocessor.
+ * @param metric The binary classification metric.
* @param <K> The type of cache entry key.
* @param <V> The type of cache entry value.
* @return Computed metric.
*/
- public static <K, V> BinaryClassificationMetricValues evaluate(IgniteCache<K, V> dataCache,
- IgniteBiPredicate<K, V> filter,
- IgniteModel<Vector, Double> mdl,
- Preprocessor<K, V> preprocessor) {
- return calcMetricValues(
- dataCache, filter,
- mdl,
- preprocessor
- );
+ public static <K, V> double evaluate(Map<K, V> dataCache, IgniteBiPredicate<K, V> filter,
+ IgniteModel<Vector, Double> mdl,
+ Preprocessor<K, V> preprocessor,
+ MetricName metric) {
+ return evaluate(dataCache, filter, mdl, preprocessor, metric.create());
}
/**
- * Computes the given metrics on the given cache.
+ * Evaluate binary classifier by default metrics (see package classification). TODO: IGNITE-12156
*
* @param dataCache The given cache.
- * @param filter The given filter.
* @param mdl The model.
* @param preprocessor The preprocessor.
* @param <K> The type of cache entry key.
* @param <V> The type of cache entry value.
- * @return Computed metric.
+ * @return Computed metrics.
*/
- public static <K, V> BinaryClassificationMetricValues evaluate(Map<K, V> dataCache, IgniteBiPredicate<K, V> filter,
- IgniteModel<Vector, Double> mdl,
- Preprocessor<K, V> preprocessor) {
- return calcMetricValues(dataCache, filter, mdl, preprocessor);
+ public static <K, V> EvaluationResult evaluateBinaryClassification(IgniteCache<K, V> dataCache,
+ IgniteModel<Vector, Double> mdl,
+ Preprocessor<K, V> preprocessor) {
+
+ return evaluateBinaryClassification(dataCache, (k, v) -> true, mdl, preprocessor);
}
/**
- * Computes the regression metrics on the given cache.
+ * Evaluate binary classifier by default metrics (see package classification).
*
- * @param dataCache Data cache.
- * @param filter Filter.
- * @param mdl Model.
- * @param preprocessor Preprocessor.
- * @param <K> The type of cache entry key.
- * @param <V> The type of cache entry value.
- * @return Computed metric.
+ * @param dataCache The given cache.
+ * @param filter The filter.
+ * @param mdl The model.
+ * @param preprocessor The preprocessor.
+ * @param <K> The type of cache entry key.
+ * @param <V> The type of cache entry value.
+ * @return Computed metrics.
*/
- public static <K, V> RegressionMetricValues evaluateRegression(IgniteCache<K, V> dataCache,
+ public static <K, V> EvaluationResult evaluateBinaryClassification(IgniteCache<K, V> dataCache,
+ // TODO: IGNITE-12156
IgniteBiPredicate<K, V> filter,
IgniteModel<Vector, Double> mdl,
Preprocessor<K, V> preprocessor) {
- return calcRegressionMetricValues(
- dataCache,
- filter,
- mdl,
- preprocessor
+
+ Metric[] metrics = merge(
+ MetricName.ACCURACY, MetricName.PRECISION, MetricName.RECALL, MetricName.F_MEASURE,
+ MetricName.BALANCED_ACCURACY, MetricName.FALL_OUT, MetricName.FDR, MetricName.MISS_RATE,
+ MetricName.NPV, MetricName.SPECIFICITY, MetricName.TRUE_POSITIVE, MetricName.FALSE_POSITIVE,
+ MetricName.TRUE_NEGATIVE, MetricName.FALSE_NEGATIVE
);
+ return evaluate(new CacheBasedDatasetBuilder<>(Ignition.ignite(), dataCache, filter), mdl, preprocessor,
+ metrics);
}
/**
- * Computes the regression metrics on the given cache.
+ * Evaluate binary classifier by default metrics (see package classification).
*
- * @param dataCache Data cache.
- * @param filter Filter.
- * @param mdl Model.
- * @param preprocessor Preprocessor.
- * @param <K> The type of cache entry key.
- * @param <V> The type of cache entry value.
- * @return Computed metric.
+ * @param dataCache The given cache.
+ * @param mdl The model.
+ * @param preprocessor The preprocessor.
+ * @param <K> The type of cache entry key.
+ * @param <V> The type of cache entry value.
+ * @return Computed metrics.
*/
- private static <K, V> RegressionMetricValues calcRegressionMetricValues(IgniteCache<K, V> dataCache,
- IgniteBiPredicate<K, V> filter,
+ public static <K, V> EvaluationResult evaluateBinaryClassification(Map<K, V> dataCache, // TODO: IGNITE-12156
IgniteModel<Vector, Double> mdl,
Preprocessor<K, V> preprocessor) {
- return calcMetricValues(dataCache, filter, mdl, preprocessor, new RegressionMetrics());
+
+ return evaluateBinaryClassification(dataCache, (k, v) -> true, mdl, preprocessor);
}
/**
- * Computes the given metrics on the given cache.
+ * Evaluate binary classifier by default metrics (see package classification).
*
* @param dataCache The given cache.
* @param filter The given filter.
@@ -247,152 +289,353 @@ public class Evaluator {
* @param preprocessor The preprocessor.
* @param <K> The type of cache entry key.
* @param <V> The type of cache entry value.
- * @return Computed metric.
+ * @return Computed metrics.
*/
- private static <K, V> BinaryClassificationMetricValues calcMetricValues(IgniteCache<K, V> dataCache,
- IgniteBiPredicate<K, V> filter,
- IgniteModel<Vector, Double> mdl,
- Preprocessor<K, V> preprocessor) {
- BinaryClassificationMetricValues metricValues;
- BinaryClassificationMetrics binaryMetrics = new BinaryClassificationMetrics();
-
- try (LabelPairCursor<Double> cursor = new CacheBasedLabelPairCursor<>(
- dataCache,
- filter,
- preprocessor,
- mdl
- )) {
- metricValues = binaryMetrics.scoreAll(cursor.iterator());
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
+ public static <K, V> EvaluationResult evaluateBinaryClassification(Map<K, V> dataCache, // TODO: IGNITE-12156
+ IgniteBiPredicate<K, V> filter,
+ IgniteModel<Vector, Double> mdl,
+ Preprocessor<K, V> preprocessor) {
- return metricValues;
+ return evaluate(new LocalDatasetBuilder<>(dataCache, filter, 1), mdl, preprocessor,
+ merge(MetricName.ACCURACY, MetricName.PRECISION, MetricName.RECALL, MetricName.F_MEASURE));
}
/**
- * Computes the given metrics on the given cache.
+ * Evaluate regression by default metrics (see package regression).
*
* @param dataCache The given cache.
- * @param filter The given filter.
* @param mdl The model.
* @param preprocessor The preprocessor.
* @param <K> The type of cache entry key.
* @param <V> The type of cache entry value.
- * @return Computed metric.
+ * @return Computed metrics.
*/
- private static <K, V> BinaryClassificationMetricValues calcMetricValues(Map<K, V> dataCache,
- IgniteBiPredicate<K, V> filter,
- IgniteModel<Vector, Double> mdl,
- Preprocessor<K, V> preprocessor) {
- BinaryClassificationMetricValues metricValues;
- BinaryClassificationMetrics binaryMetrics = new BinaryClassificationMetrics();
-
- try (LabelPairCursor<Double> cursor = new LocalLabelPairCursor<>(
- dataCache,
- filter,
- preprocessor,
- mdl
- )) {
- metricValues = binaryMetrics.scoreAll(cursor.iterator());
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
+ public static <K, V> EvaluationResult evaluateRegression(IgniteCache<K, V> dataCache, // TODO: IGNITE-12156
+ IgniteModel<Vector, Double> mdl,
+ Preprocessor<K, V> preprocessor) {
- return metricValues;
+ return evaluateRegression(dataCache, (k, v) -> true, mdl, preprocessor);
}
/**
- * Computes the given metric on the given cache.
+ * Evaluate regression by default metrics (see package regression).
*
* @param dataCache The given cache.
* @param filter The given filter.
* @param mdl The model.
* @param preprocessor The preprocessor.
- * @param metric The binary classification metric.
- * @param <L> The type of label.
* @param <K> The type of cache entry key.
* @param <V> The type of cache entry value.
- * @return Computed metric.
+ * @return Computed metrics.
*/
- private static <L, K, V> double calculateMetric(IgniteCache<K, V> dataCache, IgniteBiPredicate<K, V> filter,
- IgniteModel<Vector, L> mdl, Preprocessor<K, V> preprocessor, Metric<L> metric) {
- double metricRes;
-
- try (LabelPairCursor<L> cursor = new CacheBasedLabelPairCursor<>(
- dataCache,
- filter,
- preprocessor,
- mdl
- )) {
- metricRes = metric.score(cursor.iterator());
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
+ public static <K, V> EvaluationResult evaluateRegression(IgniteCache<K, V> dataCache, // TODO: IGNITE-12156
+ IgniteBiPredicate<K, V> filter,
+ IgniteModel<Vector, Double> mdl,
+ Preprocessor<K, V> preprocessor) {
- return metricRes;
+ return evaluate(new CacheBasedDatasetBuilder<>(Ignition.ignite(), dataCache, filter), mdl, preprocessor,
+ merge(MetricName.MAE, MetricName.MSE, MetricName.R2, MetricName.RMSE, MetricName.RSS));
}
/**
- * Computes the given metric on the given cache.
+ * Evaluate regression by default metrics (see package regression).
*
* @param dataCache The given cache.
- * @param filter The given filter.
* @param mdl The model.
* @param preprocessor The preprocessor.
- * @param metric The binary classification metric.
- * @param <L> The type of label.
* @param <K> The type of cache entry key.
* @param <V> The type of cache entry value.
- * @return Computed metric.
+ * @return Computed metrics.
*/
- private static <L, K, V> double calculateMetric(Map<K, V> dataCache, IgniteBiPredicate<K, V> filter,
- IgniteModel<Vector, L> mdl, Preprocessor<K, V> preprocessor, Metric<L> metric) {
- double metricRes;
-
- try (LabelPairCursor<L> cursor = new LocalLabelPairCursor<>(
- dataCache,
- filter,
- preprocessor,
- mdl
- )) {
- metricRes = metric.score(cursor.iterator());
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
+ public static <K, V> EvaluationResult evaluateRegression(Map<K, V> dataCache, // TODO: IGNITE-12156
+ IgniteModel<Vector, Double> mdl,
+ Preprocessor<K, V> preprocessor) {
- return metricRes;
+ return evaluateRegression(dataCache, (k, v) -> true, mdl, preprocessor);
}
/**
- * Computes regression metrics on the given cache.
+ * Evaluate regression by default metrics (see package regression).
*
- * @param dataCache The given cache.
- * @param filter The given filter.
- * @param mdl The model.
+ * @param dataCache The given cache.
+ * @param filter The given filter.
+ * @param mdl The model.
* @param preprocessor The preprocessor.
- * @param <K> The type of cache entry key.
- * @param <V> The type of cache entry value.
- * @return Computed metric.
+ * @param <K> The type of cache entry key.
+ * @param <V> The type of cache entry value.
+ * @return Computed metrics.
+ */
+ public static <K, V> EvaluationResult evaluateRegression(Map<K, V> dataCache, // TODO: IGNITE-12156
+ IgniteBiPredicate<K, V> filter,
+ IgniteModel<Vector, Double> mdl,
+ Preprocessor<K, V> preprocessor) {
+
+ return evaluate(new LocalDatasetBuilder<>(dataCache, filter, 1), mdl, preprocessor,
+ merge(MetricName.MAE, MetricName.MSE, MetricName.R2, MetricName.RMSE, MetricName.RSS));
+ }
+
+ /**
+ * Pack metric names to array of metrics.
+ *
+ * @param name1 Metric 1 name.
+ * @param name2 Metric 2 name.
+ * @param metricNames Metric Names.
+ * @return Array of metrics.
+ */
+ private static Metric[] merge(MetricName name1, MetricName name2, MetricName... metricNames) {
+ Metric[] metrics = new Metric[metricNames.length + 2];
+ metrics[0] = name1.create();
+ metrics[1] = name2.create();
+ for (int i = 0; i < metricNames.length; i++)
+ metrics[i + 2] = metricNames[i].create();
+ return metrics;
+ }
+
+ /**
+ * Evaluate model.
+ *
+ * @param mdl The model.
+ * @param dataCache Dataset cache.
+ * @param filter Dataset filter.
+ * @param preprocessor Preprocessor.
+ * @param metrics Metrics to compute.
+ * @param <K> Type of key.
+ * @param <V> Type of value.
+ * @return Evaluation result.
*/
- private static <K, V, M extends MetricValues> M calcMetricValues(IgniteCache<K, V> dataCache,
+ private static <K, V> EvaluationResult evaluate(IgniteModel<Vector, Double> mdl,
+ IgniteCache<K, V> dataCache,
IgniteBiPredicate<K, V> filter,
+ Preprocessor<K, V> preprocessor,
+ Metric[] metrics) {
+ return evaluate(new CacheBasedDatasetBuilder<>(Ignition.ignite(), dataCache, filter), mdl, preprocessor, metrics);
+ }
+
+ /**
+ * Evaluate model.
+ *
+ * @param mdl The model.
+ * @param datasetBuilder Dataset builder.
+ * @param preprocessor Preprocessor.
+ * @param metrics Metrics to compute.
+ * @param <K> Type of key.
+ * @param <V> Type of value.
+ * @return Evaluation result.
+ */
+ public static <K, V> EvaluationResult evaluate(DatasetBuilder<K, V> datasetBuilder,
IgniteModel<Vector, Double> mdl,
- Preprocessor<K, V> preprocessor, AbstractMetrics<M> metrics) {
- M metricValues;
-
- try (LabelPairCursor<Double> cursor = new CacheBasedLabelPairCursor<>(
- dataCache,
- filter,
- preprocessor,
- mdl
+ Preprocessor<K, V> preprocessor,
+ Metric... metrics) {
+ try (Dataset<EmptyContext, FeatureMatrixWithLabelsOnHeapData> dataset = datasetBuilder.build(
+ LearningEnvironmentBuilder.defaultBuilder(),
+ new EmptyContextBuilder<>(),
+ new FeatureMatrixWithLabelsOnHeapDataBuilder<>(preprocessor),
+ LearningEnvironment.DEFAULT_TRAINER_ENV
)) {
- metricValues = metrics.scoreAll(cursor.iterator());
+ IgniteCache<K, V> cache = null;
+ if (datasetBuilder instanceof CacheBasedDatasetBuilder)
+ cache = ((CacheBasedDatasetBuilder<K, V>)datasetBuilder).getUpstreamCache();
+
+ return evaluate(mdl, dataset, cache, preprocessor, metrics);
}
catch (Exception e) {
throw new RuntimeException(e);
}
+ }
+
+ /**
+ * Evaluate model.
+ *
+ * @param mdl The model.
+ * @param dataset Dataset.
+ * @param cache Upstream cache.
+ * @param preprocessor Preprocessor.
+ * @param metrics Metrics to compute.
+ * @return Evaluation result.
+ */
+ @SuppressWarnings("unchecked")
+ private static <K, V> EvaluationResult evaluate(IgniteModel<Vector, Double> mdl,
+ Dataset<EmptyContext, FeatureMatrixWithLabelsOnHeapData> dataset, IgniteCache<K, V> cache,
+ Preprocessor<K, V> preprocessor, Metric[] metrics) {
+ final Map<MetricName, Metric> metricMap = new HashMap<>();
+ final Map<MetricName, Class> metricToAggrCls = new HashMap<>();
+ for (Metric metric : metrics) {
+ MetricStatsAggregator aggregator = metric.makeAggregator();
+ MetricName name = metric.name();
+
+ metricToAggrCls.put(name, aggregator.getClass());
+ metricMap.put(name, metric);
+ }
+
+ Map<MetricName, Double> res = new HashMap<>();
+
+ final Map<Class, EvaluationContext> aggrClsToCtx = initEvaluationContexts(dataset, metrics);
+ final Map<Class, MetricStatsAggregator> aggrClsToAggr = computeStats(mdl, dataset, cache, preprocessor, aggrClsToCtx, metrics);
+
+ for (Metric metric : metrics) {
+ MetricName name = metric.name();
+ Class aggrCls = metricToAggrCls.get(name);
+ MetricStatsAggregator aggr = aggrClsToAggr.get(aggrCls);
+ res.put(name, metricMap.get(name).initBy(aggr).value());
+ }
+
+ return new EvaluationResult(res);
+ }
+
+ /**
+ * Inits evaluation contexts for metrics.
+ *
+ * @param dataset Dataset.
+ * @param metrics Metrics.
+ * @return Computed contexts.
+ */
+ @SuppressWarnings("unchecked")
+ private static Map<Class, EvaluationContext> initEvaluationContexts(
+ Dataset<EmptyContext, FeatureMatrixWithLabelsOnHeapData> dataset,
+ Metric... metrics
+ ) {
+ long nonEmptyCtxsCnt = Arrays.stream(metrics)
+ .map(x -> x.makeAggregator().createUnitializedContext())
+ .filter(x -> ((EvaluationContext)x).needToCompute())
+ .count();
+
+ if (nonEmptyCtxsCnt == 0) {
+ HashMap<Class, EvaluationContext> res = new HashMap<>();
+
+ for (Metric m : metrics) {
+ MetricStatsAggregator<Double, ?, ?> aggregator = m.makeAggregator();
+ res.put(aggregator.getClass(), (EvaluationContext)m.makeAggregator().createUnitializedContext());
+ return res;
+ }
+ }
+
+ return dataset.compute(data -> {
+ Map<Class, MetricStatsAggregator> aggrs = new HashMap<>();
+ for (Metric m : metrics) {
+ MetricStatsAggregator<Double, ?, ?> aggregator = m.makeAggregator();
+ if (!aggrs.containsKey(aggregator.getClass()))
+ aggrs.put(aggregator.getClass(), aggregator);
+ }
+
+ Map<Class, EvaluationContext> aggrToEvCtx = new HashMap<>();
+ aggrs.forEach((clazz, aggr) -> aggrToEvCtx.put(clazz, (EvaluationContext)aggr.createUnitializedContext()));
+
+ for (int i = 0; i < data.getLabels().length; i++) {
+ LabeledVector<Double> vector = VectorUtils.of(data.getFeatures()[i]).labeled(data.getLabels()[i]);
+ aggrToEvCtx.values().stream().forEach(ctx -> ctx.aggregate(vector));
+ }
+ return aggrToEvCtx;
+ }, (left, right) -> {
+ if (left == null && right == null)
+ return new HashMap<>();
+
+ if (left == null)
+ return right;
+ if (right == null)
+ return left;
+
+ HashMap<Class, EvaluationContext> res = new HashMap<>();
+ for (Class key : left.keySet()) {
+ EvaluationContext ctx1 = left.get(key);
+ EvaluationContext ctx2 = right.get(key);
+ A.ensure(ctx1 != null && ctx2 != null, "ctx1 != null && ctx2 != null");
+ res.put(key, ctx1.mergeWith(ctx2));
+ }
+ return res;
+ });
+ }
+
+ /**
+ * Aggregates statistics for metrics evaluation.
+ *
+ * @param dataset Dataset.
+ * @param metrics Metrics.
+ * @return Aggregated statistics.
+ */
+ @SuppressWarnings("unchecked")
+ private static <K, V> Map<Class, MetricStatsAggregator> computeStats(IgniteModel<Vector, Double> mdl,
+ Dataset<EmptyContext, FeatureMatrixWithLabelsOnHeapData> dataset, IgniteCache<K, V> cache,
+ Preprocessor<K, V> preprocessor,
+ Map<Class, EvaluationContext> ctxs, Metric... metrics) {
+
+ if (isOnlyLocalEstimation(mdl) && cache != null) {
+ Map<Class, MetricStatsAggregator> aggrs = initAggregators(ctxs, metrics);
+
+ try (QueryCursor<Cache.Entry<K, V>> query = cache.query(new ScanQuery<>())) {
+ query.iterator().forEachRemaining(kv -> {
+ LabeledVector vector = preprocessor.apply(kv.getKey(), kv.getValue());
+
+ for (Class key : aggrs.keySet()) {
+ MetricStatsAggregator aggr = aggrs.get(key);
+ aggr.aggregate(mdl, vector);
+ }
+ });
+ }
+
+ return aggrs;
+ }
+ else {
+ return dataset.compute(data -> {
+ Map<Class, MetricStatsAggregator> aggrs = initAggregators(ctxs, metrics);
+
+ for (int i = 0; i < data.getLabels().length; i++) {
+ LabeledVector<Double> vector = VectorUtils.of(data.getFeatures()[i]).labeled(data.getLabels()[i]);
+ for (Class key : aggrs.keySet()) {
+ MetricStatsAggregator aggr = aggrs.get(key);
+ aggr.aggregate(mdl, vector);
+ }
+ }
- return metricValues;
+ return aggrs;
+ }, (left, right) -> {
+ if (left == null && right == null)
+ return new HashMap<>();
+ if (left == null)
+ return right;
+ if (right == null)
+ return left;
+
+ HashMap<Class, MetricStatsAggregator> res = new HashMap<>();
+ for (Class key : left.keySet()) {
+ MetricStatsAggregator agg1 = left.get(key);
+ MetricStatsAggregator agg2 = right.get(key);
+ A.ensure(agg1 != null && agg2 != null, "agg1 != null && agg2 != null");
+ res.put(key, agg1.mergeWith(agg2));
+ }
+ return res;
+ });
+ }
+ }
+
+ /**
+ * Inits aggregators.
+ *
+ * @param ctxs Evaluation contexts.
+ * @param metrics Metrics.
+ * @return Aggregators map.
+ */
+ private static Map<Class, MetricStatsAggregator> initAggregators(Map<Class, EvaluationContext> ctxs,
+ Metric[] metrics) {
+ Map<Class, MetricStatsAggregator> aggrs = new HashMap<>();
+ for (Metric m : metrics) {
+ MetricStatsAggregator aggregator = m.makeAggregator();
+ EvaluationContext ctx = ctxs.get(aggregator.getClass());
+ A.ensure(ctx != null, "ctx != null");
+ aggregator.initByContext(ctx);
+
+ if (!aggrs.containsKey(aggregator.getClass()))
+ aggrs.put(aggregator.getClass(), aggregator);
+ }
+ return aggrs;
+ }
+
+ /**
+ * Returns true if model should be evaluated only through scan query.
+ *
+ * @param mdl Model to estimation.
+ * @return true if model should be evaluated only through scan query.
+ */
+ private static boolean isOnlyLocalEstimation(IgniteModel<Vector, Double> mdl) {
+ return mdl instanceof KNNModel; // TODO:IGNITE-12156, mode this logic into model meta
}
}
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/selection/scoring/evaluator/aggregator/BinaryClassificationPointwiseMetricStatsAggregator.java b/modules/ml/src/main/java/org/apache/ignite/ml/selection/scoring/evaluator/aggregator/BinaryClassificationPointwiseMetricStatsAggregator.java
new file mode 100644
index 0000000..ca99c57
--- /dev/null
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/selection/scoring/evaluator/aggregator/BinaryClassificationPointwiseMetricStatsAggregator.java
@@ -0,0 +1,249 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.selection.scoring.evaluator.aggregator;
+
+import java.io.Serializable;
+import org.apache.ignite.internal.util.typedef.internal.A;
+import org.apache.ignite.ml.IgniteModel;
+import org.apache.ignite.ml.math.primitives.vector.Vector;
+import org.apache.ignite.ml.selection.scoring.evaluator.context.BinaryClassificationEvaluationContext;
+import org.apache.ignite.ml.structures.LabeledVector;
+
+/**
+ * This class represents statistics for pointwise metrics evaluation for binary classification like TruePositive,
+ * FalsePositive, TrueNegative and FalseNegative.
+ */
+public class BinaryClassificationPointwiseMetricStatsAggregator<L extends Serializable> implements MetricStatsAggregator<L, BinaryClassificationEvaluationContext<L>, BinaryClassificationPointwiseMetricStatsAggregator<L>> {
+ /**
+ * Serial version uid.
+ */
+ private static final long serialVersionUID = -7677193556950322385L;
+
+ /**
+ * False label.
+ */
+ private L falseLabel;
+
+ /**
+ * Truth label.
+ */
+ private L truthLabel;
+
+ /**
+ * Count of true positives.
+ */
+ private int truePositive;
+
+ /**
+ * Count of false positives.
+ */
+ int falsePositive;
+
+ /**
+ * Count of true negatives.
+ */
+ int trueNegative;
+
+ /**
+ * Count of false negatives.
+ */
+ int falseNegative;
+
+ /**
+ * Creates an instance of BinaryClassificationPointwiseMetricStatsAggregator.
+ */
+ public BinaryClassificationPointwiseMetricStatsAggregator() {
+ }
+
+ /**
+ * Creates an instance of BinaryClassificationPointwiseMetricStatsAggregator.
+ *
+ * @param falseLabel False label.
+ * @param truthLabel Truth label.
+ * @param truePositive True positives count.
+ * @param falsePositive False positives count.
+ * @param trueNegative True negatives count.
+ * @param falseNegative False negatives count.
+ */
+ public BinaryClassificationPointwiseMetricStatsAggregator(L falseLabel, L truthLabel,
+ int truePositive, int falsePositive, int trueNegative, int falseNegative) {
+
+ this.falseLabel = falseLabel;
+ this.truthLabel = truthLabel;
+ this.truePositive = truePositive;
+ this.falsePositive = falsePositive;
+ this.trueNegative = trueNegative;
+ this.falseNegative = falseNegative;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override public void aggregate(IgniteModel<Vector, L> model, LabeledVector<L> vector) {
+ L modelAns = model.predict(vector.features());
+ L realAns = vector.label();
+
+ if (modelAns.equals(falseLabel) && realAns.equals(falseLabel))
+ trueNegative += 1;
+ else if (modelAns.equals(falseLabel) && realAns.equals(truthLabel))
+ falseNegative += 1;
+ else if (modelAns.equals(truthLabel) && realAns.equals(truthLabel))
+ truePositive += 1;
+ else if (modelAns.equals(truthLabel) && realAns.equals(falseLabel))
+ falsePositive += 1;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override public BinaryClassificationPointwiseMetricStatsAggregator<L> mergeWith(
+ BinaryClassificationPointwiseMetricStatsAggregator other) {
+ A.ensure(this.falseLabel.equals(other.falseLabel), "this.falseLabel == other.falseLabel");
+ A.ensure(this.truthLabel.equals(other.truthLabel), "this.truthLabel == other.truthLabel");
+
+ return new BinaryClassificationPointwiseMetricStatsAggregator<>(
+ this.falseLabel,
+ this.truthLabel,
+ this.truePositive + other.truePositive,
+ this.falsePositive + other.falsePositive,
+ this.trueNegative + other.trueNegative,
+ this.falseNegative + other.falseNegative
+ );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override public BinaryClassificationEvaluationContext<L> createUnitializedContext() {
+ return new BinaryClassificationEvaluationContext<>();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override public void initByContext(BinaryClassificationEvaluationContext<L> context) {
+ this.falseLabel = context.getFirstClassLbl();
+ this.truthLabel = context.getSecondClassLbl();
+ }
+
+ /**
+ * Returns false label.
+ *
+ * @return False label.
+ */
+ public L getFalseLabel() {
+ return falseLabel;
+ }
+
+ /**
+ * Returns truth label.
+ *
+ * @return Truth label.
+ */
+ public L getTruthLabel() {
+ return truthLabel;
+ }
+
+ /**
+ * Returns true positives count.
+ *
+ * @return True positives count.
+ */
+ public int getTruePositive() {
+ return truePositive;
+ }
+
+ /**
+ * Returns false positives count.
+ *
+ * @return False positives count.
+ */
+ public int getFalsePositive() {
+ return falsePositive;
+ }
+
+ /**
+ * Returns true negatives count.
+ *
+ * @return True negatives count.
+ */
+ public int getTrueNegative() {
+ return trueNegative;
+ }
+
+ /**
+ * Returns false negatives count.
+ *
+ * @return False negatives count.
+ */
+ public int getFalseNegative() {
+ return falseNegative;
+ }
+
+ /**
+ * Returns number of elements in dataset.
+ *
+ * @return Number of elements in dataset.
+ */
+ public int getN() {
+ return truePositive + falsePositive + trueNegative + falseNegative;
+ }
+
+ /**
+ * Class represents already initialized aggregator.
+ */
+ public static class WithCustomLabelsAggregator<L extends Serializable> extends BinaryClassificationPointwiseMetricStatsAggregator<L> {
+ /**
+ * Truth label.
+ */
+ private final L truthLabel;
+
+ /**
+ * False label.
+ */
+ private final L falseLabel;
+
+ /**
+ * Create an instance of WithCustomLabels.
+ *
+ * @param truthLabel Truth label.
+ * @param falseLabel False label.
+ */
+ public WithCustomLabelsAggregator(L truthLabel, L falseLabel) {
+ this.truthLabel = truthLabel;
+ this.falseLabel = falseLabel;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override public BinaryClassificationEvaluationContext<L> createUnitializedContext() {
+ return new BinaryClassificationEvaluationContext<L>(falseLabel, truthLabel) {
+ /**
+ * Serial version ID.
+ */
+ private static final long serialVersionUID = 4739649114414953828L;
+
+ /** {@inheritDoc} */
+ @Override public boolean needToCompute() {
+ return false;
+ }
+ };
+ }
+ }
+}
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/selection/scoring/evaluator/aggregator/ClassificationMetricsAggregator.java b/modules/ml/src/main/java/org/apache/ignite/ml/selection/scoring/evaluator/aggregator/ClassificationMetricsAggregator.java
new file mode 100644
index 0000000..f47b357
--- /dev/null
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/selection/scoring/evaluator/aggregator/ClassificationMetricsAggregator.java
@@ -0,0 +1,117 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.selection.scoring.evaluator.aggregator;
+
+import java.io.Serializable;
+import org.apache.ignite.ml.IgniteModel;
+import org.apache.ignite.ml.math.primitives.vector.Vector;
+import org.apache.ignite.ml.selection.scoring.evaluator.context.EmptyContext;
+import org.apache.ignite.ml.selection.scoring.evaluator.context.EvaluationContext;
+import org.apache.ignite.ml.structures.LabeledVector;
+
+/**
+ * Class represents aggregations for classification metric (including multiclassification case).
+ *
+ * @param <L> Type of label.
+ */
+public class ClassificationMetricsAggregator<L extends Serializable> implements MetricStatsAggregator<L, EmptyContext<L>, ClassificationMetricsAggregator<L>> {
+ /**
+ * Serial version uid.
+ */
+ private static final long serialVersionUID = 6508258921730584458L;
+
+ /**
+ * Valid answers count.
+ */
+ private long validAnswersCount = 0;
+
+ /**
+ * Total number of examples.
+ */
+ private long totalNumberOfExamples = 0;
+
+ /**
+ * Creates an instance of ClassificationMetricsAggregator.
+ */
+ public ClassificationMetricsAggregator() {
+ }
+
+ /**
+ * Creates an instance of ClassificationMetricsAggregator.
+ *
+ * @param validAnswersCount Valid answers count.
+ * @param totalNumberOfExamples Total number of examples.
+ */
+ public ClassificationMetricsAggregator(long validAnswersCount, long totalNumberOfExamples) {
+ this.validAnswersCount = validAnswersCount;
+ this.totalNumberOfExamples = totalNumberOfExamples;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override public void aggregate(IgniteModel<Vector, L> model, LabeledVector<L> vector) {
+ L modelAns = model.predict(vector.features());
+ L truth = vector.label();
+ if (modelAns.equals(truth))
+ validAnswersCount++;
+ totalNumberOfExamples++;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override public ClassificationMetricsAggregator<L> mergeWith(ClassificationMetricsAggregator<L> other) {
+ return new ClassificationMetricsAggregator<>(
+ this.validAnswersCount + other.validAnswersCount,
+ this.totalNumberOfExamples + other.totalNumberOfExamples
+ );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override public EmptyContext<L> createUnitializedContext() {
+ return EvaluationContext.empty();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override public void initByContext(EmptyContext<L> context) {
+
+ }
+
+ /**
+ * Returns validAnswersCount.
+ *
+ * @return validAnswersCount.
+ */
+ public long getValidAnswersCount() {
+ return validAnswersCount;
+ }
+
+ /**
+ * Returns totalNumberOfExamples.
+ *
+ * @return totalNumberOfExamples.
+ */
+ public long getTotalNumberOfExamples() {
+ return totalNumberOfExamples;
+ }
+}
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/selection/scoring/evaluator/aggregator/MetricStatsAggregator.java b/modules/ml/src/main/java/org/apache/ignite/ml/selection/scoring/evaluator/aggregator/MetricStatsAggregator.java
new file mode 100644
index 0000000..c981289
--- /dev/null
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/selection/scoring/evaluator/aggregator/MetricStatsAggregator.java
@@ -0,0 +1,63 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.selection.scoring.evaluator.aggregator;
+
+import java.io.Serializable;
+import org.apache.ignite.ml.IgniteModel;
+import org.apache.ignite.ml.math.primitives.vector.Vector;
+import org.apache.ignite.ml.structures.LabeledVector;
+
+/**
+ * Classes with such interface are responsible for metric statistics aggregations used for metric computations over
+ * given dataset.
+ *
+ * @param <L> Label class.
+ * @param <Ctx> Context class.
+ * @param <Self> Aggregator class.
+ */
+public interface MetricStatsAggregator<L, Ctx, Self extends MetricStatsAggregator<L, Ctx, ? super Self>> extends Serializable {
+ /**
+ * Aggregates statistics for metric computation given model and vector with answer.
+ *
+ * @param model Model.
+ * @param vector Vector.
+ */
+ public void aggregate(IgniteModel<Vector, L> model, LabeledVector<L> vector);
+
+ /**
+ * Merges statistics of two aggregators to new aggreagator.
+ *
+ * @param other Other aggregator.
+ * @return New aggregator.
+ */
+ public Self mergeWith(Self other);
+
+ /**
+ * Returns unitialized context.
+ *
+ * @return Unitialized evaluation context.
+ */
+ public Ctx createUnitializedContext();
+
+ /**
+ * Inits this aggtegator by evaluation context.
+ *
+ * @param ctx Evaluation context.
+ */
+ public void initByContext(Ctx ctx);
+}
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/selection/scoring/evaluator/aggregator/RegressionMetricStatsAggregator.java b/modules/ml/src/main/java/org/apache/ignite/ml/selection/scoring/evaluator/aggregator/RegressionMetricStatsAggregator.java
new file mode 100644
index 0000000..2d6a69f
--- /dev/null
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/selection/scoring/evaluator/aggregator/RegressionMetricStatsAggregator.java
@@ -0,0 +1,194 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.selection.scoring.evaluator.aggregator;
+
+import org.apache.ignite.internal.util.typedef.internal.A;
+import org.apache.ignite.ml.IgniteModel;
+import org.apache.ignite.ml.math.primitives.vector.Vector;
+import org.apache.ignite.ml.selection.scoring.evaluator.context.EmptyContext;
+import org.apache.ignite.ml.structures.LabeledVector;
+
+/**
+ * Class represents statistics aggregator for regression estimation.
+ */
+public class RegressionMetricStatsAggregator implements MetricStatsAggregator<Double, EmptyContext<Double>, RegressionMetricStatsAggregator> {
+ /**
+ * Serial version uid.
+ */
+ private static final long serialVersionUID = -2459352313996869235L;
+
+ /**
+ * Number of examples in dataset.
+ */
+ private long n = 0;
+
+ /**
+ * Absolute error.
+ */
+ private double absoluteError = Double.NaN;
+
+ /**
+ * Resudual sum of squares.
+ */
+ private double rss = Double.NaN;
+
+ /**
+ * Sum of labels.
+ */
+ private double sumOfYs = Double.NaN;
+
+ /**
+ * Sum of squared labels.
+ */
+ private double sumOfSquaredYs = Double.NaN;
+
+ /**
+ * Creates an instance of RegressionMetricStatsAggregator.
+ */
+ public RegressionMetricStatsAggregator() {
+ }
+
+ /**
+ * Creates an instance of RegressionMetricStatsAggregator.
+ *
+ * @param n Number of examples in dataset.
+ * @param absoluteError Absolute error.
+ * @param rss Rss.
+ * @param sumOfYs Sum of labels.
+ * @param sumOfSquaredYs Sum of squared labels.
+ */
+ public RegressionMetricStatsAggregator(long n, double absoluteError, double rss, double sumOfYs,
+ double sumOfSquaredYs) {
+ this.n = n;
+ this.absoluteError = absoluteError;
+ this.rss = rss;
+ this.sumOfYs = sumOfYs;
+ this.sumOfSquaredYs = sumOfSquaredYs;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override public void aggregate(IgniteModel<Vector, Double> model, LabeledVector<Double> vector) {
+ n += 1;
+ Double prediction = model.predict(vector.features());
+ Double truth = vector.label();
+ A.notNull(truth != null, "Test set mustn't contain null labels");
+ A.notNull(prediction != null, "Model mustn't return null answers");
+ double error = truth - prediction;
+
+ absoluteError = sum(Math.abs(error), absoluteError);
+ rss = sum(Math.pow(error, 2), rss);
+ sumOfYs = sum(truth, sumOfYs);
+ sumOfSquaredYs = sum(Math.pow(truth, 2), sumOfSquaredYs);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override public RegressionMetricStatsAggregator mergeWith(RegressionMetricStatsAggregator other) {
+ long n = this.n + other.n;
+ double absoluteError = sum(this.absoluteError, other.absoluteError);
+ double squaredError = sum(this.rss, other.rss);
+ double sumOfYs = sum(this.sumOfYs, other.sumOfYs);
+ double sumOfSquaredYs = sum(this.sumOfSquaredYs, other.sumOfSquaredYs);
+
+ return new RegressionMetricStatsAggregator(n, absoluteError, squaredError, sumOfYs, sumOfSquaredYs);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override public EmptyContext createUnitializedContext() {
+ return new EmptyContext();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override public void initByContext(EmptyContext context) {
+
+ }
+
+ /**
+ * Returns mean absolute error.
+ *
+ * @return Mean absolute error.
+ */
+ public double getMAE() {
+ if (Double.isNaN(absoluteError))
+ return Double.NaN;
+
+ return absoluteError / Math.max(n, 1);
+ }
+
+ /**
+ * Returns mean squared error.
+ *
+ * @return Mean squared error.
+ */
+ public double getMSE() {
+ return rss / Math.max(n, 1);
+ }
+
+ /**
+ * Returns sum of squared errors.
+ *
+ * @return Sum of squared errors
+ */
+ public double ysRss() {
+ return ysVariance() * Math.max(n, 1);
+ }
+
+ /**
+ * Returns label variance.
+ *
+ * @return Label variance.
+ */
+ public double ysVariance() {
+ if (Double.isNaN(sumOfSquaredYs))
+ return Double.NaN;
+
+ return (sumOfSquaredYs / Math.max(n, 1) - Math.pow(sumOfYs / Math.max(n, 1), 2));
+ }
+
+ /**
+ * Returns RSS.
+ *
+ * @return RSS.
+ */
+ public double getRss() {
+ return rss;
+ }
+
+ /**
+ * Returns sum of given values considering NaNs.
+ *
+ * @param v1 First value.
+ * @param v2 Second value.
+ * @return v1 + v2.
+ */
+ private double sum(double v1, double v2) {
+ if (Double.isNaN(v1))
+ return v2;
+ else if (Double.isNaN(v2))
+ return v1;
+ else
+ return v1 + v2;
+ }
+}
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/clustering/package-info.java b/modules/ml/src/main/java/org/apache/ignite/ml/selection/scoring/evaluator/aggregator/package-info.java
similarity index 83%
copy from examples/src/main/java/org/apache/ignite/examples/ml/clustering/package-info.java
copy to modules/ml/src/main/java/org/apache/ignite/ml/selection/scoring/evaluator/aggregator/package-info.java
index 872aa16..2c06f83 100644
--- a/examples/src/main/java/org/apache/ignite/examples/ml/clustering/package-info.java
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/selection/scoring/evaluator/aggregator/package-info.java
@@ -16,7 +16,6 @@
*/
/**
- * <!-- Package description. -->
- * ML clustering examples.
+ * <!-- Package description. --> Package contains aggregators for metrics computation.
*/
-package org.apache.ignite.examples.ml.clustering;
+package org.apache.ignite.ml.selection.scoring.evaluator.aggregator;
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/selection/scoring/evaluator/context/BinaryClassificationEvaluationContext.java b/modules/ml/src/main/java/org/apache/ignite/ml/selection/scoring/evaluator/context/BinaryClassificationEvaluationContext.java
new file mode 100644
index 0000000..2c13308
--- /dev/null
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/selection/scoring/evaluator/context/BinaryClassificationEvaluationContext.java
@@ -0,0 +1,156 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.selection.scoring.evaluator.context;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Objects;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+import org.apache.ignite.internal.util.typedef.internal.A;
+import org.apache.ignite.ml.structures.LabeledVector;
+
+/**
+ * This context tries to define positive and negative labels for estimation of binary classifier.
+ */
+public class BinaryClassificationEvaluationContext<L extends Serializable> implements EvaluationContext<L, BinaryClassificationEvaluationContext<L>> {
+ /**
+ * Serial version uid.
+ */
+ private static final long serialVersionUID = 658785331349096576L;
+
+ /**
+ * First class lbl.
+ */
+ private L firstClassLbl;
+
+ /**
+ * Second class lbl.
+ */
+ private L secondClassLbl;
+
+ /**
+ * Creates an instance of BinaryClassificationEvaluationContext.
+ */
+ public BinaryClassificationEvaluationContext() {
+ this.firstClassLbl = null;
+ this.secondClassLbl = null;
+ }
+
+ /**
+ * Creates an instance of BinaryClassificationEvaluationContext.
+ *
+ * @param firstClassLbl First class lbl.
+ * @param secondClassLbl Second class lbl.
+ */
+ public BinaryClassificationEvaluationContext(L firstClassLbl, L secondClassLbl) {
+ this.firstClassLbl = firstClassLbl;
+ this.secondClassLbl = secondClassLbl;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override public void aggregate(LabeledVector<L> vector) {
+ L label = vector.label();
+ if (firstClassLbl == null)
+ this.firstClassLbl = label;
+ else if (secondClassLbl == null && !label.equals(firstClassLbl)) {
+ secondClassLbl = label;
+ swapLabelsIfNeed();
+ }
+ else
+ checkNewLabel(label);
+ }
+
+ /**
+ * Swaps labels in sorting order if it's possible.
+ */
+ private void swapLabelsIfNeed() {
+ if (firstClassLbl instanceof Comparable) {
+ Comparable cmp1 = (Comparable)firstClassLbl;
+ int res = cmp1.compareTo(secondClassLbl);
+ if (res > 0) {
+ L tmp = secondClassLbl;
+ secondClassLbl = firstClassLbl;
+ firstClassLbl = tmp;
+ }
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override public BinaryClassificationEvaluationContext<L> mergeWith(
+ BinaryClassificationEvaluationContext<L> other) {
+ checkNewLabel(other.firstClassLbl);
+ checkNewLabel(other.secondClassLbl);
+
+ List<L> uniqLabels = new ArrayList<>(4);
+ uniqLabels.add(this.firstClassLbl);
+ uniqLabels.add(this.secondClassLbl);
+ uniqLabels.add(other.firstClassLbl);
+ uniqLabels.add(other.secondClassLbl);
+ Stream<L> s = uniqLabels.stream().filter(Objects::nonNull).distinct();
+ if (firstClassLbl instanceof Comparable || secondClassLbl instanceof Comparable ||
+ other.firstClassLbl instanceof Comparable || other.secondClassLbl instanceof Comparable)
+ s = s.sorted();
+ uniqLabels = s.collect(Collectors.toList());
+
+ A.ensure(uniqLabels.size() < 3, "labels.length < 3");
+ return new BinaryClassificationEvaluationContext<>(
+ uniqLabels.isEmpty() ? null : uniqLabels.get(0),
+ uniqLabels.size() < 2 ? null : uniqLabels.get(1)
+ );
+ }
+
+ /**
+ * Returns first class label.
+ *
+ * @return First class label.
+ */
+ public L getFirstClassLbl() {
+ return firstClassLbl;
+ }
+
+ /**
+ * Returns second class label.
+ *
+ * @return Second class label.
+ */
+ public L getSecondClassLbl() {
+ return secondClassLbl;
+ }
+
+ /**
+ * Checks new label to mergeability with this context.
+ *
+ * @param label Label.
+ */
+ private void checkNewLabel(L label) {
+ A.ensure(
+ firstClassLbl == null || secondClassLbl == null || label == null ||
+ label.equals(firstClassLbl) || label.equals(secondClassLbl),
+ "Unable to collect binary classification ctx stat. There are more than two labels. " +
+ "First label = " + firstClassLbl +
+ ", second label = " + secondClassLbl +
+ ", another label = " + label
+ );
+ }
+}
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/selection/scoring/metric/exceptions/UnknownClassLabelException.java b/modules/ml/src/main/java/org/apache/ignite/ml/selection/scoring/evaluator/context/EmptyContext.java
similarity index 51%
rename from modules/ml/src/main/java/org/apache/ignite/ml/selection/scoring/metric/exceptions/UnknownClassLabelException.java
rename to modules/ml/src/main/java/org/apache/ignite/ml/selection/scoring/evaluator/context/EmptyContext.java
index 050a8de..09a176c 100644
--- a/modules/ml/src/main/java/org/apache/ignite/ml/selection/scoring/metric/exceptions/UnknownClassLabelException.java
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/selection/scoring/evaluator/context/EmptyContext.java
@@ -15,23 +15,38 @@
* limitations under the License.
*/
-package org.apache.ignite.ml.selection.scoring.metric.exceptions;
+package org.apache.ignite.ml.selection.scoring.evaluator.context;
-import org.apache.ignite.IgniteException;
+import java.io.Serializable;
+import org.apache.ignite.ml.structures.LabeledVector;
/**
- * Indicates an unknown class label for metric calculator.
+ * Class represents context stub for metrics that don't require such context preparations.
*/
-public class UnknownClassLabelException extends IgniteException {
- /** */
- private static final long serialVersionUID = 0L;
+public class EmptyContext<L extends Serializable> implements EvaluationContext<L, EmptyContext<L>> {
+ /**
+ * Serial version uid.
+ */
+ private static final long serialVersionUID = 1439494372470803212L;
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override public void aggregate(LabeledVector<L> vector) {
+
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override public EmptyContext<L> mergeWith(EmptyContext<L> other) {
+ return this;
+ }
/**
- * @param incorrectVal Incorrect value.
- * @param positiveClsLb Positive class label.
- * @param negativeClsLb Negative class label.
+ * {@inheritDoc}
*/
- public UnknownClassLabelException(double incorrectVal, double positiveClsLb, double negativeClsLb) {
- super("The next class label: " + incorrectVal + " is not positive class label: " + positiveClsLb + " or negative class label: " + negativeClsLb);
+ @Override public boolean needToCompute() {
+ return false;
}
}
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/selection/scoring/evaluator/context/EvaluationContext.java b/modules/ml/src/main/java/org/apache/ignite/ml/selection/scoring/evaluator/context/EvaluationContext.java
new file mode 100644
index 0000000..a5758ff
--- /dev/null
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/selection/scoring/evaluator/context/EvaluationContext.java
@@ -0,0 +1,63 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.selection.scoring.evaluator.context;
+
+import java.io.Serializable;
+import org.apache.ignite.ml.structures.LabeledVector;
+
+/**
+ * Classes with this interface are responsible for preparatory computations before model evaluation. For example if we
+ * don't know what is positive and negative label we can define it in autimatically way using such evaluation context.
+ *
+ * @param <L> Type of label.
+ * @param <Self> Type of evaluation context.
+ */
+public interface EvaluationContext<L, Self extends EvaluationContext<L, ? super Self>> extends Serializable {
+ /**
+ * Aggregates statistic from vector of sample.
+ *
+ * @param vector Vector.
+ */
+ public void aggregate(LabeledVector<L> vector);
+
+ /**
+ * Merges statistics of this and other context.
+ *
+ * @param other Other context.
+ * @return New merged context.
+ */
+ public Self mergeWith(Self other);
+
+ /**
+ * Returns true if this contexts should be evaluated through map-reduce.
+ *
+ * @return True if this contexts should be evaluated through map-reduce.
+ */
+ public default boolean needToCompute() {
+ return true;
+ }
+
+ /**
+ * Returns default empty context.
+ *
+ * @return Empty context.
+ */
+ public static <L extends Serializable> EmptyContext<L> empty() {
+ return new EmptyContext<L>();
+ }
+}
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/selection/scoring/metric/exceptions/package-info.java b/modules/ml/src/main/java/org/apache/ignite/ml/selection/scoring/evaluator/context/package-info.java
similarity index 85%
rename from modules/ml/src/main/java/org/apache/ignite/ml/selection/scoring/metric/exceptions/package-info.java
rename to modules/ml/src/main/java/org/apache/ignite/ml/selection/scoring/evaluator/context/package-info.java
index c3e515f..8353738 100644
--- a/modules/ml/src/main/java/org/apache/ignite/ml/selection/scoring/metric/exceptions/package-info.java
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/selection/scoring/evaluator/context/package-info.java
@@ -16,7 +16,6 @@
*/
/**
- * <!-- Package description. -->
- * Root package for exceptions.
+ * <!-- Package description. --> Package for metric evaluation contexts.
*/
-package org.apache.ignite.ml.selection.scoring.metric.exceptions;
+package org.apache.ignite.ml.selection.scoring.evaluator.context;
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/selection/scoring/evaluator/package-info.java b/modules/ml/src/main/java/org/apache/ignite/ml/selection/scoring/evaluator/package-info.java
index a93dd66..c5cdf08 100644
--- a/modules/ml/src/main/java/org/apache/ignite/ml/selection/scoring/evaluator/package-info.java
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/selection/scoring/evaluator/package-info.java
@@ -16,8 +16,7 @@
*/
/**
- * <!-- Package description. -->
- * Package for model evaluator classes.
+ * <!-- Package description. --> Package for model evaluator classes.
*/
package org.apache.ignite.ml.selection.scoring.evaluator;
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/selection/scoring/metric/AbstractMetrics.java b/modules/ml/src/main/java/org/apache/ignite/ml/selection/scoring/metric/AbstractMetrics.java
deleted file mode 100644
index 0adc406..0000000
--- a/modules/ml/src/main/java/org/apache/ignite/ml/selection/scoring/metric/AbstractMetrics.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.ml.selection.scoring.metric;
-
-import org.apache.ignite.ml.selection.scoring.LabelPair;
-
-import java.util.Iterator;
-import java.util.function.Function;
-
-/**
- * Abstract metrics calculator.
- * It could be used in two ways: to caculate all regression metrics or custom regression metric.
- */
-public abstract class AbstractMetrics<M extends MetricValues> implements Metric<Double> {
- /** The main metric to get individual score. */
- protected Function<M, Double> metric;
-
- /**
- * Calculates metrics values.
- *
- * @param iter Iterator that supplies pairs of truth values and predicated.
- * @return Scores for all regression metrics.
- */
- public abstract M scoreAll(Iterator<LabelPair<Double>> iter);
-
- /**
- *
- */
- public AbstractMetrics withMetric(Function<M, Double> metric) {
- if (metric != null)
- this.metric = metric;
- return this;
- }
-
- /** {@inheritDoc} */
- @Override public double score(Iterator<LabelPair<Double>> iter) {
- return metric.apply(scoreAll(iter));
- }
-}
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/selection/scoring/metric/Metric.java b/modules/ml/src/main/java/org/apache/ignite/ml/selection/scoring/metric/Metric.java
index 783d7fc..a362906 100644
--- a/modules/ml/src/main/java/org/apache/ignite/ml/selection/scoring/metric/Metric.java
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/selection/scoring/metric/Metric.java
@@ -17,29 +17,44 @@
package org.apache.ignite.ml.selection.scoring.metric;
-import java.util.Iterator;
-import org.apache.ignite.ml.selection.scoring.LabelPair;
+import java.io.Serializable;
+import org.apache.ignite.ml.selection.scoring.evaluator.aggregator.MetricStatsAggregator;
+import org.apache.ignite.ml.selection.scoring.evaluator.context.EvaluationContext;
/**
- * Base interface for score calculators.
+ * This class represents a container with computed value of metric and it provides a factory for metric statistics
+ * aggregation class.
*
- * @param <L> Type of a label (truth or prediction).
+ * @param <L> Type of label.
+ * @param <C> Type of evaluation context.
+ * @param <A> Type of statistics aggregator.
*/
-public interface Metric<L> {
+public interface Metric<L, C extends EvaluationContext<L, C>, A extends MetricStatsAggregator<L, C, A>> extends Serializable {
/**
- * Calculates score.
+ * Creates statistics aggregator.
*
- * @param iter Iterator that supplies pairs of truth values and predicated.
- * @return Score.
+ * @return Statistics aggregator
*/
- public double score(Iterator<LabelPair<L>> iter);
+ public A makeAggregator();
/**
- * Returns the metric's name.
+ * Initializes metric value by statistics aggregator.
*
- * NOTE: Should be unique to calculate multiple metrics correctly.
+ * @param aggr Aggregator.
+ */
+ public Metric<L, C, A> initBy(A aggr);
+
+ /**
+ * Returns metric value.
+ *
+ * @return Metric value.
+ */
+ public double value();
+
+ /**
+ * Returns metric name.
*
- * @return String name representation.
+ * @return Metric name.
*/
- public String name();
+ public MetricName name();
}
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/selection/scoring/metric/MetricName.java b/modules/ml/src/main/java/org/apache/ignite/ml/selection/scoring/metric/MetricName.java
new file mode 100644
index 0000000..7a720de
--- /dev/null
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/selection/scoring/metric/MetricName.java
@@ -0,0 +1,213 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.selection.scoring.metric;
+
+import org.apache.ignite.ml.selection.scoring.metric.classification.Accuracy;
+import org.apache.ignite.ml.selection.scoring.metric.classification.BalancedAccuracy;
+import org.apache.ignite.ml.selection.scoring.metric.classification.FMeasure;
+import org.apache.ignite.ml.selection.scoring.metric.classification.FallOut;
+import org.apache.ignite.ml.selection.scoring.metric.classification.FalseNegativeAbsoluteValue;
+import org.apache.ignite.ml.selection.scoring.metric.classification.FalsePositiveAbsoluteValue;
+import org.apache.ignite.ml.selection.scoring.metric.classification.Fdr;
+import org.apache.ignite.ml.selection.scoring.metric.classification.MissRate;
+import org.apache.ignite.ml.selection.scoring.metric.classification.Npv;
+import org.apache.ignite.ml.selection.scoring.metric.classification.Precision;
+import org.apache.ignite.ml.selection.scoring.metric.classification.Recall;
+import org.apache.ignite.ml.selection.scoring.metric.classification.Specificity;
+import org.apache.ignite.ml.selection.scoring.metric.classification.TrueNegativeAbsoluteValue;
+import org.apache.ignite.ml.selection.scoring.metric.classification.TruePositiveAbsoluteValue;
+import org.apache.ignite.ml.selection.scoring.metric.regression.Mae;
+import org.apache.ignite.ml.selection.scoring.metric.regression.Mse;
+import org.apache.ignite.ml.selection.scoring.metric.regression.R2;
+import org.apache.ignite.ml.selection.scoring.metric.regression.Rmse;
+import org.apache.ignite.ml.selection.scoring.metric.regression.Rss;
+
+/**
+ * Enum for all metrics aggregation.
+ */
+public enum MetricName {
+ // binary classification metrics
+ /**
+ * Accuracy.
+ */
+ ACCURACY("Accuracy"),
+
+ /**
+ * Precision.
+ */
+ PRECISION("Precision"),
+
+ /**
+ * Recall.
+ */
+ RECALL("Recall"),
+
+ /**
+ * F measure.
+ */
+ F_MEASURE("F-measure"),
+
+ /**
+ * TP.
+ */
+ TRUE_POSITIVE("TP"),
+
+ /**
+ * TN.
+ */
+ TRUE_NEGATIVE("TN"),
+
+ /**
+ * FN.
+ */
+ FALSE_NEGATIVE("FN"),
+
+ /**
+ * FP.
+ */
+ FALSE_POSITIVE("FP"),
+
+ /**
+ * Specificity.
+ */
+ SPECIFICITY("Specificity"),
+
+ /**
+ * NPV.
+ */
+ NPV("NPV"),
+
+ /**
+ * FallOut.
+ */
+ FALL_OUT("Fall out"),
+
+ /**
+ * FDR.
+ */
+ FDR("FDR"),
+
+ /**
+ * Miss Rate.
+ */
+ MISS_RATE("Miss rate"),
+
+ /**
+ * Balanced accuracy.
+ */
+ BALANCED_ACCURACY("Balanced accuracy"),
+
+ // regression metrics
+ /**
+ * Mae.
+ */
+ MAE("MAE"),
+
+ /**
+ * R 2.
+ */
+ R2("R2"),
+
+ /**
+ * Rmse.
+ */
+ RMSE("RMSE"),
+
+ /**
+ * Rss.
+ */
+ RSS("RSS"),
+
+ /**
+ * Mse.
+ */
+ MSE("MSE");
+
+ /**
+ * Pretty name.
+ */
+ private final String prettyName;
+
+ /**
+ * Creates an instance of MetricName.
+ *
+ * @param prettyName Pretty name.
+ */
+ MetricName(String prettyName) {
+ this.prettyName = prettyName;
+ }
+
+ /**
+ * Creates an instance of metric class by name.
+ *
+ * @return Metric instance.
+ */
+ public Metric create() {
+ switch (this) {
+ case ACCURACY:
+ return new Accuracy();
+ case PRECISION:
+ return new Precision();
+ case RECALL:
+ return new Recall();
+ case F_MEASURE:
+ return new FMeasure();
+ case MSE:
+ return new Mse();
+ case MAE:
+ return new Mae();
+ case R2:
+ return new R2();
+ case RMSE:
+ return new Rmse();
+ case RSS:
+ return new Rss();
+ case TRUE_POSITIVE:
+ return new TruePositiveAbsoluteValue();
+ case TRUE_NEGATIVE:
+ return new TrueNegativeAbsoluteValue();
+ case FALSE_POSITIVE:
+ return new FalsePositiveAbsoluteValue();
+ case FALSE_NEGATIVE:
+ return new FalseNegativeAbsoluteValue();
+ case SPECIFICITY:
+ return new Specificity();
+ case FALL_OUT:
+ return new FallOut();
+ case BALANCED_ACCURACY:
+ return new BalancedAccuracy();
+ case FDR:
+ return new Fdr();
+ case MISS_RATE:
+ return new MissRate();
+ case NPV:
+ return new Npv();
+ }
+
+ throw new IllegalArgumentException("Cannot define metric by name: " + name());
+ }
+
+ /**
+ * Returns pretty name.
+ *
+ * @return Name of metric.
+ */
+ public String getPrettyName() {
+ return prettyName;
+ }
+}
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/selection/scoring/metric/MetricValues.java b/modules/ml/src/main/java/org/apache/ignite/ml/selection/scoring/metric/MetricValues.java
deleted file mode 100644
index c942d96..0000000
--- a/modules/ml/src/main/java/org/apache/ignite/ml/selection/scoring/metric/MetricValues.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.ml.selection.scoring.metric;
-
-import java.lang.reflect.Field;
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * Common interface to present metric values for different ML tasks.
- */
-public interface MetricValues {
- /** Returns the pair of metric name and metric value. */
- public default Map<String, Double> toMap() {
- Map<String, Double> metricValues = new HashMap<>();
- Class<? extends MetricValues> aCls = getClass();
- for (Field field : aCls.getDeclaredFields()) {
- try {
- field.setAccessible(true);
- metricValues.put(field.getName(), field.getDouble(this));
- }
- catch (IllegalAccessException e) {
- throw new RuntimeException("Cannot read field [class=" + aCls.getSimpleName() + ", field_name=" + field.getName() + "]", e);
- }
- }
-
- return metricValues;
- }
-}
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/selection/scoring/metric/classification/Accuracy.java b/modules/ml/src/main/java/org/apache/ignite/ml/selection/scoring/metric/classification/Accuracy.java
index 0ab5cd4..7391791 100644
--- a/modules/ml/src/main/java/org/apache/ignite/ml/selection/scoring/metric/classification/Accuracy.java
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/selection/scoring/metric/classification/Accuracy.java
@@ -17,39 +17,58 @@
package org.apache.ignite.ml.selection.scoring.metric.classification;
-import org.apache.ignite.ml.selection.scoring.LabelPair;
+import java.io.Serializable;
+import org.apache.ignite.ml.selection.scoring.evaluator.aggregator.ClassificationMetricsAggregator;
+import org.apache.ignite.ml.selection.scoring.evaluator.context.EmptyContext;
import org.apache.ignite.ml.selection.scoring.metric.Metric;
-
-import java.util.Iterator;
+import org.apache.ignite.ml.selection.scoring.metric.MetricName;
/**
- * Accuracy score calculator.
- *
- * @param <L> Type of a label (truth or prediction).
+ * Accuracy metric class.
*/
-public class Accuracy<L> implements Metric<L> {
- /** {@inheritDoc} */
- @Override public double score(Iterator<LabelPair<L>> iter) {
- long totalCnt = 0;
- long correctCnt = 0;
+public class Accuracy<L extends Serializable> implements Metric<L, EmptyContext<L>, ClassificationMetricsAggregator<L>> {
+ /**
+ * Serial version uid.
+ */
+ private static final long serialVersionUID = -7042505196665295151L;
- while (iter.hasNext()) {
- LabelPair<L> e = iter.next();
+ /**
+ * Value.
+ */
+ private Double accuracy = Double.NaN;
- L prediction = e.getPrediction();
- L truth = e.getTruth();
+ /**
+ * Creates an instance of Accuracy metric.
+ */
+ public Accuracy() {
+ }
- if (prediction.equals(truth))
- correctCnt++;
+ /**
+ * {@inheritDoc}
+ */
+ @Override public Accuracy<L> initBy(ClassificationMetricsAggregator<L> aggr) {
+ accuracy = ((double)aggr.getValidAnswersCount()) / Math.max(aggr.getTotalNumberOfExamples(), 1);
+ return this;
+ }
- totalCnt++;
- }
+ /**
+ * {@inheritDoc}
+ */
+ @Override public ClassificationMetricsAggregator<L> makeAggregator() {
+ return new ClassificationMetricsAggregator<>();
+ }
- return 1.0 * correctCnt / totalCnt;
+ /**
+ * {@inheritDoc}
+ */
+ @Override public double value() {
+ return accuracy;
}
- /** {@inheritDoc} */
- @Override public String name() {
- return "accuracy";
+ /**
+ * {@inheritDoc}
+ */
+ @Override public MetricName name() {
+ return MetricName.ACCURACY;
}
}
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/selection/scoring/metric/classification/BalancedAccuracy.java b/modules/ml/src/main/java/org/apache/ignite/ml/selection/scoring/metric/classification/BalancedAccuracy.java
new file mode 100644
index 0000000..fbace40
--- /dev/null
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/selection/scoring/metric/classification/BalancedAccuracy.java
@@ -0,0 +1,79 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.selection.scoring.metric.classification;
+
+import java.io.Serializable;
+import org.apache.ignite.ml.selection.scoring.evaluator.aggregator.BinaryClassificationPointwiseMetricStatsAggregator;
+import org.apache.ignite.ml.selection.scoring.metric.MetricName;
+
+/**
+ * BalancedAccuracy metric class.
+ */
+public class BalancedAccuracy<L extends Serializable> extends BinaryClassificationMetric<L> {
+ /**
+ * Serial version uid.
+ */
+ private static final long serialVersionUID = 91677523635381939L;
+
+ /**
+ * Metric value.
+ */
+ private Double value = Double.NaN;
+
+ /**
+ * Creates an instance of BalancedAccuracy.
+ */
+ public BalancedAccuracy() {
+ }
+
+ /**
+ * Creates an instance of BalancedAccuracy class.
+ *
+ * @param truthLabel Truth label.
+ * @param falseLabel False label.
+ */
+ public BalancedAccuracy(L truthLabel, L falseLabel) {
+ super(truthLabel, falseLabel);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override public BalancedAccuracy<L> initBy(BinaryClassificationPointwiseMetricStatsAggregator<L> aggr) {
+ int n = aggr.getTrueNegative() + aggr.getFalsePositive();
+ ;
+ int p = aggr.getTruePositive() + aggr.getFalseNegative();
+ ;
+ value = n == 0 && p == 0 ? 1 : ((double)aggr.getTruePositive() / p + (double)aggr.getTrueNegative() / n) / 2;
+ return this;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override public double value() {
+ return value;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override public MetricName name() {
+ return MetricName.BALANCED_ACCURACY;
+ }
+}
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/selection/scoring/metric/classification/BinaryClassificationMetric.java b/modules/ml/src/main/java/org/apache/ignite/ml/selection/scoring/metric/classification/BinaryClassificationMetric.java
new file mode 100644
index 0000000..83d8d4f
--- /dev/null
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/selection/scoring/metric/classification/BinaryClassificationMetric.java
@@ -0,0 +1,71 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ignite.ml.selection.scoring.metric.classification;
+
+import java.io.Serializable;
+import org.apache.ignite.ml.selection.scoring.evaluator.aggregator.BinaryClassificationPointwiseMetricStatsAggregator;
+import org.apache.ignite.ml.selection.scoring.evaluator.context.BinaryClassificationEvaluationContext;
+import org.apache.ignite.ml.selection.scoring.metric.Metric;
+
+/**
+ * Common abstract class for all binary classification metrics.
+ */
+public abstract class BinaryClassificationMetric<L extends Serializable> implements Metric<L, BinaryClassificationEvaluationContext<L>, BinaryClassificationPointwiseMetricStatsAggregator<L>> {
+ /**
+ * Serial version uid.
+ */
+ private static final long serialVersionUID = 7549975086331141766L;
+
+ /**
+ * Truth label.
+ */
+ private final L truthLabel;
+
+ /**
+ * False label.
+ */
+ private final L falseLabel;
+
+ /**
+ * Creates an instance of BinaryClassificationMetric.
+ *
+ * @param truthLabel User provided truth label.
+ * @param falseLabel User provided false label.
+ */
+ public BinaryClassificationMetric(L truthLabel, L falseLabel) {
+ this.truthLabel = truthLabel;
+ this.falseLabel = falseLabel;
+ }
+
+ /**
+ * Creates an instance of BinaryClassificationMetric.
+ */
+ public BinaryClassificationMetric() {
+ truthLabel = null;
+ falseLabel = null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override public BinaryClassificationPointwiseMetricStatsAggregator<L> makeAggregator() {
+ if (truthLabel == null && falseLabel == null)
+ return new BinaryClassificationPointwiseMetricStatsAggregator<>();
+ else
+ return new BinaryClassificationPointwiseMetricStatsAggregator.WithCustomLabelsAggregator<>(truthLabel, falseLabel);
+ }
+}
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/selection/scoring/metric/classification/BinaryClassificationMetricValues.java b/modules/ml/src/main/java/org/apache/ignite/ml/selection/scoring/metric/classification/BinaryClassificationMetricValues.java
deleted file mode 100644
index 841faf6..0000000
--- a/modules/ml/src/main/java/org/apache/ignite/ml/selection/scoring/metric/classification/BinaryClassificationMetricValues.java
+++ /dev/null
@@ -1,181 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.ml.selection.scoring.metric.classification;
-
-import org.apache.ignite.ml.selection.scoring.metric.MetricValues;
-
-/**
- * Provides access to binary metric values.
- */
-public class BinaryClassificationMetricValues implements MetricValues {
- /** True Positive (TP). */
- private double tp;
-
- /** True Negative (TN). */
- private double tn;
-
- /** False Positive (FP). */
- private double fp;
-
- /** False Negative (FN). */
- private double fn;
-
- /** Sensitivity or True Positive Rate (TPR). */
- private double recall;
-
- /** Specificity (SPC) or True Negative Rate (TNR). */
- private double specificity;
-
- /** Precision or Positive Predictive Value (PPV). */
- private double precision;
-
- /** Negative Predictive Value (NPV). */
- private double npv;
-
- /** Fall-out or False Positive Rate (FPR). */
- private double fallOut;
-
- /** False Discovery Rate (FDR). */
- private double fdr;
-
- /** Miss Rate or False Negative Rate (FNR). */
- private double missRate;
-
- /** Accuracy. */
- private double accuracy;
-
- /** Balanced accuracy. */
- private double balancedAccuracy;
-
- /** F1-Score is the harmonic mean of Precision and Sensitivity. */
- private double f1Score;
-
- /** ROC AUC. */
- private double rocauc;
-
- /**
- * Initialize an example by 4 metrics.
- *
- * @param tp True Positive (TP).
- * @param tn True Negative (TN).
- * @param fp False Positive (FP).
- * @param fn False Negative (FN).
- */
- public BinaryClassificationMetricValues(long tp, long tn, long fp, long fn, double rocauc) {
- this.tp = tp;
- this.tn = tn;
- this.fp = fp;
- this.fn = fn;
- this.rocauc = rocauc;
-
- long p = tp + fn;
- long n = tn + fp;
- long positivePredictions = tp + fp;
- long negativePredictions = tn + fn;
-
- // according to https://github.com/dice-group/gerbil/wiki/Precision,-Recall-and-F1-measure
- recall = p == 0 ? 1 : (double)tp / p;
- precision = positivePredictions == 0 ? 1 : (double)tp / positivePredictions;
- specificity = n == 0 ? 1 : (double)tn / n;
- npv = negativePredictions == 0 ? 1 : (double)tn / negativePredictions;
- fallOut = n == 0 ? 1 : (double)fp / n;
- fdr = positivePredictions == 0 ? 1 : (double)fp / positivePredictions;
- missRate = p == 0 ? 1 : (double)fn / p;
-
- f1Score = 2 * (recall * precision) / (recall + precision);
-
- accuracy = (p + n) == 0 ? 1 : (double)(tp + tn) / (p + n); // multiplication on 1.0 to make double
- balancedAccuracy = p == 0 && n == 0 ? 1 : ((double)tp / p + (double)tn / n) / 2;
- }
-
- /** */
- public double tp() {
- return tp;
- }
-
- /** */
- public double tn() {
- return tn;
- }
-
- /** */
- public double fp() {
- return fp;
- }
-
- /** */
- public double fn() {
- return fn;
- }
-
- /** Returns Sensitivity or True Positive Rate (TPR). */
- public double recall() {
- return recall;
- }
-
- /** Returns Specificity (SPC) or True Negative Rate (TNR). */
- public double specificity() {
- return specificity;
- }
-
- /** Returns Precision or Positive Predictive Value (PPV). */
- public double precision() {
- return precision;
- }
-
- /** Returns Negative Predictive Value (NPV). */
- public double npv() {
- return npv;
- }
-
- /** Returns Fall-out or False Positive Rate (FPR). */
- public double fallOut() {
- return fallOut;
- }
-
- /** Returns False Discovery Rate (FDR). */
- public double fdr() {
- return fdr;
- }
-
- /** Returns Miss Rate or False Negative Rate (FNR). */
- public double missRate() {
- return missRate;
- }
-
- /** Returns Accuracy. */
- public double accuracy() {
- return accuracy;
- }
-
- /** Returns Balanced accuracy. */
- public double balancedAccuracy() {
- return balancedAccuracy;
- }
-
- /** Returns F1-Score is the harmonic mean of Precision and Sensitivity. */
- public double f1Score() {
- return f1Score;
- }
-
- /** Returns ROCAUC value. */
- public double rocauc() {
- return rocauc;
- }
-
-}
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/selection/scoring/metric/classification/BinaryClassificationMetrics.java b/modules/ml/src/main/java/org/apache/ignite/ml/selection/scoring/metric/classification/BinaryClassificationMetrics.java
deleted file mode 100644
index d9a6715..0000000
--- a/modules/ml/src/main/java/org/apache/ignite/ml/selection/scoring/metric/classification/BinaryClassificationMetrics.java
+++ /dev/null
@@ -1,138 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.ml.selection.scoring.metric.classification;
-
-import java.util.Comparator;
-import java.util.Iterator;
-import java.util.PriorityQueue;
-import org.apache.commons.math3.util.Pair;
-import org.apache.ignite.ml.selection.scoring.LabelPair;
-import org.apache.ignite.ml.selection.scoring.metric.AbstractMetrics;
-import org.apache.ignite.ml.selection.scoring.metric.exceptions.UnknownClassLabelException;
-
-/**
- * Binary classification metrics calculator.
- * It could be used in two ways: to caculate all binary classification metrics or specific metric.
- */
-public class BinaryClassificationMetrics extends AbstractMetrics<BinaryClassificationMetricValues> {
- /** Positive class label. */
- private double positiveClsLb = 1.0;
-
- /** Negative class label. Default value is 0.0. */
- private double negativeClsLb;
-
- /** This flag enabels ROC AUC calculation that is hard for perfromance due to internal implementation. */
- private boolean enableROCAUC;
-
- {
- metric = BinaryClassificationMetricValues::accuracy;
- }
-
- /**
- * Calculates binary metrics values.
- *
- * @param iter Iterator that supplies pairs of truth values and predicated.
- * @return Scores for all binary metrics.
- */
- @Override public BinaryClassificationMetricValues scoreAll(Iterator<LabelPair<Double>> iter) {
- long tp = 0;
- long tn = 0;
- long fp = 0;
- long fn = 0;
- double rocauc = Double.NaN;
-
- // for ROC AUC calculation
- long pos = 0;
- long neg = 0;
- PriorityQueue<Pair<Double, Double>> queue = new PriorityQueue<>(Comparator.comparingDouble(Pair::getKey));
-
- while (iter.hasNext()) {
- LabelPair<Double> e = iter.next();
-
- double prediction = e.getPrediction();
- double truth = e.getTruth();
-
- if (prediction != negativeClsLb && prediction != positiveClsLb)
- throw new UnknownClassLabelException(prediction, positiveClsLb, negativeClsLb);
- if (truth != negativeClsLb && truth != positiveClsLb)
- throw new UnknownClassLabelException(truth, positiveClsLb, negativeClsLb);
-
- if (truth == positiveClsLb && prediction == positiveClsLb) tp++;
- else if (truth == positiveClsLb && prediction == negativeClsLb) fn++;
- else if (truth == negativeClsLb && prediction == negativeClsLb) tn++;
- else if (truth == negativeClsLb && prediction == positiveClsLb) fp++;
-
- if(enableROCAUC) {
- queue.add(new Pair<>(prediction, truth));
-
- if (truth == positiveClsLb)
- pos++;
- else if (truth == negativeClsLb)
- neg++;
- else
- throw new UnknownClassLabelException(truth, positiveClsLb, negativeClsLb);
- }
-
- }
-
- if (enableROCAUC)
- rocauc = ROCAUC.calculateROCAUC(queue, pos, neg, positiveClsLb);
-
- return new BinaryClassificationMetricValues(tp, tn, fp, fn, rocauc);
- }
-
- /** */
- public double positiveClsLb() {
- return positiveClsLb;
- }
-
- /** */
- public BinaryClassificationMetrics withPositiveClsLb(double positiveClsLb) {
- if (Double.isFinite(positiveClsLb))
- this.positiveClsLb = positiveClsLb;
- return this;
- }
-
- /** */
- public double negativeClsLb() {
- return negativeClsLb;
- }
-
- /** */
- public BinaryClassificationMetrics withNegativeClsLb(double negativeClsLb) {
- if (Double.isFinite(negativeClsLb))
- this.negativeClsLb = negativeClsLb;
- return this;
- }
-
- /** */
- public BinaryClassificationMetrics withEnablingROCAUC(boolean enableROCAUC) {
- this.enableROCAUC = enableROCAUC;
- return this;
- }
-
- /** */
- public boolean isROCAUCenabled() {
- return enableROCAUC;
- }
-
- /** {@inheritDoc} */
- @Override public String name() {
- return "Binary classification metrics";
- }
-}
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/selection/scoring/metric/classification/ClassMetric.java b/modules/ml/src/main/java/org/apache/ignite/ml/selection/scoring/metric/classification/ClassMetric.java
deleted file mode 100644
index 2a0a7eb..0000000
--- a/modules/ml/src/main/java/org/apache/ignite/ml/selection/scoring/metric/classification/ClassMetric.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.ml.selection.scoring.metric.classification;
-
-import org.apache.ignite.ml.selection.scoring.metric.Metric;
-
-/**
- * Metric calculator for one class label.
- *
- * @param <L> Type of a label (truth or prediction).
- */
-public abstract class ClassMetric<L> implements Metric<L> {
- /** Class label. */
- protected L clsLb;
-
- /**
- * The class of interest or positive class.
- *
- * @param clsLb The label.
- */
- public ClassMetric(L clsLb) {
- this.clsLb = clsLb;
- }
-}
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/selection/scoring/metric/classification/FMeasure.java b/modules/ml/src/main/java/org/apache/ignite/ml/selection/scoring/metric/classification/FMeasure.java
new file mode 100644
index 0000000..df8aa42
--- /dev/null
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/selection/scoring/metric/classification/FMeasure.java
@@ -0,0 +1,118 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.selection.scoring.metric.classification;
+
+import java.io.Serializable;
+import org.apache.ignite.ml.selection.scoring.evaluator.aggregator.BinaryClassificationPointwiseMetricStatsAggregator;
+import org.apache.ignite.ml.selection.scoring.metric.MetricName;
+
+/**
+ * F-measure metric class.
+ */
+public class FMeasure<L extends Serializable> extends BinaryClassificationMetric<L> {
+ /**
+ * Serial version uid.
+ */
+ private static final long serialVersionUID = 9156779288165194348L;
+
+ /**
+ * Square of beta parameter for F-score.
+ */
+ private final double betaSquare;
+
+ /**
+ * Precision.
+ */
+ private final Precision<L> precision = new Precision<L>();
+
+ /**
+ * Recall.
+ */
+ private final Recall<L> recall = new Recall<L>();
+
+ /**
+ * Fscore.
+ */
+ private Double fscore = Double.NaN;
+
+ /**
+ * Creates an instance of FScore class.
+ *
+ * @param beta Beta (see https://en.wikipedia.org/wiki/F1_score ).
+ */
+ public FMeasure(double beta) {
+ betaSquare = Math.pow(beta, 2);
+ }
+
+ /**
+ * Creates an instance of FScore class.
+ */
+ public FMeasure() {
+ betaSquare = 1;
+ }
+
+ /**
+ * Creates an instance of FScore class.
+ *
+ * @param truthLabel Truth label.
+ * @param falseLabel False label.
+ * @param betaSquare Squared beta parameter.
+ */
+ public FMeasure(L truthLabel, L falseLabel, double betaSquare) {
+ super(truthLabel, falseLabel);
+ this.betaSquare = betaSquare;
+ }
+
+ /**
+ * Creates an instance of FScore class.
+ *
+ * @param truthLabel Truth label.
+ * @param falseLabel False label.
+ */
+ public FMeasure(L truthLabel, L falseLabel) {
+ super(truthLabel, falseLabel);
+ this.betaSquare = 1;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override public FMeasure<L> initBy(BinaryClassificationPointwiseMetricStatsAggregator<L> aggr) {
+ precision.initBy(aggr);
+ recall.initBy(aggr);
+
+ double nom = (1 + betaSquare) * precision.value() * recall.value();
+ double denom = (betaSquare * precision.value() + recall.value());
+ fscore = nom / denom;
+ return this;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override public double value() {
+ return fscore;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override public MetricName name() {
+ return MetricName.F_MEASURE;
+ }
+}
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/selection/scoring/metric/classification/FallOut.java b/modules/ml/src/main/java/org/apache/ignite/ml/selection/scoring/metric/classification/FallOut.java
new file mode 100644
index 0000000..f0aa813
--- /dev/null
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/selection/scoring/metric/classification/FallOut.java
@@ -0,0 +1,77 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.selection.scoring.metric.classification;
+
+import java.io.Serializable;
+import org.apache.ignite.ml.selection.scoring.evaluator.aggregator.BinaryClassificationPointwiseMetricStatsAggregator;
+import org.apache.ignite.ml.selection.scoring.metric.MetricName;
+
+/**
+ * FallOut metric class.
+ */
+public class FallOut<L extends Serializable> extends BinaryClassificationMetric<L> {
+ /**
+ * Serial version uid.
+ */
+ private static final long serialVersionUID = -2644409083604699500L;
+
+ /**
+ * Metric value.
+ */
+ private Double value = Double.NaN;
+
+ /**
+ * Creates an instance of FallOut.
+ */
+ public FallOut() {
+ }
+
+ /**
+ * Creates an instance of FallOut class.
+ *
+ * @param truthLabel Truth label.
+ * @param falseLabel False label.
+ */
+ public FallOut(L truthLabel, L falseLabel) {
+ super(truthLabel, falseLabel);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override public FallOut<L> initBy(BinaryClassificationPointwiseMetricStatsAggregator<L> aggr) {
+ int n = aggr.getTrueNegative() + aggr.getFalsePositive();
+ ;
+ value = n == 0 ? 1 : (double)aggr.getFalsePositive() / n;
+ return this;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override public double value() {
+ return value;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override public MetricName name() {
+ return MetricName.FALL_OUT;
+ }
+}
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/selection/scoring/metric/classification/FalseNegativeAbsoluteValue.java b/modules/ml/src/main/java/org/apache/ignite/ml/selection/scoring/metric/classification/FalseNegativeAbsoluteValue.java
new file mode 100644
index 0000000..8e6f574
--- /dev/null
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/selection/scoring/metric/classification/FalseNegativeAbsoluteValue.java
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.selection.scoring.metric.classification;
+
+import java.io.Serializable;
+import org.apache.ignite.ml.selection.scoring.evaluator.aggregator.BinaryClassificationPointwiseMetricStatsAggregator;
+import org.apache.ignite.ml.selection.scoring.metric.MetricName;
+
+/**
+ * FalseNegative metric class.
+ */
+public class FalseNegativeAbsoluteValue<L extends Serializable> extends BinaryClassificationMetric<L> {
+ /**
+ * Serial version uid.
+ */
+ private static final long serialVersionUID = 1888543464986349144L;
+
+ /**
+ * FN value.
+ */
+ private Double fn = Double.NaN;
+
+ /**
+ * Creates an instance of FalseNegativeAbsoluteValue.
+ */
+ public FalseNegativeAbsoluteValue() {
+ }
+
+ /**
+ * Creates an instance of FalseNegativeAbsoluteValue class.
+ *
+ * @param truthLabel Truth label.
+ * @param falseLabel False label.
+ */
+ public FalseNegativeAbsoluteValue(L truthLabel, L falseLabel) {
+ super(truthLabel, falseLabel);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override public FalseNegativeAbsoluteValue<L> initBy(BinaryClassificationPointwiseMetricStatsAggregator<L> aggr) {
+ fn = (double)aggr.getFalseNegative();
+ return this;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override public double value() {
+ return fn;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override public MetricName name() {
+ return MetricName.FALSE_NEGATIVE;
+ }
+}
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/selection/scoring/metric/classification/FalsePositiveAbsoluteValue.java b/modules/ml/src/main/java/org/apache/ignite/ml/selection/scoring/metric/classification/FalsePositiveAbsoluteValue.java
new file mode 100644
index 0000000..e8fa878
--- /dev/null
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/selection/scoring/metric/classification/FalsePositiveAbsoluteValue.java
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.selection.scoring.metric.classification;
+
+import java.io.Serializable;
+import org.apache.ignite.ml.selection.scoring.evaluator.aggregator.BinaryClassificationPointwiseMetricStatsAggregator;
+import org.apache.ignite.ml.selection.scoring.metric.MetricName;
+
+/**
+ * FalsePositive metric class.
+ */
+public class FalsePositiveAbsoluteValue<L extends Serializable> extends BinaryClassificationMetric<L> {
+ /**
+ * Serial version uid.
+ */
+ private static final long serialVersionUID = 5110086813607332001L;
+
+ /**
+ * FP value.
+ */
+ private Double fp = Double.NaN;
+
+ /**
+ * Creates an instance of FalsePositiveAbsoluteValue.
+ */
+ public FalsePositiveAbsoluteValue() {
+ }
+
+ /**
+ * Creates an instance of FalsePositiveAbsoluteValue class.
+ *
+ * @param truthLabel Truth label.
+ * @param falseLabel False label.
+ */
+ public FalsePositiveAbsoluteValue(L truthLabel, L falseLabel) {
+ super(truthLabel, falseLabel);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override public FalsePositiveAbsoluteValue<L> initBy(BinaryClassificationPointwiseMetricStatsAggregator<L> aggr) {
+ fp = (double)aggr.getFalsePositive();
+ return this;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override public double value() {
+ return fp;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override public MetricName name() {
+ return MetricName.FALSE_POSITIVE;
+ }
+}
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/selection/scoring/metric/classification/Fdr.java b/modules/ml/src/main/java/org/apache/ignite/ml/selection/scoring/metric/classification/Fdr.java
new file mode 100644
index 0000000..8060b9b
--- /dev/null
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/selection/scoring/metric/classification/Fdr.java
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.selection.scoring.metric.classification;
+
+import java.io.Serializable;
+import org.apache.ignite.ml.selection.scoring.evaluator.aggregator.BinaryClassificationPointwiseMetricStatsAggregator;
+import org.apache.ignite.ml.selection.scoring.metric.MetricName;
+
+/**
+ * FDR metric class.
+ */
+public class Fdr<L extends Serializable> extends BinaryClassificationMetric<L> {
+ /**
+ * Serial version uid.
+ */
+ private static final long serialVersionUID = 1246865138630168628L;
+
+ /**
+ * Metric value.
+ */
+ private Double value = Double.NaN;
+
+ /**
+ * Creates an instance of Fdr class.
+ */
+ public Fdr() {
+ }
+
+ /**
+ * Creates an instance of FDR class.
+ *
+ * @param truthLabel Truth label.
+ * @param falseLabel False label.
+ */
+ public Fdr(L truthLabel, L falseLabel) {
+ super(truthLabel, falseLabel);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override public Fdr<L> initBy(BinaryClassificationPointwiseMetricStatsAggregator<L> aggr) {
+ int positivePredictions = aggr.getFalsePositive() + aggr.getTruePositive();
+ value = positivePredictions == 0 ? 1 : (double)aggr.getTruePositive() / positivePredictions;
+ return this;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override public double value() {
+ return value;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override public MetricName name() {
+ return MetricName.FDR;
+ }
+}
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/selection/scoring/metric/classification/Fmeasure.java b/modules/ml/src/main/java/org/apache/ignite/ml/selection/scoring/metric/classification/Fmeasure.java
deleted file mode 100644
index 10f5c5c..0000000
--- a/modules/ml/src/main/java/org/apache/ignite/ml/selection/scoring/metric/classification/Fmeasure.java
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.ml.selection.scoring.metric.classification;
-
-import org.apache.ignite.ml.selection.scoring.LabelPair;
-
-import java.util.Iterator;
-
-/**
- * F-measure calculator.
- *
- * @param <L> Type of a label (truth or prediction).
- */
-public class Fmeasure<L> extends ClassMetric<L> {
- /**
- * The class of interest or positive class.
- *
- * @param clsLb The label.
- */
- public Fmeasure(L clsLb) {
- super(clsLb);
- }
-
- /** {@inheritDoc} */
- @Override public double score(Iterator<LabelPair<L>> it) {
- if (clsLb != null) {
- long tp = 0;
- long fn = 0;
- long fp = 0;
- double recall;
- double precision;
-
- while (it.hasNext()) {
- LabelPair<L> e = it.next();
-
- L prediction = e.getPrediction();
- L truth = e.getTruth();
-
- if (clsLb.equals(truth)) {
- if (prediction.equals(truth))
- tp++;
- else
- fn++;
- }
-
- if (clsLb.equals(prediction) && !prediction.equals(truth))
- fp++;
- }
- long denominatorRecall = tp + fn;
-
- long denominatorPrecision = tp + fp;
-
- // according to https://github.com/dice-group/gerbil/wiki/Precision,-Recall-and-F1-measure
- recall = denominatorRecall == 0 ? 1 : (double)tp / denominatorRecall;
- precision = denominatorPrecision == 0 ? 1 : (double)tp / denominatorPrecision;
-
- return 2 * (recall * precision) / (recall + precision);
- }
- else
- return Double.NaN;
- }
-
- /** {@inheritDoc} */
- @Override public String name() {
- return "F-measure for class with label " + clsLb;
- }
-}
... 2842 lines suppressed ...