-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.py
56 lines (44 loc) · 1.31 KB
/
run.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
from zenml.client import Client
from zenml.logger import get_logger
from zenml import step, Model, pipeline, log_metadata
from sklearn.datasets import load_iris
from sklearn.linear_model import LogisticRegression
import numpy as np
logger = get_logger(__name__)
model_name = "IrisClassifier"
model = Model(
name=model_name,
description="Iris classifier",
tags=["quickstart", "iris", "logistic"],
)
@step
def get_data() -> tuple[np.ndarray, np.ndarray]:
X, y = load_iris(return_X_y=True)
return X, y
@step
def get_model() -> LogisticRegression:
clf = LogisticRegression(random_state=0)
return clf
@step
def assess_model(clf, X, y) -> float:
clf = clf.fit(X, y)
clf.predict(X[:2, :])
clf.predict_proba(X[:2, :])
score = clf.score(X, y)
log_metadata(metadata={"accuracy": score})
return score
@pipeline(model=model)
def main():
client = Client()
run_args_train = {}
orchf = client.active_stack.orchestrator.flavor
sof = None
if client.active_stack.step_operator:
sof = client.active_stack.step_operator.flavor
pipeline_args = {}
pipeline_args["enable_cache"] = False
X,y = get_data()
clf = get_model()
score = assess_model(clf, X, y)
if __name__ == "__main__":
main()