|
4 | 4 | # Copyright © 2019, SAS Institute Inc., Cary, NC, USA. All Rights Reserved.
|
5 | 5 | # SPDX-License-Identifier: Apache-2.0
|
6 | 6 |
|
7 |
| -import swat |
8 | 7 | from sasctl import Session
|
9 | 8 | from sasctl.tasks import register_model, publish_model
|
10 | 9 |
|
| 10 | +hostname = '' |
| 11 | +username = '' |
| 12 | +password = '' |
11 | 13 |
|
12 |
| -with swat.CAS('hostname', 5570, 'username', 'password') as cas: |
13 |
| - # Load the regression actions in CAS |
14 |
| - cas.loadactionset('regression') |
| 14 | +# Use sasctl to connect to SAS |
| 15 | +sess = Session('hostname', 'username', 'password', protocol='http') |
| 16 | +cas = sess.as_swat() |
15 | 17 |
|
16 |
| - # Upload the local CSV file to a CAS table |
17 |
| - tbl = cas.upload('data/boston_house_prices.csv').casTable |
| 18 | +# Load the regression actions in CAS |
| 19 | +cas.loadactionset('regression') |
18 | 20 |
|
19 |
| - # Model input features are everything except the target |
20 |
| - features = tbl.columns[tbl.columns != 'medv'] |
| 21 | +# Upload the local CSV file to a CAS table |
| 22 | +tbl = cas.upload('data/boston_house_prices.csv').casTable |
21 | 23 |
|
22 |
| - # Fit a linear regression model in CAS and output an ASTORE |
23 |
| - tbl.glm(target='medv', inputs=list(features), savestate='model_table') |
| 24 | +# Model input features are everything except the target |
| 25 | +features = tbl.columns[tbl.columns != 'medv'] |
24 | 26 |
|
25 |
| - astore = cas.CASTable('model_table') |
| 27 | +# Fit a linear regression model in CAS and output an ASTORE |
| 28 | +tbl.glm(target='medv', inputs=list(features), savestate='model_table') |
26 | 29 |
|
27 |
| - # Use sasctl to connect to SAS |
28 |
| - Session('hostname', 'username', 'password') |
| 30 | +astore = cas.CASTable('model_table') |
29 | 31 |
|
30 |
| - # Register the model in SAS Model Manager, creating the "Boston Housing" |
31 |
| - # project if it doesn't already exist |
32 |
| - model = register_model(astore, 'Linear Regression', 'Boston Housing', force=True) |
| 32 | +# Register the model in SAS Model Manager, creating the "Boston Housing" |
| 33 | +# project if it doesn't already exist |
| 34 | +model = register_model(astore, 'Linear Regression', 'Boston Housing', force=True) |
33 | 35 |
|
34 |
| - # Publish the model to a real-time scoring engine |
35 |
| - module = publish_model(model, 'maslocal') |
| 36 | +# Publish the model to a real-time scoring engine |
| 37 | +module = publish_model(model, 'maslocal') |
36 | 38 |
|
37 |
| - # Pass a row of data to MAS and receive the predicted result. |
38 |
| - first_row = tbl.head(1) |
39 |
| - result = module.score(first_row) |
40 |
| - print(result) |
| 39 | +# Pass a row of data to MAS and receive the predicted result. |
| 40 | +first_row = tbl.head(1) |
| 41 | +result = module.score(first_row) |
| 42 | +print(result) |
0 commit comments