latools/filtering/classifier_obj.py
def format_data(self, data, scale=True):
        """
        Function for converting a dict to an array suitable for sklearn.

        Parameters
        ----------
        data : dict
            A dict of data, containing all elements of
            `analytes` as items.
        scale : bool
            Whether or not to scale the data. Should always be
            `True`, unless used by `classifier.fitting_data`
            where a scaler hasn't been created yet.

        Returns
        -------
        A data array suitable for use with `sklearn.cluster`.
        """
        if len(self.analytes) == 1:
            # if single analyte
            d = nominal_values(data[self.analytes[0]])
            ds = np.array(list(zip(d, np.zeros(len(d)))))
        else:
            # package multiple analytes
            d = [nominal_values(data[a]) for a in self.analytes]
            ds = np.vstack(d).T

        # identify all nan values
        finite = np.isfinite(ds).sum(1) == ds.shape[1]
        # remember which values are sampled
        sampled = np.arange(data[self.analytes[0]].size)[finite]
        # remove all nan values
        ds = ds[finite]

        if scale:
            ds = self.scaler.transform(ds)

        return ds, sampled
def format_data(self, data, scale=True):
        if len(self.analytes) == 1:
            # if single analyte
            d = nominal_values(data[self.analytes[0]])
            ds = np.array(list(zip(d, np.zeros(len(d)))))
        else:
            # package multiple analytes
            d = [nominal_values(data[a]) for a in self.analytes]
            ds = np.vstack(d).T

        # identify all nan values
        finite = np.isfinite(ds).sum(1) == ds.shape[1]
        # remember which values are sampled
        sampled = np.arange(data[self.analytes[0]].size)[finite]
        # remove all nan values
        ds = ds[finite]

        if scale:
            ds = self.scaler.transform(ds)

        return ds, sampled
def format_data ( self , data , scale = True ) : if len ( self . analytes ) == 1 : # if single analyte d = nominal_values ( data [ self . analytes [ 0 ] ] ) ds = np . array ( list ( zip ( d , np . zeros ( len ( d ) ) ) ) ) else : # package multiple analytes d = [ nominal_values ( data [ a ] ) for a in self . analytes ] ds = np . vstack ( d ) . T # identify all nan values finite = np . isfinite ( ds ) . sum ( 1 ) == ds . shape [ 1 ] # remember which values are sampled sampled = np . arange ( data [ self . analytes [ 0 ] ] . size ) [ finite ] # remove all nan values ds = ds [ finite ] if scale : ds = self . scaler . transform ( ds ) return ds , sampled
Function for converting a dict to an array suitable for sklearn.

        Parameters
        ----------
        data : dict
            A dict of data, containing all elements of
            `analytes` as items.
        scale : bool
            Whether or not to scale the data. Should always be
            `True`, unless used by `classifier.fitting_data`
            where a scaler hasn't been created yet.

        Returns
        -------
        A data array suitable for use with `sklearn.cluster`.
Function for converting a dict to an array suitable for sklearn .