예제 #1
0
class OrdinalEncoderImpl():
    def __init__(self, categories='auto', dtype=None):
        self._hyperparams = {'categories': categories, 'dtype': dtype}

    def fit(self, X, y=None):
        self._sklearn_model = SKLModel(**self._hyperparams)
        if (y is not None):
            self._sklearn_model.fit(X, y)
        else:
            self._sklearn_model.fit(X)
        return self

    def transform(self, X):
        return self._sklearn_model.transform(X)
예제 #2
0
class NanOrdinalEncoder(_BaseEncoder):
    def __init__(self):
        self.lbe = OrdinalEncoder()

    def fit(self, X):
        self.lbe.fit(X)
        return self

    def transform(self, X):
        result = self.lbe.transform(X)
        for col in range(result.shape[1]):
            nan_idx = list(self.lbe.categories_[col]).index(nan_replace)
            column = result[:, col]
            column[column == nan_idx] = np.nan
        return result