Skip to content

Commit 2ea0b09

Browse files
committed
include performance monitoring
1 parent 90fe41b commit 2ea0b09

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

examples/full_lifecycle.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from sklearn.model_selection import train_test_split
1212

1313
from sasctl import Session
14-
from sasctl.tasks import register_model, publish_model
14+
from sasctl.tasks import register_model, publish_model, update_model_performance
1515
from sasctl.services import model_repository as mr
1616
from sasctl.services import model_management as mm
1717

@@ -39,12 +39,10 @@
3939
project=project, # Register in "Iris" project
4040
force=True) # Create project if it doesn't exist
4141

42-
# Update project properties
42+
# Update project properties. Target variable must be set before performance
43+
# definitions can be created.
4344
project = mr.get_project(project)
44-
project['function'] = 'prediction'
45-
project['targetLevel'] = 'interval'
4645
project['targetVariable'] = 'Price'
47-
project['predictionVariable'] = 'var1'
4846
project = mr.update_project(project)
4947

5048
# Instruct the project to look for tables in the "Public" CAS library with
@@ -55,8 +53,8 @@
5553
# Publish the model to the real-time scoring engine
5654
module_lm = publish_model(model_name, 'maslocal')
5755

58-
# Select the first row of training data
59-
x = X.iloc[0, :]
56+
# Select the first row of testing data
57+
x = X_test.iloc[0, :]
6058

6159
# Call the published module and score the record
6260
result = module_lm.score(**x)
@@ -76,5 +74,16 @@
7674
result = module_dt.score(**x)
7775
print(result)
7876

77+
# Model Manager can track model performance over time if provided with
78+
# historical model observations & predictions. SIMULATE historical data by
79+
# repeatedly sampling from the test set.
80+
perf_df = X_test.copy()
81+
perf_df['var1'] = lm.predict(X_test)
82+
perf_df['Price'] = y
83+
84+
# For each (simulated) historical period, upload model results
85+
for period in ('q12019', 'q22019', 'q32019', 'q42019'):
86+
sample = perf_df.sample(frac=0.2)
87+
update_model_performance(sample, model_name, period)
7988

8089

0 commit comments

Comments
 (0)