Beispiel #1
0
    def fit_transform(self, X, y=None):
        res = _transform_selected(X, self._fit_transform, self.categorical_features, copy=True)
        if self.drop_last:
            res = res[:,:-1]

        if self.sparse:
            return res.todense()
        return res
    def transform(self, X):
        """Discretizes the data.

        Parameters
        ----------
        X : numeric array-like, shape (n_samples, n_features)
            Data to be discretized.

        Returns
        -------
        Xt : numeric array-like, shape (n_samples, n_features)
            Data in the binned space.
        """
        X = self._check_X_post_fit(X)

        return _transform_selected(X,
                                   self._transform,
                                   self.transformed_features_,
                                   copy=True,
                                   retain_order=True)
Beispiel #3
0
def _check_transform_selected(X, X_expected, sel):
    for M in (X, sparse.csr_matrix(X)):
        Xtr = _transform_selected(M, Binarizer().transform, sel)
        assert_array_equal(toarray(Xtr), X_expected)
def _check_transform_selected(X, X_expected, sel):
    for M in (X, sparse.csr_matrix(X)):
        Xtr = _transform_selected(M, Binarizer().transform, sel)
        assert_array_equal(toarray(Xtr), X_expected)