Nan Qin
03/07/2023, 5:16 PMimport pandas as pd
from sklearn.datasets import load_wine
from sklearn.linear_model import LogisticRegression
import flytekit.extras.sklearn
from flytekit import task, workflow
@task
def get_data() -> pd.DataFrame:
"""Get the wine dataset."""
return load_wine(as_frame=True).frame
@task
def process_data(data: pd.DataFrame) -> pd.DataFrame:
"""Simplify the task from a 3-class to a binary classification problem."""
return data.assign(target=lambda x: x["target"].where(x["target"] == 0, 1))
@task
def train_model(data: pd.DataFrame, hyperparameters: dict) -> LogisticRegression:
"""Train a model on the wine dataset."""
features = data.drop("target", axis="columns")
target = data["target"]
return LogisticRegression(max_iter=3000, **hyperparameters).fit(features, target)
@workflow
def training_workflow(hyperparameters: dict) -> LogisticRegression:
"""Put all of the steps together into a single workflow."""
data = get_data()
processed_data = process_data(data=data)
return train_model(
data=processed_data,
hyperparameters=hyperparameters,
)
Ketan (kumare3)
03/07/2023, 5:25 PMflytectl version
Nan Qin
03/07/2023, 5:27 PM(flyte) % flytectl version ~ protopias-mbp
INFO[0000] [0] Couldn't find a config file []. Relying on env vars and pflags.
{
"App": "flytectl",
"Build": "a6b856a",
"Version": "0.6.32",
"BuildTime": "2023-03-07 11:26:50.606778 -0600 CST m=+0.016443210"
}%
(flyte) % pip list | grep flyte ~/flytesnacks (master ⚡) protopias-mbp
flyteidl 1.3.9
flytekit 1.4.0
Ketan (kumare3)
03/07/2023, 5:40 PMjeev
03/07/2023, 5:49 PMNan Qin
03/07/2023, 5:55 PMpip install flytekit scikit-learn
brew install flyteorg/homebrew-tap/flytectl
flytectl demo start
export FLYTECTL_CONFIG=~/.flyte/config-sandbox.yaml
pyflyte run --remote example.py training_workflow \
--hyperparameters '{"C": 0.1}'
Ketan (kumare3)
03/07/2023, 5:55 PMjeev
03/07/2023, 5:56 PMKetan (kumare3)
03/07/2023, 5:58 PMjeev
03/07/2023, 5:58 PMYee
03/07/2023, 5:59 PMjeev
03/07/2023, 5:59 PMYee
03/07/2023, 5:59 PMKetan (kumare3)
03/07/2023, 5:59 PMYee
03/07/2023, 6:00 PMNan Qin
03/07/2023, 6:26 PM@Nan Qin can you confirm?yes 1.3.2 works
Eduardo Apolinario (eapolinario)
03/08/2023, 3:03 AMNan Qin
03/08/2023, 7:24 PM