Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ImageSpec to wine classification example #48

Merged
merged 4 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.idea
.venv
.DS_Store
26 changes: 0 additions & 26 deletions wine-classification/{{cookiecutter.project_name}}/Dockerfile

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pandas
scikit-learn
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
unionai
flytekitplugins-envd
-r image-requirements.txt

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,26 @@

from sklearn.datasets import load_wine
from sklearn.linear_model import LogisticRegression
from flytekit import task, workflow
from flytekit import ImageSpec, task, workflow

@task
image_spec = ImageSpec(
registry="ghcr.io/<my-github-org>",
name="wine-classification-image",
base_image="ghcr.io/flyteorg/flytekit:py3.11-latest",
requirements="image-requirements.txt"
)

@task(container_image=image_spec)
def get_data() -> pd.DataFrame:
"""Get the wine dataset."""
return load_wine(as_frame=True).frame

@task
@task(container_image=image_spec)
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
@task(container_image=image_spec)
def train_model(data: pd.DataFrame, hyperparameters: dict) -> LogisticRegression:
"""Train a model on the wine dataset."""
features = data.drop("target", axis="columns")
Expand All @@ -30,6 +37,3 @@ def training_workflow(hyperparameters: dict = {"C": 0.1}) -> LogisticRegression:
data=processed_data,
hyperparameters=hyperparameters,
)

if __name__ == "__main__":
training_workflow(hyperparameters={"C": 0.1})