Scaffold for turniing floats to hashable and fittinng to columns

This commit is contained in:
gaxler
2021-01-27 19:36:38 -08:00
parent 408b97d8aa
commit 5c400f40d2
+27
View File
@@ -0,0 +1,27 @@
#![allow(clippy::ptr_arg)]
//! # Encode categorical features as a one-hot numeric array.
use crate::error::Failed;
use crate::linalg::{BaseVector, Matrix};
use crate::math::num::RealNumber;
use crate::preprocessing::series_encoder::SeriesOneHotEncoder;
pub type HashableReal = u32;
fn hashable_num<T: RealNumber>(v: &T) -> HashableReal {
// gaxler: If first 32 bits are the same, assume numbers are the same for the categorical coercion
v.to_f32_bits()
}
#[derive(Debug, Clone)]
pub struct OneHotEncoderParams {
pub categorical_param_idxs: Option<Vec<usize>>,
pub infer_categorical: bool,
}
/// Encode Categorical variavbles of data matrix to one-hot
pub struct OneHotEncoder {
series_encoders: Vec<SeriesOneHotEncoder<HashableReal>>,
categorical_param_idxs: Vec<usize>,
}