def test_higher_order_1(self): from lale.lib.lale import Both from lale.lib.sklearn import PCA, Nystroem from lale.json_operator import from_json operator = Both(op1=PCA(n_components=2), op2=Nystroem) json_expected = { 'class': 'lale.lib.lale.both.BothImpl', 'state': 'trainable', 'operator': 'Both', 'label': 'Both', 'documentation_url': 'https://lale.readthedocs.io/en/latest/modules/lale.lib.lale.both.html', 'hyperparams': { 'op1': {'$ref': '../steps/pca'}, 'op2': {'$ref': '../steps/nystroem'}}, 'steps': { 'pca': { 'class': 'lale.lib.sklearn.pca.PCAImpl', 'state': 'trainable', 'operator': 'PCA', 'label': 'PCA', 'documentation_url': 'https://lale.readthedocs.io/en/latest/modules/lale.lib.sklearn.pca.html', 'hyperparams': {'n_components': 2}, 'is_frozen_trainable': False}, 'nystroem': { 'class': 'lale.lib.sklearn.nystroem.NystroemImpl', 'state': 'planned', 'operator': 'Nystroem', 'label': 'Nystroem', 'documentation_url': 'https://lale.readthedocs.io/en/latest/modules/lale.lib.sklearn.nystroem.html'}}, 'is_frozen_trainable': False} json = operator.to_json() self.assertEqual(json, json_expected) operator_2 = from_json(json) json_2 = operator_2.to_json() self.assertEqual(json, json_2)
def test_init_fit_transform(self): import lale.datasets from lale.lib.lale import Both nmf = NMF() pca = PCA() trainable = Both(op1=nmf, op2=pca) (train_X, train_y), (test_X, test_y) = lale.datasets.digits_df() trained = trainable.fit(train_X, train_y) transformed = trained.transform(test_X)
def test_higher_order_1(self): from lale.json_operator import from_json from lale.lib.lale import Both from lale.lib.sklearn import PCA, Nystroem operator = Both(op1=PCA(n_components=2), op2=Nystroem) json_expected = { "class": Both.class_name(), "state": "trainable", "operator": "Both", "label": "Both", "documentation_url": "https://lale.readthedocs.io/en/latest/modules/lale.lib.lale.both.html", "hyperparams": { "op1": { "$ref": "../steps/pca" }, "op2": { "$ref": "../steps/nystroem" }, }, "steps": { "pca": { "class": PCA.class_name(), "state": "trainable", "operator": "PCA", "label": "PCA", "documentation_url": "https://lale.readthedocs.io/en/latest/modules/lale.lib.sklearn.pca.html", "hyperparams": { "n_components": 2 }, "is_frozen_trainable": False, }, "nystroem": { "class": Nystroem.class_name(), "state": "planned", "operator": "Nystroem", "label": "Nystroem", "documentation_url": "https://lale.readthedocs.io/en/latest/modules/lale.lib.sklearn.nystroem.html", }, }, "is_frozen_trainable": False, } json = operator.to_json() self.assertEqual(json, json_expected) operator_2 = from_json(json) json_2 = operator_2.to_json() self.assertEqual(json, json_2)
def test_higher_order(self): from lale.lib.lale import Both from lale.lib.sklearn import PCA, Nystroem pipeline = Both(op1=PCA(n_components=2), op2=Nystroem) expected = """from lale.lib.lale import Both from sklearn.decomposition import PCA from sklearn.kernel_approximation import Nystroem import lale lale.wrap_imported_operators() pca = PCA(n_components=2) pipeline = Both(op1=pca, op2=Nystroem)""" self._roundtrip(expected, lale.pretty_print.to_string(pipeline))