Skip to content

Commit f288c02

Browse files
committed
updated scoring execution/definition to handle input mapping
1 parent a617124 commit f288c02

4 files changed

Lines changed: 26 additions & 15 deletions

File tree

‎examples/score_testing_example.ipynb‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@
504504
},
505505
{
506506
"cell_type": "code",
507-
"execution_count": 21,
507+
"execution_count": null,
508508
"metadata": {},
509509
"outputs": [
510510
{
@@ -531,8 +531,7 @@
531531
" # Calculate the model statistics, ROC chart, and Lift chart; then write to json files\n",
532532
" pzmm.JSONFiles.calculate_model_statistics(\n",
533533
" target_value=1, \n",
534-
" prob_value=0.5, \n",
535-
" train_data=train_data, \n",
534+
" train_data=train_data, \n",
536535
" test_data=test_data, \n",
537536
" json_path=path\n",
538537
" )\n",
@@ -689,7 +688,7 @@
689688
],
690689
"metadata": {
691690
"kernelspec": {
692-
"display_name": ".venv",
691+
"display_name": ".venv311 (3.11.16)",
693692
"language": "python",
694693
"name": "python3"
695694
},
@@ -703,7 +702,7 @@
703702
"name": "python",
704703
"nbconvert_exporter": "python",
705704
"pygments_lexer": "ipython3",
706-
"version": "3.11.2"
705+
"version": "3.11.16"
707706
}
708707
},
709708
"nbformat": 4,

‎src/sasctl/_services/score_definitions.py‎

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from pathlib import Path
66
import json
7-
from typing import Union, Optional
7+
from typing import Dict, Union, Optional
88

99
from ..core import current_session, delete, get, sasctl_command, RestObj
1010
from .cas_management import CASManagement
@@ -41,12 +41,13 @@ def create_score_definition(
4141
score_def_name: str,
4242
model: Union[str, dict],
4343
table_name: str,
44-
use_cas_gateway: Optional[bool] = False,
44+
use_cas_gateway: Optional[bool] = True,
4545
table_file: Union[str, Path] = None,
4646
description: str = "",
4747
server_name: str = "cas-shared-default",
4848
library_name: str = "Public",
4949
model_version: Union[str, dict] = "latest",
50+
input_mapping: Optional[Dict] = None
5051
):
5152
"""Creates the score definition service.
5253
@@ -70,6 +71,8 @@ def create_score_definition(
7071
The library within the CAS server the table exists in. Defaults to "Public".
7172
model_version: str, optional
7273
The user-chosen version of the model. Deafaults to "latest".
74+
input_mapping: list, optional
75+
A list of dictionaries mapping variables from the data table to the variables in the model if they are different. Defaults to None.
7376
7477
Returns
7578
-------
@@ -101,11 +104,18 @@ def create_score_definition(
101104
try:
102105
inputMapping = []
103106
for input_item in model.get("inputVariables"):
104-
var = {
105-
"mappingValue": input_item["name"],
106-
"mappingType": "datasource",
107-
"variableName": input_item["name"],
108-
}
107+
if input_mapping and input_item["name"] in input_mapping:
108+
var = {
109+
"mappingValue": input_mapping[input_item["name"]],
110+
"mappingType": "datasource",
111+
"variableName": input_item["name"],
112+
}
113+
else:
114+
var = {
115+
"mappingValue": input_item["name"],
116+
"mappingType": "datasource",
117+
"variableName": input_item["name"],
118+
}
109119
inputMapping.append(var)
110120

111121
except:
@@ -133,7 +143,7 @@ def create_score_definition(
133143
# Checks if the model version is valid and how to find the name
134144

135145
save_score_def = {
136-
"name": model_name, # used to be score_def_name
146+
"name": score_def_name, # used to be score_def_name
137147
"description": description,
138148
"objectDescriptor": {
139149
"uri": object_uri,

‎src/sasctl/_services/score_execution.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ def poll_score_execution_state(
147147

148148
@classmethod
149149
def get_score_execution_results(
150-
cls, score_execution: Union[dict, str], use_cas_gateway: False
150+
cls, score_execution: Union[dict, str], use_cas_gateway: True
151151
):
152152
"""Generates an output table for the score_execution results.
153153

‎src/sasctl/tasks.py‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -980,8 +980,9 @@ def score_model_with_cas(
980980
server_name: str = "cas-shared-default",
981981
library_name: str = "Public",
982982
model_version: str = "latest",
983-
use_cas_gateway: bool = False,
983+
use_cas_gateway: bool = True,
984984
timeout: int = 300,
985+
input_mapping: dict = None
985986
):
986987
score_definition = sd.create_score_definition(
987988
score_def_name,
@@ -993,6 +994,7 @@ def score_model_with_cas(
993994
library_name=library_name,
994995
model_version=model_version,
995996
use_cas_gateway=use_cas_gateway,
997+
input_mapping = input_mapping
996998
)
997999
score_execution = se.create_score_execution(score_definition.id)
9981000
score_execution_poll = se.poll_score_execution_state(score_execution, timeout)

0 commit comments

Comments
 (0)