Implementation of Standard scaler (#143)

* docs: Fix typo in doc for categorical transformer.
* feat: Add option to take a column from Matrix.
I created the method `Matrix::take_column` that uses the `Matrix::take`-interface to extract a single column from a matrix. I need that feature in the implementation of  `StandardScaler`.
* feat: Add `StandardScaler`.
Authored-by: titoeb <timtoebrock@googlemail.com>
This commit is contained in:
Tim Toebrock
2022-08-26 16:20:20 +02:00
committed by GitHub
parent 3d2f4f71fa
commit d305406dfd
3 changed files with 428 additions and 1 deletions
+21
View File
@@ -651,6 +651,10 @@ pub trait BaseMatrix<T: RealNumber>: Clone + Debug {
result
}
/// Take an individual column from the matrix.
fn take_column(&self, column_index: usize) -> Self {
self.take(&[column_index], 1)
}
}
/// Generic matrix with additional mixins like various factorization methods.
@@ -761,4 +765,21 @@ mod tests {
assert_eq!(m.take(&vec!(1, 1, 3), 0), expected_0);
assert_eq!(m.take(&vec!(1, 0), 1), expected_1);
}
#[test]
fn take_second_column_from_matrix() {
let four_columns: DenseMatrix<f64> = DenseMatrix::from_2d_array(&[
&[0.0, 1.0, 2.0, 3.0],
&[0.0, 1.0, 2.0, 3.0],
&[0.0, 1.0, 2.0, 3.0],
&[0.0, 1.0, 2.0, 3.0],
]);
let second_column = four_columns.take_column(1);
assert_eq!(
second_column,
DenseMatrix::from_2d_array(&[&[1.0], &[1.0], &[1.0], &[1.0]]),
"The second column was not extracted correctly"
);
}
}