def __init__(self, wrapped_node, in_args_transform=None): if not hasattr(wrapped_node, "transform"): raise ValueError("wrapped_node should implement transform") super(TransformNode, self).__init__(wrapped_node=wrapped_node) self.in_args_transform = \ _func_get_args_names(self.wrapped_node.transform) \ if in_args_transform is None else in_args_transform
def __init__(self, wrapped_node, in_args_fit=None, in_args_transform=None, in_args_predict=None, out_args_predict=None): is_fit_estimator = False if hasattr(wrapped_node, "fit") and hasattr(wrapped_node, "transform"): is_fit_estimator = True elif hasattr(wrapped_node, "fit") and hasattr(wrapped_node, "predict"): is_fit_estimator = True if not is_fit_estimator: raise ValueError("%s should implement fit and transform or fit " "and predict" % wrapped_node.__class__.__name__) super(Estimator, self).__init__(wrapped_node=wrapped_node) if in_args_fit: self.in_args_fit = in_args_fit else: self.in_args_fit = _func_get_args_names(self.wrapped_node.fit) # Internal Estimator if hasattr(wrapped_node, "transform"): if in_args_transform: self.in_args_transform = in_args_transform else: self.in_args_transform = \ _func_get_args_names(self.wrapped_node.transform) # Leaf Estimator if hasattr(wrapped_node, "predict"): if in_args_predict: self.in_args_predict = in_args_predict else: self.in_args_predict = \ _func_get_args_names(self.wrapped_node.predict) if out_args_predict is None: fit_predict_diff = list(set(self.in_args_fit).difference( self.in_args_predict)) if len(fit_predict_diff) > 0: self.out_args_predict = fit_predict_diff else: self.out_args_predict = self.in_args_predict else: self.out_args_predict = out_args_predict
def __init__(self, estimator, in_args_fit=None, in_args_predict=None, out_args_predict=None): ''' Parameters ---------- estimator: any class contains fit and predict functions any class implements fit and predict in_args_fit: list of strings names of input arguments of the fit method. If missing discover discover it automatically. in_args_predict: list of strings names of input arguments of the predict method. If missing, discover it automatically. out_args_predict: list of strings names of output arguments of the predict method. If missing, discover it automatically by self.in_args_fit - in_args_predict. If not differences (such with PCA with fit(X) and predict(X)) use in_args_predict. ''' if not hasattr(estimator, "fit") or not \ hasattr(estimator, "predict"): raise ValueError("estimator should implement fit and predict") super(LeafEstimator, self).__init__(estimator=estimator) self.in_args_fit = _func_get_args_names(self.estimator.fit) \ if in_args_fit is None else in_args_fit self.in_args_predict = _func_get_args_names(self.estimator.predict) \ if in_args_predict is None else in_args_predict if out_args_predict is None: fit_predict_diff = list(set(self.in_args_fit).difference( self.in_args_predict)) if len(fit_predict_diff) > 0: self.out_args_predict = fit_predict_diff else: self.out_args_predict = self.in_args_predict else: self.out_args_predict = out_args_predict
def __init__(self, estimator, in_args_fit=None, in_args_transform=None): """ Parameters ---------- estimator: any class contains fit and transform functions any class implements fit and transform in_args_fit: list of strings names of input arguments of the fit method. If missing discover discover it automatically. in_args_transform: list of strings names of input arguments of the tranform method. If missing, discover it automatically. """ if not hasattr(estimator, "fit") or not \ hasattr(estimator, "transform"): raise ValueError("estimator should implement fit and transform") super(InternalEstimator, self).__init__(estimator=estimator) self.in_args_fit = _func_get_args_names(self.estimator.fit) \ if in_args_fit is None else in_args_fit self.in_args_transform = \ _func_get_args_names(self.estimator.transform) \ if in_args_transform is None else in_args_transform