pub fn to_class(
        &self,
        som: &Som,
        data: &DataFrame,
        layer_index: usize,
    ) -> Result<(String, Vec<String>), DataTypeError> {
        if !self.input_layers[layer_index].is_class {
            return Err(DataTypeError(format!(
                "Classes can be derived only for categorical layers, but layer {} is not.",
                layer_index
            )));
        }
        let layer = &self.layers[layer_index];
        let start_col = som.params().start_columns()[layer_index];

        let classes: Vec<_> = som.weights().columns()[start_col..(start_col + layer.ncols())]
            .iter()
            .map(|n| n.splitn(2, ':').nth(1).unwrap())
            .collect();
        let name = self.data.columns()[start_col]
            .splitn(2, ':')
            .next()
            .unwrap();

        let no_data = &self.csv_options.no_data;
        let result: Vec<_> = data
            .iter_rows()
            .map(|row| {
                let mut v_max = std::f64::MIN;
                let mut idx_max = 0;
                let mut any = false;
                for (i, &v) in row.iter().enumerate().skip(start_col).take(layer.ncols()) {
                    if !v.is_nan() {
                        if v > v_max {
                            v_max = v;
                            idx_max = i;
                        }
                        any = true;
                    }
                }
                if any {
                    classes[idx_max - start_col].to_string()
                } else {
                    no_data.clone()
                }
            })
            .collect();

        Ok((name.to_string(), result))
    }
/// Transforms a categorical / class layer to a vector of class labels.
///
/// Returns an error if the layer is not categorical.
Transforms a categorical / class layer to a vector of class labels.
Returns an error if the layer is not categorical.
Transforms a categorical / class layer to a vector of class labels . Returns an error if the layer is not categorical .
pub fn to_class(
        &self,
        som: &Som,
        data: &DataFrame,
        layer_index: usize,
    ) -> Result<(String, Vec<String>), DataTypeError> {
        if !self.input_layers[layer_index].is_class {
            return Err(DataTypeError(format!(
                "Classes can be derived only for categorical layers, but layer {} is not.",
                layer_index
            )));
        }
        let layer = &self.layers[layer_index];
        let start_col = som.params().start_columns()[layer_index];
        let classes: Vec<_> = som.weights().columns()[start_col..(start_col + layer.ncols())]
            .iter()
            .map(|n| n.splitn(2, ':').nth(1).unwrap())
            .collect();
        let name = self.data.columns()[start_col]
            .splitn(2, ':')
            .next()
            .unwrap();
        let no_data = &self.csv_options.no_data;
        let result: Vec<_> = data
            .iter_rows()
            .map(|row| {
                let mut v_max = std::f64::MIN;
                let mut idx_max = 0;
                let mut any = false;
                for (i, &v) in row.iter().enumerate().skip(start_col).take(layer.ncols()) {
                    if !v.is_nan() {
                        if v > v_max {
                            v_max = v;
                            idx_max = i;
                        }
                        any = true;
                    }
                }
                if any {
                    classes[idx_max - start_col].to_string()
                } else {
                    no_data.clone()
                }
            })
            .collect();
        Ok((name.to_string(), result))
    }
pub fn to_class ( & self , som : & Som , data : & DataFrame , layer_index : usize , ) -> Result < ( String , Vec < String > ) , DataTypeError > { if ! self . input_layers [ layer_index ] . is_class { return Err ( DataTypeError ( format ! ( " " layer_index ) ) ) ; } let layer = & self . layers [ layer_index ] ; let start_col = som . params ( ) . start_columns ( ) [ layer_index ] ; let classes : Vec < _ > = som . weights ( ) . columns ( ) [ start_col .. ( start_col + layer . ncols ( ) ) ] . iter ( ) . map ( | n | n . splitn ( 2 , ':' ) . nth ( 1 ) . unwrap ( ) ) . collect ( ) ; let name = self . data . columns ( ) [ start_col ] . splitn ( 2 , ':' ) . next ( ) . unwrap ( ) ; let no_data = & self . csv_options . no_data ; let result : Vec < _ > = data . iter_rows ( ) . map ( | row | { let mut v_max = std :: f64 :: MIN ; let mut idx_max = 0 ; let mut any = false ; for ( i , & v ) in row . iter ( ) . enumerate ( ) . skip ( start_col ) . take ( layer . ncols ( ) ) { if ! v . is_nan ( ) { if v > v_max { v_max = v ; idx_max = i ; } any = true ; } } if any { classes [ idx_max - start_col ] . to_string ( ) } else { no_data . clone ( ) } } ) . collect ( ) ; Ok ( ( name . to_string ( ) , result ) ) }
Transforms a categorical / class layer to a vector of class labels.
Transforms a categorical / class layer to a vector of class labels .
&self
som
&Som
data
&DataFrame
layer_index
usize
&self
som
&Som
data
&DataFrame
layer_index
usize