|
11 | 11 | from sklearn.model_selection import train_test_split
|
12 | 12 |
|
13 | 13 | 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 |
15 | 15 | from sasctl.services import model_repository as mr
|
16 | 16 | from sasctl.services import model_management as mm
|
17 | 17 |
|
|
39 | 39 | project=project, # Register in "Iris" project
|
40 | 40 | force=True) # Create project if it doesn't exist
|
41 | 41 |
|
42 |
| -# Update project properties |
| 42 | +# Update project properties. Target variable must be set before performance |
| 43 | +# definitions can be created. |
43 | 44 | project = mr.get_project(project)
|
44 |
| -project['function'] = 'prediction' |
45 |
| -project['targetLevel'] = 'interval' |
46 | 45 | project['targetVariable'] = 'Price'
|
47 |
| -project['predictionVariable'] = 'var1' |
48 | 46 | project = mr.update_project(project)
|
49 | 47 |
|
50 | 48 | # Instruct the project to look for tables in the "Public" CAS library with
|
|
55 | 53 | # Publish the model to the real-time scoring engine
|
56 | 54 | module_lm = publish_model(model_name, 'maslocal')
|
57 | 55 |
|
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, :] |
60 | 58 |
|
61 | 59 | # Call the published module and score the record
|
62 | 60 | result = module_lm.score(**x)
|
|
76 | 74 | result = module_dt.score(**x)
|
77 | 75 | print(result)
|
78 | 76 |
|
| 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) |
79 | 88 |
|
80 | 89 |
|
0 commit comments