12#ifndef MLPACK_CORE_DATA_IMPUTE_STRATEGIES_MEAN_IMPUTATION_HPP
13#define MLPACK_CORE_DATA_IMPUTE_STRATEGIES_MEAN_IMPUTATION_HPP
39 const size_t dimension,
40 const bool columnMajor =
true)
45 using PairType = std::pair<size_t, size_t>;
47 std::vector<PairType> targets;
54 for (
size_t i = 0; i < input.n_cols; ++i)
56 if (input(dimension, i) == mappedValue ||
57 std::isnan(input(dimension, i)))
59 targets.emplace_back(dimension, i);
64 sum += input(dimension, i);
70 for (
size_t i = 0; i < input.n_rows; ++i)
72 if (input(i, dimension) == mappedValue ||
73 std::isnan(input(i, dimension)))
75 targets.emplace_back(i, dimension);
80 sum += input(i, dimension);
86 Log::Fatal <<
"it is impossible to calculate mean; no valid elements in "
87 <<
"the dimension" << std::endl;
90 const double mean = sum / elems;
94 for (
const PairType& target : targets)
96 input(target.first, target.second) = mean;
static MLPACK_EXPORT util::PrefixedOutStream Fatal
Prints fatal messages prefixed with [FATAL], then terminates the program.
A simple mean imputation class.
void Impute(arma::Mat< T > &input, const T &mappedValue, const size_t dimension, const bool columnMajor=true)
Impute function searches through the input looking for mappedValue and replaces it with the mean of t...
Linear algebra utility functions, generally performed on matrices or vectors.
The core includes that mlpack expects; standard C++ includes and Armadillo.