-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GH-15855: core pipeline API #16039
GH-15855: core pipeline API #16039
Changes from all commits
c73bdc0
0f2664b
1c5239a
cd15cc9
0689c31
9ca6a30
bd48176
196299c
1f0dd43
78db7a6
f3d717d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
|
||
extensions = dict( | ||
required_params=[], | ||
frame_params=[], | ||
validate_required_params="", | ||
set_required_params="", | ||
module=""" | ||
.h2o.fill_pipeline <- function(model, parameters, allparams) { | ||
if (!is.null(model$estimator)) { | ||
model$estimator_model <- h2o.getModel(model$estimator$name) | ||
} else { | ||
model$estimator_model <- NULL | ||
} | ||
model$transformers <- unlist(lapply(model$transformers, function(dt) new("H2ODataTransformer", id=dt$id, description=dt$description))) | ||
# class(model) <- "H2OPipeline" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this commented? If needed, you can assign multiple classes, e.g., There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good point! right I forgot about the multiple inheritance. I think I commented it out because it didn't seem necessary (single algo don't have dedicated class) and it broke some behaviour somewhere (can't remember what exactly). setClass("H2OPipeline", contains="H2OModel", but afair, it was still not recognized as a model somewhere… |
||
return(model) | ||
} | ||
""" | ||
) | ||
|
||
doc = dict( | ||
preamble=""" | ||
Build a pipeline model given a list of transformers and a final model. | ||
|
||
Currently R model pipelines, as produced by AutoML for example, | ||
are only available as read-only models that can not be constructed and trained directly by the end-user. | ||
""", | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
supervised_learning = None # actually depends on the estimator model in the pipeline, leave it to None for now as it is needed only for training and we don't support pipeline as input yet | ||
|
||
|
||
# in future update, we'll want to expose parameters applied to each transformer | ||
def module_extensions(): | ||
class H2ODataTransformer(H2ODisplay): | ||
@classmethod | ||
def make(cls, kvs): | ||
dt = H2ODataTransformer(**{k: v for k, v in kvs if k not in H2OSchema._ignored_schema_keys_}) | ||
dt._json = kvs | ||
return dt | ||
|
||
def __init__(self, id=None, description=None): | ||
self._json = None | ||
self.id = id | ||
self.description = description | ||
|
||
def _repr_(self): | ||
return repr(self._json) | ||
|
||
def _str_(self, verbosity=None): | ||
return repr_def(self) | ||
|
||
|
||
# self-register transformer class: done as soon as `h2o.estimators` is loaded, which means as soon as h2o.h2o is... | ||
register_schema_handler("DataTransformerV3", H2ODataTransformer) | ||
|
||
|
||
def class_extensions(): | ||
@property | ||
def transformers(self): | ||
return self._model_json['output']['transformers'] | ||
|
||
@property | ||
def estimator_model(self): | ||
m_json = self._model_json['output']['estimator'] | ||
return None if (m_json is None or m_json['name'] is None) else h2o.get_model(m_json['name']) | ||
|
||
def transform(self, fr): | ||
""" | ||
Applies all the pipeline transformers to the given input frame. | ||
:return: the transformed frame, as it would be passed to `estimator_model`, if calling `predict` instead. | ||
""" | ||
return H2OFrame._expr(expr=ExprNode("transform", ASTId(self.key), ASTId(fr.key)))._frame(fill_cache=True) | ||
|
||
|
||
extensions = dict( | ||
__imports__=""" | ||
import h2o | ||
from h2o.display import H2ODisplay, repr_def | ||
from h2o.expr import ASTId, ExprNode | ||
from h2o.schemas import H2OSchema, register_schema_handler | ||
""", | ||
__class__=class_extensions, | ||
__module__=module_extensions, | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changes in the algos are mainly due to the fact that the CV API now only exposes
protected
hooks at various places in the model building cycle, otherwise it breaks the pipeline logic that needs a very strict behaviour when building CV models (esp. as it needs full control over the frames being used at that time).Algos are therefore encouraged to override only those small hooks, and the ModelBuilder itself remains algo-agnostic.