Skip to content

Commit da592a6

Browse files
committed
Update sas regression example to use Session.as_swat()
1 parent 9ba4ec6 commit da592a6

File tree

1 file changed

+24
-22
lines changed

1 file changed

+24
-22
lines changed

examples/register_sas_regression_model.py

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,37 +4,39 @@
44
# Copyright © 2019, SAS Institute Inc., Cary, NC, USA. All Rights Reserved.
55
# SPDX-License-Identifier: Apache-2.0
66

7-
import swat
87
from sasctl import Session
98
from sasctl.tasks import register_model, publish_model
109

10+
hostname = ''
11+
username = ''
12+
password = ''
1113

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()
1517

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')
1820

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
2123

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']
2426

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')
2629

27-
# Use sasctl to connect to SAS
28-
Session('hostname', 'username', 'password')
30+
astore = cas.CASTable('model_table')
2931

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)
3335

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')
3638

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

Comments
 (0)