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 & BOOST_SERIALIZATION_NVP(mean);
157 ar & BOOST_SERIALIZATION_NVP(stddev);