custom_imputation.hpp
Go to the documentation of this file.
1 
12 #ifndef MLPACK_CORE_DATA_IMPUTE_STRATEGIES_CUSTOM_IMPUTATION_HPP
13 #define MLPACK_CORE_DATA_IMPUTE_STRATEGIES_CUSTOM_IMPUTATION_HPP
14 
15 #include <mlpack/prereqs.hpp>
16 
17 namespace mlpack {
18 namespace data {
23 template <typename T>
25 {
26  public:
27  CustomImputation(T customValue):
28  customValue(std::move(customValue))
29  {
30  // nothing to initialize here
31  }
32 
44  void Impute(arma::Mat<T>& input,
45  const T& mappedValue,
46  const size_t dimension,
47  const bool columnMajor = true)
48  {
49  // replace the target value to custom value
50  if (columnMajor)
51  {
52  for (size_t i = 0; i < input.n_cols; ++i)
53  {
54  if (input(dimension, i) == mappedValue ||
55  std::isnan(input(dimension, i)))
56  {
57  input(dimension, i) = customValue;
58  }
59  }
60  }
61  else
62  {
63  for (size_t i = 0; i < input.n_rows; ++i)
64  {
65  if (input(i, dimension) == mappedValue ||
66  std::isnan(input(i, dimension)))
67  {
68  input(i, dimension) = customValue;
69  }
70  }
71  }
72  }
73 
74  private:
76  T customValue;
77 }; // class CustomImputation
78 
79 } // namespace data
80 } // namespace mlpack
81 
82 #endif
A simple custom imputation class.
Linear algebra utility functions, generally performed on matrices or vectors.
The core includes that mlpack expects; standard C++ includes and Armadillo.
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 user-defi...