def test_higher_order_2(self): self.maxDiff = None from lale.lib.sklearn import VotingClassifier as Vote from lale.lib.sklearn import KNeighborsClassifier as KNN from lale.lib.sklearn import PCA from lale.lib.sklearn import LogisticRegression as LR from lale.json_operator import from_json operator = Vote(estimators=[('knn',KNN), ('pipeline',PCA()>>LR)], voting='soft') json_expected = { 'class': 'lale.lib.sklearn.voting_classifier.VotingClassifierImpl', 'state': 'trainable', 'operator': 'VotingClassifier', 'is_frozen_trainable': True, 'label': 'Vote', 'documentation_url': 'https://lale.readthedocs.io/en/latest/modules/lale.lib.sklearn.voting_classifier.html', 'hyperparams': { 'estimators': [ ('knn', {'$ref': '../steps/knn'}), ('pipeline', {'$ref': '../steps/pipeline'})], 'voting': 'soft'}, 'steps': { 'knn': { 'class': 'lale.lib.sklearn.k_neighbors_classifier.KNeighborsClassifierImpl', 'state': 'planned', 'operator': 'KNeighborsClassifier', 'label': 'KNN', 'documentation_url': 'https://lale.readthedocs.io/en/latest/modules/lale.lib.sklearn.k_neighbors_classifier.html'}, 'pipeline': { 'class': 'lale.operators.PlannedPipeline', 'state': 'planned', 'edges': [['pca', 'lr']], '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': {}, 'is_frozen_trainable': False}, 'lr': { 'class': 'lale.lib.sklearn.logistic_regression.LogisticRegressionImpl', 'state': 'planned', 'operator': 'LogisticRegression', 'label': 'LR', 'documentation_url': 'https://lale.readthedocs.io/en/latest/modules/lale.lib.sklearn.logistic_regression.html'}}}}} 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_2(self): from lale.lib.sklearn import VotingClassifier as Vote from lale.lib.sklearn import KNeighborsClassifier as KNN from lale.lib.sklearn import PCA from lale.lib.sklearn import LogisticRegression as LR pipeline = Vote(estimators=[('knn', KNN), ('pipeline', PCA() >> LR)], voting='soft') expected = """from lale.lib.sklearn import VotingClassifier as Vote from lale.lib.sklearn import KNeighborsClassifier as KNN from lale.lib.sklearn import PCA from lale.lib.sklearn import LogisticRegression as LR import lale lale.wrap_imported_operators() pipeline = Vote(estimators=[('knn', KNN), ('pipeline', PCA() >> LR)], voting='soft')""" self._roundtrip(expected, lale.pretty_print.to_string(pipeline))
def test_higher_order_2(self): from lale.lib.sklearn import PCA from lale.lib.sklearn import KNeighborsClassifier as KNN from lale.lib.sklearn import LogisticRegression as LR from lale.lib.sklearn import VotingClassifier as Vote pipeline = Vote(estimators=[("knn", KNN), ("pipeline", PCA() >> LR)], voting="soft") expected = """from sklearn.ensemble import VotingClassifier as Vote from sklearn.neighbors import KNeighborsClassifier as KNN from sklearn.decomposition import PCA from sklearn.linear_model import LogisticRegression as LR import lale lale.wrap_imported_operators() pipeline = Vote( estimators=[("knn", KNN), ("pipeline", PCA() >> LR)], voting="soft" )""" self._roundtrip(expected, lale.pretty_print.to_string(pipeline))
def test_higher_order_2(self): self.maxDiff = None from lale.json_operator import from_json from lale.lib.sklearn import PCA from lale.lib.sklearn import KNeighborsClassifier as KNN from lale.lib.sklearn import LogisticRegression as LR from lale.lib.sklearn import VotingClassifier as Vote operator = Vote( estimators=[("knn", KNN), ("pipeline", PCA() >> LR)], voting="soft" ) json_expected = { "class": Vote.class_name(), "state": "trainable", "operator": "VotingClassifier", "is_frozen_trainable": True, "label": "Vote", "documentation_url": "https://lale.readthedocs.io/en/latest/modules/lale.lib.sklearn.voting_classifier.html", "hyperparams": { "estimators": [ ("knn", {"$ref": "../steps/knn"}), ("pipeline", {"$ref": "../steps/pipeline"}), ], "voting": "soft", }, "steps": { "knn": { "class": KNN.class_name(), "state": "planned", "operator": "KNeighborsClassifier", "label": "KNN", "documentation_url": "https://lale.readthedocs.io/en/latest/modules/lale.lib.sklearn.k_neighbors_classifier.html", }, "pipeline": { "class": "lale.operators.PlannedPipeline", "state": "planned", "edges": [["pca", "lr"]], "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": {}, "is_frozen_trainable": False, }, "lr": { "class": LR.class_name(), "state": "planned", "operator": "LogisticRegression", "label": "LR", "documentation_url": "https://lale.readthedocs.io/en/latest/modules/lale.lib.sklearn.logistic_regression.html", }, }, }, }, } 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)