mrk-andreev commented on a change in pull request #8466:
URL: https://github.com/apache/ignite/pull/8466#discussion_r535916676
##########
File path:
modules/ml/src/main/java/org/apache/ignite/ml/preprocessing/encoding/EncoderTrainer.java
##########
@@ -116,6 +143,77 @@
}
}
+ /**
+ * Calculates encoding frequencies as frequency divided on amount of rows
in dataset.
+ *
+ * NOTE: The amount of rows is calculated as sum of absolute frequencies.
+ *
+ * @param dataset Dataset.
+ * @return Encoding frequency for each feature.
+ */
+ private TargetEncodingMeta[]
calculateTargetEncodingFrequencies(Dataset<EmptyContext, EncoderPartitionData>
dataset) {
+ TargetCounter[] targetCounters = dataset.compute(
+ EncoderPartitionData::targetCounters,
+ (a, b) -> {
+ if (a == null)
+ return b;
+
+ if (b == null)
+ return a;
+
+ assert a.length == b.length;
+
+ for (int i = 0; i < a.length; i++) {
+ if (handledIndices.contains(i)) {
+ int finalI = i;
+ b[i].setTargetSum(a[i].getTargetSum() +
b[i].getTargetSum());
+ b[i].setTargetCount(a[i].getTargetCount() +
b[i].getTargetCount());
+ a[i].getCategoryCounts()
+ .forEach((k, v) ->
b[finalI].getCategoryCounts().merge(k, v, Long::sum));
+ a[i].getCategoryTargetSum()
+ .forEach((k, v) ->
b[finalI].getCategoryTargetSum().merge(k, v, Double::sum));
+ }
+ }
+ return b;
+ }
+ );
+
+ TargetEncodingMeta[] targetEncodingMetas = new
TargetEncodingMeta[targetCounters.length];
+ for (int i = 0; i < targetCounters.length; i++) {
+ if (handledIndices.contains(i)) {
+ int finalI = i;
+
+ targetEncodingMetas[i] = new TargetEncodingMeta(
+ targetCounters[i].getTargetSum() /
targetCounters[i].getTargetCount(),
Review comment:
Extracted to new method
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]