Ejemplo n.º 1
0
 def test_remove_row(self):
     data = Table("iris")
     with data.unlocked():
         data.X[0, 0] = np.nan
     pp_data = RemoveNaNRows()(data)
     self.assertEqual(len(pp_data), len(data) - 1)
     self.assertFalse(np.isnan(pp_data.X).any())
Ejemplo n.º 2
0
 def createinstance(params):
     params = dict(params)
     method = params.pop("method", ImputeEditor.Average)
     if method == ImputeEditor.NoImputation:
         return None
     elif method == ImputeEditor.Average:
         return preprocess.Impute()
     elif method == ImputeEditor.Model:
         return preprocess.Impute(method=preprocess.impute.Model())
     elif method == ImputeEditor.DropRows:
         return RemoveNaNRows()
     elif method == ImputeEditor.DropColumns:
         return preprocess.RemoveNaNColumns()
     else:
         method, defaults = ImputeEditor.Imputers[method]
         defaults = dict(defaults)
         defaults.update(params)
         return preprocess.Impute(method=method)
Ejemplo n.º 3
0
class LinearProjector(Projector):
    name = "Linear Projection"
    supports_sparse = False
    preprocessors = [RemoveNaNRows()]
    projection = DomainProjection

    def __init__(self, preprocessors=None):
        super().__init__(preprocessors=preprocessors)
        self.components_ = None

    def fit(self, X, Y=None):
        self.components_ = self.get_components(X, Y)
        return self.projection(self, self.domain)

    def get_components(self, X, Y):
        raise NotImplementedError

    def transform(self, X):
        return np.dot(X, self.components_.T)