test_class.file: modules/ml/src/test/java/org/apache/ignite/ml/preprocessing/imputing/ImputerTrainerTest.java
test_class.identifier: ImputerTrainerTest
test_class.superclass: extends TrainerTest
test_case.body: @Test
      public void testFit() {
          Map<Integer, Vector> data = new HashMap<>();
          data.put(1, VectorUtils.of(1, 2, Double.NaN));
          data.put(2, VectorUtils.of(1, Double.NaN, 22));
          data.put(3, VectorUtils.of(Double.NaN, 10, 100));
          data.put(4, VectorUtils.of(0, 2, 100));
  
          DatasetBuilder<Integer, Vector> datasetBuilder = new LocalDatasetBuilder<>(data, parts);
  
          final Vectorizer<Integer, Vector, Integer, Double> vectorizer = new DummyVectorizer<>(0, 1, 2);
  
          ImputerTrainer<Integer, Vector> imputerTrainer = new ImputerTrainer<Integer, Vector>()
              .withImputingStrategy(ImputingStrategy.MOST_FREQUENT);
  
          ImputerPreprocessor<Integer, Vector> preprocessor = imputerTrainer.fit(
              TestUtils.testEnvBuilder(),
              datasetBuilder,
              vectorizer
          );
  
          assertArrayEquals(new double[] {1, 0, 100}, preprocessor.apply(5, VectorUtils.of(Double.NaN, 0, Double.NaN)).features().asArray(), 1e-8);
      }
test_case.class_method_signature: ImputerTrainerTest.testFit()
test_case.full_signature: @Test public void testFit()
test_case.identifier: testFit
test_case.invocations: put of put of put of put of withImputingStrategy fit testEnvBuilder assertArrayEquals asArray features apply of
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testFit()
focal_class.declarator: imputingStgy = ImputingStrategy.MEAN
focal_class.modifier: private
focal_class.original_string: private ImputingStrategy imputingStgy = ImputingStrategy.MEAN;
focal_class.type: ImputingStrategy
focal_class.var_name: imputingStgy
focal_class.file: modules/ml/src/main/java/org/apache/ignite/ml/preprocessing/imputing/ImputerTrainer.java
focal_class.identifier: ImputerTrainer
focal_class.interfaces: implements PreprocessingTrainer<K, V>
focal_class.class_method_signature: ImputerTrainer.fit(LearningEnvironmentBuilder envBuilder, DatasetBuilder<K, V> datasetBuilder,
                                                     Preprocessor<K, V> basePreprocessor)
focal_class.full_signature: @Override public ImputerPreprocessor<K, V> fit(LearningEnvironmentBuilder envBuilder, DatasetBuilder<K, V> datasetBuilder,
                                                     Preprocessor<K, V> basePreprocessor)
focal_class.identifier: fit
focal_class.modifiers: @Override public
focal_class.parameters: (LearningEnvironmentBuilder envBuilder, DatasetBuilder<K, V> datasetBuilder,
                                                     Preprocessor<K, V> basePreprocessor)
focal_class.return: ImputerPreprocessor<K, V>
focal_class.signature: ImputerPreprocessor<K, V> fit(LearningEnvironmentBuilder envBuilder, DatasetBuilder<K, V> datasetBuilder,
                                                     Preprocessor<K, V> basePreprocessor)
focal_class.class_method_signature: ImputerTrainer.calculateImputingValuesByFrequencies(
          Dataset<EmptyContext, ImputerPartitionData> dataset)
focal_class.full_signature: private double[] calculateImputingValuesByFrequencies(
          Dataset<EmptyContext, ImputerPartitionData> dataset)
focal_class.identifier: calculateImputingValuesByFrequencies
focal_class.modifiers: private
focal_class.parameters: (
          Dataset<EmptyContext, ImputerPartitionData> dataset)
focal_class.return: double[]
focal_class.signature: double[] calculateImputingValuesByFrequencies(
          Dataset<EmptyContext, ImputerPartitionData> dataset)
