|
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 |
7 | 8 | from sasctl import Session
|
8 | 9 | from sasctl.tasks import register_model, publish_model
|
9 | 10 |
|
10 |
| -hostname = '' |
11 |
| -username = '' |
12 |
| -password = '' |
13 | 11 |
|
14 |
| -# Use sasctl to connect to SAS |
15 |
| -sess = Session('hostname', 'username', 'password', protocol='http') |
16 |
| -cas = sess.as_swat() |
| 12 | +with swat.CAS('hostname', 5570, 'username', 'password') as cas: |
| 13 | + # Load the regression actions in CAS |
| 14 | + cas.loadactionset('regression') |
17 | 15 |
|
18 |
| -# Load the regression actions in CAS |
19 |
| -cas.loadactionset('regression') |
| 16 | + # Upload the local CSV file to a CAS table |
| 17 | + tbl = cas.upload('data/boston_house_prices.csv').casTable |
20 | 18 |
|
21 |
| -# Upload the local CSV file to a CAS table |
22 |
| -tbl = cas.upload('data/boston_house_prices.csv').casTable |
| 19 | + # Model input features are everything except the target |
| 20 | + features = tbl.columns[tbl.columns != 'medv'] |
23 | 21 |
|
24 |
| -# Model input features are everything except the target |
25 |
| -features = tbl.columns[tbl.columns != 'medv'] |
| 22 | + # Fit a linear regression model in CAS and output an ASTORE |
| 23 | + tbl.glm(target='medv', inputs=list(features), savestate='model_table') |
26 | 24 |
|
27 |
| -# Fit a linear regression model in CAS and output an ASTORE |
28 |
| -tbl.glm(target='medv', inputs=list(features), savestate='model_table') |
| 25 | + astore = cas.CASTable('model_table') |
29 | 26 |
|
30 |
| -astore = cas.CASTable('model_table') |
| 27 | + # Use sasctl to connect to SAS |
| 28 | + Session('hostname', 'username', 'password') |
31 | 29 |
|
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) |
| 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) |
35 | 33 |
|
36 |
| -# Publish the model to a real-time scoring engine |
37 |
| -module = publish_model(model, 'maslocal') |
| 34 | + # Publish the model to a real-time scoring engine |
| 35 | + module = publish_model(model, 'maslocal') |
38 | 36 |
|
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) |
| 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) |
0 commit comments