|
Cosan
1.0
Data Analytics Library
|
Go to the documentation of this file. 1 #ifndef COSAN_STANDARDSCALER_H
2 #define COSAN_STANDARDSCALER_H
10 template<Numeric NumericType>
29 fmt::print(
"*********************************\n");
30 fmt::print(
"Begin standardizing data \n");
31 this->
mean = X.colwise().mean();
32 this->
std = ((X.rowwise() - this->
mean).array().pow(2).colwise().sum() / X.rows()).sqrt();
33 if ((this->
std.array()==0).any()==
true){
34 std::cout<<
"Error!"<<std::endl;
35 for (gsl::index idx = 0;idx<this->
std.size();idx++ ){
36 if (this->
std[idx]==0){
37 std::cout<<
"Column "<<idx<<
" has identical values!"<<std::endl;
40 throw std::invalid_argument(
41 "Check your column! Some column has identical values!"
45 fmt::print(
"End of standardizing data. One may transform or reverse-transform by .transform(),.InvTransform() function. \n");
46 fmt::print(
"*********************************\n");
49 return (X.rowwise() - this->mean).array().rowwise() / this->
std.array();
53 return (X.array().rowwise()*(this->std.array())).array().rowwise()+this->
mean.array();
60 #endif //COSAN_STANDARDSCALER_H
CosanMatrix< NumericType > GetInput()
Get a copy of CosanMatrix<NumericType> X.
StandardScaler(CosanRawData< NumericType > &RD)
CosanRowVector< NumericType > GetStd() const
void UpdateData(const CosanMatrix< NumericType > &inputX)
Update X using CosanMatrix<NumericType> input X.
Eigen::Matrix< NumericType, Eigen::Dynamic, Eigen::Dynamic > CosanMatrix
void fit(CosanRawData< NumericType > &RD)
CosanRowVector< NumericType > mean
CosanRowVector< NumericType > GetMean() const
CosanMatrix< NumericType > transform(const CosanMatrix< NumericType > &X) override
Eigen::Matrix< NumericType, 1, Eigen::Dynamic > CosanRowVector
CosanRowVector< NumericType > std
void fit(const CosanMatrix< NumericType > &X) override
CosanMatrix< NumericType > InvTransform(const CosanMatrix< NumericType > &X)