focal_class.class_method_signature: ImputerTrainer.calculateImputingValuesBySumsAndCounts(Dataset<EmptyContext, ImputerPartitionData> dataset)
focal_class.full_signature: private double[] calculateImputingValuesBySumsAndCounts(Dataset<EmptyContext, ImputerPartitionData> dataset)
focal_class.identifier: calculateImputingValuesBySumsAndCounts
focal_class.modifiers: private
focal_class.parameters: (Dataset<EmptyContext, ImputerPartitionData> dataset)
focal_class.return: double[]
focal_class.signature: double[] calculateImputingValuesBySumsAndCounts(Dataset<EmptyContext, ImputerPartitionData> dataset)
focal_class.class_method_signature: ImputerTrainer.calculateFrequencies(LabeledVector row, Map<Double, Integer>[] valuesByFreq)
focal_class.full_signature: private Map<Double, Integer>[] calculateFrequencies(LabeledVector row, Map<Double, Integer>[] valuesByFreq)
focal_class.identifier: calculateFrequencies
focal_class.modifiers: private
focal_class.parameters: (LabeledVector row, Map<Double, Integer>[] valuesByFreq)
focal_class.return: Map<Double, Integer>[]
focal_class.signature: Map<Double, Integer>[] calculateFrequencies(LabeledVector row, Map<Double, Integer>[] valuesByFreq)
focal_class.class_method_signature: ImputerTrainer.calculateTheSums(LabeledVector row, double[] sums)
focal_class.full_signature: private double[] calculateTheSums(LabeledVector row, double[] sums)
focal_class.identifier: calculateTheSums
focal_class.modifiers: private
focal_class.parameters: (LabeledVector row, double[] sums)
focal_class.return: double[]
focal_class.signature: double[] calculateTheSums(LabeledVector row, double[] sums)
focal_class.class_method_signature: ImputerTrainer.calculateTheCounts(LabeledVector row, int[] counts)
focal_class.full_signature: private int[] calculateTheCounts(LabeledVector row, int[] counts)
focal_class.identifier: calculateTheCounts
focal_class.modifiers: private
focal_class.parameters: (LabeledVector row, int[] counts)
focal_class.return: int[]
focal_class.signature: int[] calculateTheCounts(LabeledVector row, int[] counts)
focal_class.class_method_signature: ImputerTrainer.withImputingStrategy(ImputingStrategy imputingStgy)
focal_class.full_signature: public ImputerTrainer<K, V> withImputingStrategy(ImputingStrategy imputingStgy)
focal_class.identifier: withImputingStrategy
focal_class.modifiers: public
focal_class.parameters: (ImputingStrategy imputingStgy)
focal_class.return: ImputerTrainer<K, V>
focal_class.signature: ImputerTrainer<K, V> withImputingStrategy(ImputingStrategy imputingStgy)
focal_method.body: @Override public ImputerPreprocessor<K, V> fit(LearningEnvironmentBuilder envBuilder, DatasetBuilder<K, V> datasetBuilder,
                                                     Preprocessor<K, V> basePreprocessor) {
          PartitionContextBuilder<K, V, EmptyContext> builder = (env, upstream, upstreamSize) -> new EmptyContext();
          try (Dataset<EmptyContext, ImputerPartitionData> dataset = datasetBuilder.build(
              envBuilder,
              builder,
              (env, upstream, upstreamSize, ctx) -> {
                  double[] sums = null;
                  int[] counts = null;
                  Map<Double, Integer>[] valuesByFreq = null;
  
                  while (upstream.hasNext()) {
                      UpstreamEntry<K, V> entity = upstream.next();
                      LabeledVector row = basePreprocessor.apply(entity.getKey(), entity.getValue());
  
                      switch (imputingStgy) {
                          case MEAN:
                              sums = calculateTheSums(row, sums);
                              counts = calculateTheCounts(row, counts);
                              break;
                          case MOST_FREQUENT:
                              valuesByFreq = calculateFrequencies(row, valuesByFreq);
                              break;
                          default: throw new UnsupportedOperationException("The chosen strategy is not supported");
                      }
                  }
  
                  ImputerPartitionData partData;
  
                  switch (imputingStgy) {
                      case MEAN:
                          partData = new ImputerPartitionData().withSums(sums).withCounts(counts);
                          break;
                      case MOST_FREQUENT:
                          partData = new ImputerPartitionData().withValuesByFrequency(valuesByFreq);
                          break;
                      default: throw new UnsupportedOperationException("The chosen strategy is not supported");
                  }
                  return partData;
              }, learningEnvironment(basePreprocessor)
          )) {
  
              Vector imputingValues;
  
              switch (imputingStgy) {
                  case MEAN:
                      imputingValues = VectorUtils.of(calculateImputingValuesBySumsAndCounts(dataset));
                      break;
                  case MOST_FREQUENT:
                      imputingValues = VectorUtils.of(calculateImputingValuesByFrequencies(dataset));
                      break;
                  default: throw new UnsupportedOperationException("The chosen strategy is not supported");
              }
  
              return new ImputerPreprocessor<>(imputingValues, basePreprocessor);
  
          }
          catch (Exception e) {
              throw new RuntimeException(e);
          }
      }
focal_method.class_method_signature: ImputerTrainer.fit(LearningEnvironmentBuilder envBuilder, DatasetBuilder<K, V> datasetBuilder,
                                                     Preprocessor<K, V> basePreprocessor)
focal_method.full_signature: @Override public ImputerPreprocessor<K, V> fit(LearningEnvironmentBuilder envBuilder, DatasetBuilder<K, V> datasetBuilder,
                                                     Preprocessor<K, V> basePreprocessor)
focal_method.identifier: fit
focal_method.invocations: build hasNext next apply getKey getValue calculateTheSums calculateTheCounts calculateFrequencies withCounts withSums withValuesByFrequency learningEnvironment of calculateImputingValuesBySumsAndCounts of calculateImputingValuesByFrequencies
focal_method.modifiers: @Override public
focal_method.parameters: (LearningEnvironmentBuilder envBuilder, DatasetBuilder<K, V> datasetBuilder,
                                                     Preprocessor<K, V> basePreprocessor)
focal_method.return: ImputerPreprocessor<K, V>
focal_method.signature: ImputerPreprocessor<K, V> fit(LearningEnvironmentBuilder envBuilder, DatasetBuilder<K, V> datasetBuilder,
                                                     Preprocessor<K, V> basePreprocessor)