-
Notifications
You must be signed in to change notification settings - Fork 93
/
dummy-pretransformer.py
57 lines (46 loc) · 2.01 KB
/
dummy-pretransformer.py
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
"""Dummy Pre-Transformer to use as a template for custom pre-transformer recipes.
This transformer consumes all features at once, adds 'pre:' to the names and passes
them down to transformer level and GA as-is."""
from h2oaicore.transformer_utils import CustomTransformer
import datatable as dt
import numpy as np
import pandas as pd
from sklearn.preprocessing import LabelEncoder
import os
import uuid
from h2oaicore.systemutils import temporary_files_path, config, remove
from h2o.estimators.coxph import H2OCoxProportionalHazardsEstimator
from h2oaicore.systemutils import make_experiment_logger, loggerinfo, loggerwarning
from h2oaicore.separators import extra_prefix, orig_feat_prefix
class DummyIdentityPreTransformer(CustomTransformer):
_unsupervised = True
# only works with binomial problem for now
_regression = True
_binary = True
_multiclass = True
_numeric_output = False
_can_be_pretransformer = True
_default_as_pretransformer = True
_must_be_pretransformer = True
_only_as_pretransformer = True
def __init__(self, context=None, **kwargs):
super().__init__(context=context, **kwargs)
@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, **kwargs):
X_original = X
# Get the logger if it exists
logger = None
if self.context and self.context.experiment_id:
logger = make_experiment_logger(
experiment_id=self.context.experiment_id,
tmp_dir=self.context.tmp_dir,
experiment_tmp_dir=self.context.experiment_tmp_dir,
username=self.context.username,
)
self._output_feature_names = ["pre:" + x for x in list(X_original.names)]
self._feature_desc = ["Pre-transformed feature " + x for x in list(X_original.names)]
return X_original
def transform(self, X: dt.Frame):
return X