Skip to content

Commit

Permalink
Add ImageSpec to wine classification example (#48)
Browse files Browse the repository at this point in the history
* Add imagespec

Signed-off-by: Peeter Piegaze <1153481+ppiegaze@users.noreply.github.com>

* change package flytekit to unionai

Signed-off-by: Peeter Piegaze <1153481+ppiegaze@users.noreply.github.com>

---------

Signed-off-by: Peeter Piegaze <1153481+ppiegaze@users.noreply.github.com>
  • Loading branch information
ppiegaze committed May 29, 2024
1 parent d7f828a commit e08459b
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 36 deletions.
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})

0 comments on commit e08459b

Please sign in to comment.