-
Notifications
You must be signed in to change notification settings - Fork 91
Expand file tree
/
Copy pathcount_missing_values_transformer.py
More file actions
32 lines (22 loc) · 1.02 KB
/
count_missing_values_transformer.py
File metadata and controls
32 lines (22 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
"""Count of missing values per row"""
from h2oaicore.transformer_utils import CustomTransformer
import datatable as dt
import numpy as np
class CountMissingPerRowTransformer(CustomTransformer):
_unsupervised = True
_testing_can_skip_failure = False # ensure tested as if shouldn't fail
@staticmethod
def get_default_properties():
return dict(col_type="all", min_cols="all", max_cols="all", relative_importance=1)
def fit_transform(self, X: dt.Frame, y: np.array = None):
return self.transform(X)
def transform(self, X: dt.Frame):
if X.ncols == 0:
return np.zeros((X.nrows, 1))
return X[:, dt.sum([dt.isna(dt.f[x]) for x in range(X.ncols)])]
class CountMissingNumericsPerRowTransformer(CountMissingPerRowTransformer):
def transform(self, X: dt.Frame):
return super().transform(X[:, [int, float]])
class CountMissingStringsPerRowTransformer(CountMissingPerRowTransformer):
def transform(self, X: dt.Frame):
return super().transform(X[:, [str]])