12 #ifndef MLPACK_METHODS_CF_NORMALIZATION_Z_SCORE_NORMALIZATION_HPP 13 #define MLPACK_METHODS_CF_NORMALIZATION_Z_SCORE_NORMALIZATION_HPP 51 mean = arma::mean(data.row(2));
52 stddev = arma::stddev(data.row(2));
54 if (std::fabs(stddev) < 1e-14)
56 Log::Fatal <<
"Standard deviation of all existing ratings is 0! " 57 <<
"This may indicate that all existing ratings are the same." 61 data.row(2) = (data.row(2) - mean) / stddev;
64 data.row(2).for_each([](
double& x)
67 x = std::numeric_limits<float>::min();
79 arma::vec ratings = arma::nonzeros(cleanedData);
80 mean = arma::mean(ratings);
81 stddev = arma::stddev(ratings);
83 if (std::fabs(stddev) < 1e-14)
85 Log::Fatal <<
"Standard deviation of all existing ratings is 0! " 86 <<
"This may indicate that all existing ratings are the same." 93 arma::sp_mat::iterator it = cleanedData.begin();
94 arma::sp_mat::iterator it_end = cleanedData.end();
95 for (; it != it_end; ++it)
97 double tmp = (*it - mean) / stddev;
102 tmp = std::numeric_limits<float>::min();
117 const double rating)
const 119 return rating * stddev + mean;
129 arma::vec& predictions)
const 131 predictions = predictions * stddev + mean;
153 template<
typename Archive>
156 ar(CEREAL_NVP(mean));
157 ar(CEREAL_NVP(stddev));
static MLPACK_EXPORT util::PrefixedOutStream Fatal
Prints fatal messages prefixed with [FATAL], then terminates the program.
Definition: log.hpp:90
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: cv.hpp:1
double Denormalize(const size_t, const size_t, const double rating) const
Denormalize computed rating by adding mean and multiplying stddev.
Definition: z_score_normalization.hpp:115
void Normalize(arma::sp_mat &cleanedData)
Normalize the data to zero mean and one standard deviation.
Definition: z_score_normalization.hpp:76
void Normalize(arma::mat &data)
Normalize the data to zero mean and one standard deviation.
Definition: z_score_normalization.hpp:49
The core includes that mlpack expects; standard C++ includes and Armadillo.
void serialize(Archive &ar, const uint32_t)
Serialization.
Definition: z_score_normalization.hpp:154
double Mean() const
Return mean.
Definition: z_score_normalization.hpp:137
This normalization class performs z-score normalization on raw ratings.
Definition: z_score_normalization.hpp:38
void Denormalize(const arma::Mat< size_t > &, arma::vec &predictions) const
Denormalize computed rating by adding mean and multiplying stddev.
Definition: z_score_normalization.hpp:128
double Stddev() const
Return stddev.
Definition: z_score_normalization.hpp:145