You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
"""Example of Logistic regression using scikit-learnhttps://scikit-learn.org/stable/auto_examples/linear_model/plot_iris_logistic.html"""importmatplotlib.pyplotaspltimportnumpyasnpfromsklearnimportdatasetsfromsklearn.inspectionimportDecisionBoundaryDisplayfromsklearn.linear_modelimportLogisticRegressiondefload_data():
# import some data to play withiris=datasets.load_iris()
X=iris.data[:, :2] # we only take the first two features.Y=iris.targetreturnX, Ydefmodel_fit(X: np.ndarray, Y: np.ndarray, C: float=1e5):
logreg=LogisticRegression(C=C)
logreg.fit(X, Y)
returnlogregdefgenerate_plots(X: np.ndarray, Y: np.ndarray, logreg: LogisticRegression):
_, ax=plt.subplots(figsize=(4, 3))
DecisionBoundaryDisplay.from_estimator(
logreg,
X,
cmap=plt.cm.Paired,
ax=ax,
response_method="predict",
plot_method="pcolormesh",
shading="auto",
xlabel="Sepal length",
ylabel="Sepal width",
eps=0.5,
)
# Plot also the training pointsplt.scatter(X[:, 0], X[:, 1], c=Y, edgecolors="k", cmap=plt.cm.Paired)
plt.xticks(())
plt.yticks(())
plt.savefig("iris_logistic.png")
# TODO: What is the right value?return0.6## Without any orchestrationdefmain():
X, Y=load_data()
logreg=model_fit(X, Y, C=1.0)
generate_plots(X, Y, logreg)
## With runnable orchestrationdefrunnable_pipeline():
# The below code can be anywherefromrunnableimportCatalog, Pipeline, PythonTask, metric, pickled# X, Y = load_data()load_data_task=PythonTask(
function=load_data,
name="load_data",
returns=[pickled("X"), pickled("Y")], # (1)
)
# logreg = model_fit(X, Y, C=1.0)model_fit_task=PythonTask(
function=model_fit,
name="model_fit",
returns=[pickled("logreg")],
)
# generate_plots(X, Y, logreg)generate_plots_task=PythonTask(
function=generate_plots,
name="generate_plots",
terminate_with_success=True,
catalog=Catalog(put=["iris_logistic.png"]), # (2)returns=[metric("score")],
)
pipeline=Pipeline(
steps=[load_data_task, model_fit_task, generate_plots_task],
) # (4)pipeline.execute()
returnpipelineif__name__=="__main__":
# main()runnable_pipeline()
Return two serialized objects X and Y.
Store the file iris_logistic.png for future reference.
Define the sequence of tasks.
Define a pipeline with the tasks
The difference between native driver and runnable orchestration:
!!! tip inline end "Notebooks and Shell scripts"
You can execute notebooks and shell scripts too!!
They can be written just as you would want them, *plain old notebooks and scripts*.