from lale.lib.lale import ConcatFeatures as Concat
from lale.lib.lale import NoOp
from lale.lib.lale import Both
from lale.lib.sklearn import KNeighborsClassifier as KNN
from lale.lib.sklearn import LogisticRegression as LR
from lale.lib.sklearn import MinMaxScaler as Scaler
from lale.lib.sklearn import Nystroem
from lale.lib.sklearn import PCA
Symbol | Name | Description | Sklearn feature |
---|---|---|---|
>> | pipe | Feed to next | make_pipeline |
& | and | Run both | make_union , includes concat |
| | or | Choose one | (missing) |
scl = Scaler | NoOp
scl.visualize()
tfm = (PCA & Nystroem) >> Concat
tfm.visualize()
clf = KNN | LR
clf.visualize()
optimizable = scl >> tfm >> clf
optimizable.visualize()
optimizable.pretty_print(ipython_display=True, show_imports=False)
pipeline = (Scaler | NoOp) >> (PCA & Nystroem) >> Concat >> (KNN | LR)
optimizable.pretty_print(ipython_display='input')
# generated by pretty_print(ipython_display='input') from previous cell
from sklearn.preprocessing import MinMaxScaler as Scaler
from lale.lib.lale import NoOp
from sklearn.decomposition import PCA
from sklearn.kernel_approximation import Nystroem
from lale.lib.lale import ConcatFeatures as Concat
from sklearn.neighbors import KNeighborsClassifier as KNN
from sklearn.linear_model import LogisticRegression as LR
import lale
lale.wrap_imported_operators()
pipeline = (Scaler | NoOp) >> (PCA & Nystroem) >> Concat >> (KNN | LR)
from lale.operators import make_choice, make_pipeline, make_union
scl = make_choice(Scaler, NoOp)
scl.visualize()
tfm = make_union(PCA, Nystroem)
tfm.visualize()
clf = make_choice(KNN, LR)
clf.visualize()
optimizable = make_pipeline(scl, tfm, clf)
optimizable.visualize()
optimizable.pretty_print(ipython_display=True, show_imports=False, combinators=False)
choice_0 = make_choice(Scaler, NoOp)
union = make_union(PCA, Nystroem)
choice_1 = make_choice(KNN, LR)
pipeline = make_pipeline(choice_0, union, choice_1)
optimizable.pretty_print(ipython_display='input', combinators=False)
# generated by pretty_print(ipython_display='input') from previous cell
from sklearn.preprocessing import MinMaxScaler as Scaler
from lale.lib.lale import NoOp
from lale.operators import make_choice
from sklearn.decomposition import PCA
from sklearn.kernel_approximation import Nystroem
from lale.operators import make_union
from sklearn.neighbors import KNeighborsClassifier as KNN
from sklearn.linear_model import LogisticRegression as LR
from lale.operators import make_pipeline
choice_0 = make_choice(Scaler, NoOp)
union = make_union(PCA, Nystroem)
choice_1 = make_choice(KNN, LR)
pipeline = make_pipeline(choice_0, union, choice_1)
import lale
lale.wrap_imported_operators() #so combinators work
nested = PCA >> (LR(C=0.09) | NoOp >> LR(C=0.19))
nested.visualize()
nested.pretty_print(ipython_display=True, show_imports=False)
lr_0 = LR(C=0.09)
lr_1 = LR(C=0.19)
pipeline = PCA >> (lr_0 | NoOp >> lr_1)
from lale.pretty_print import ipython_display
ipython_display(nested.to_json())
{
"class": "lale.operators.PlannedPipeline",
"state": "planned",
"edges": [["pca", "choice"]],
"steps": {
"pca": {
"class": "lale.lib.sklearn.pca.PCAImpl",
"state": "planned",
"operator": "PCA",
"label": "PCA",
"documentation_url": "https://lale.readthedocs.io/en/latest/modules/lale.lib.sklearn.pca.html",
},
"choice": {
"class": "lale.operators.OperatorChoice",
"state": "planned",
"operator": "OperatorChoice",
"steps": {
"lr_0": {
"class": "lale.lib.sklearn.logistic_regression.LogisticRegressionImpl",
"state": "trainable",
"operator": "LogisticRegression",
"label": "LR",
"documentation_url": "https://lale.readthedocs.io/en/latest/modules/lale.lib.sklearn.logistic_regression.html",
"hyperparams": {"C": 0.09},
"is_frozen_trainable": false,
},
"pipeline_1": {
"class": "lale.operators.TrainablePipeline",
"state": "trainable",
"edges": [["no_op", "lr_1"]],
"steps": {
"no_op": {
"class": "lale.lib.lale.no_op.NoOpImpl",
"state": "trained",
"operator": "NoOp",
"label": "NoOp",
"documentation_url": "https://lale.readthedocs.io/en/latest/modules/lale.lib.lale.no_op.html",
"hyperparams": null,
"is_frozen_trainable": true,
"coefs": null,
"is_frozen_trained": true,
},
"lr_1": {
"class": "lale.lib.sklearn.logistic_regression.LogisticRegressionImpl",
"state": "trainable",
"operator": "LogisticRegression",
"label": "LR",
"documentation_url": "https://lale.readthedocs.io/en/latest/modules/lale.lib.sklearn.logistic_regression.html",
"hyperparams": {"C": 0.19},
"is_frozen_trainable": false,
},
},
},
},
},
},
}
higher_order = Both(op1=PCA(n_components=2), op2=Nystroem) >> (KNN | LR)
higher_order.visualize()
higher_order.pretty_print(ipython_display=True, show_imports=False)
pca = PCA(n_components=2)
both = Both(op1=pca, op2=Nystroem)
pipeline = both >> (KNN | LR)
ipython_display(higher_order.to_json())
{
"class": "lale.operators.PlannedPipeline",
"state": "planned",
"edges": [["both", "choice"]],
"steps": {
"both": {
"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,
},
"choice": {
"class": "lale.operators.OperatorChoice",
"state": "planned",
"operator": "OperatorChoice",
"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",
},
"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",
},
},
},
},
}
from lale.lib.sklearn import VotingClassifier as Vote
vote = Vote(estimators=[('knn',KNN), ('pipeline',PCA()>>LR)], voting='soft')
vote.visualize()
vote.pretty_print(ipython_display=True, show_imports=False)
pipeline = Vote(
estimators=[("knn", KNN), ("pipeline", PCA() >> LR)], voting="soft"
)