mlpack 3.4.2
Loading...
Searching...
No Matches
listwise_deletion.hpp
Go to the documentation of this file.
1
12#ifndef MLPACK_CORE_DATA_IMPUTE_STRATEGIES_LISTWISE_DELETION_HPP
13#define MLPACK_CORE_DATA_IMPUTE_STRATEGIES_LISTWISE_DELETION_HPP
14
15#include <mlpack/prereqs.hpp>
16
17namespace mlpack {
18namespace data {
24template <typename T>
26{
27 public:
37 void Impute(arma::Mat<T>& input,
38 const T& mappedValue,
39 const size_t dimension,
40 const bool columnMajor = true)
41 {
42 std::vector<arma::uword> colsToKeep;
43
44 if (columnMajor)
45 {
46 for (size_t i = 0; i < input.n_cols; ++i)
47 {
48 if (!(input(dimension, i) == mappedValue ||
49 std::isnan(input(dimension, i))))
50 {
51 colsToKeep.push_back(i);
52 }
53 }
54 input = input.cols(arma::uvec(colsToKeep));
55 }
56 else
57 {
58 for (size_t i = 0; i < input.n_rows; ++i)
59 {
60 if (!(input(i, dimension) == mappedValue ||
61 std::isnan(input(i, dimension))))
62 {
63 colsToKeep.push_back(i);
64 }
65 }
66 input = input.rows(arma::uvec(colsToKeep));
67 }
68 }
69}; // class ListwiseDeletion
70
71} // namespace data
72} // namespace mlpack
73
74#endif
A complete-case analysis to remove the values containing mappedValue.
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 remove the whole row or column...
Linear algebra utility functions, generally performed on matrices or vectors.
The core includes that mlpack expects; standard C++ includes and Armadillo.