Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions examples/score_testing_example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@
},
{
"cell_type": "code",
"execution_count": 21,
"execution_count": null,
"metadata": {},
"outputs": [
{
Expand All @@ -531,8 +531,7 @@
" # Calculate the model statistics, ROC chart, and Lift chart; then write to json files\n",
" pzmm.JSONFiles.calculate_model_statistics(\n",
" target_value=1, \n",
" prob_value=0.5, \n",
" train_data=train_data, \n",
" train_data=train_data, \n",
" test_data=test_data, \n",
" json_path=path\n",
" )\n",
Expand Down Expand Up @@ -604,7 +603,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -613,7 +612,7 @@
" score_def_name=\"example_score_def_name\", # Name of the score_definition, which can be any string\n",
" model='DecisionTreeClassifier', # Can use model name, UUID, or dictionary representation of the model\n",
" table_name=\"HMEQPERF_1_Q1\", # Table name for input data\n",
" use_cas_gateway=False, # Change to True if your Viya version is compatible with CAS Gateway. \n",
" use_cas_gateway=True, # Change to False if your Viya version is not compatible with CAS Gateway. \n",
" table_file='data/HMEQPERF_1_Q1.csv' # add the file path of HMEQPERF_1_Q1 if HMEQPERF_1_Q1 does not yet exist on the server. If the user doesn't need the file path argument, they can comment out this line completely.\n",
")\n"
]
Expand Down Expand Up @@ -650,7 +649,7 @@
"outputs": [],
"source": [
"# The following lines print the output table with scoring results. Ensure that the use_cas_gateway argument is the same as it is in the score definition call.\n",
"score_results = se.get_score_execution_results(score_execution, use_cas_gateway=False)\n",
"score_results = se.get_score_execution_results(score_execution, use_cas_gateway=True)\n",
"score_results"
]
},
Expand Down Expand Up @@ -682,14 +681,14 @@
" score_def_name=\"score_definition_example\",\n",
" model='DecisionTreeClassifier',\n",
" table_name='HMEQPERF_1_Q1', # If this call is made before running the code above, the table_file argument must be included if the file is not yet on the server\n",
" use_cas_gateway=False # Change to True if your Viya version is compatible with CAS Gateway. \n",
" use_cas_gateway=True # Change to False if your Viya version is not compatible with CAS Gateway. \n",
")"
]
}
],
"metadata": {
"kernelspec": {
"display_name": ".venv",
"display_name": ".venv311 (3.11.16)",
"language": "python",
"name": "python3"
},
Expand All @@ -703,7 +702,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.2"
"version": "3.11.16"
}
},
"nbformat": 4,
Expand Down
26 changes: 18 additions & 8 deletions src/sasctl/_services/score_definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from pathlib import Path
import json
from typing import Union, Optional
from typing import Dict, Union, Optional

from ..core import current_session, delete, get, sasctl_command, RestObj
from .cas_management import CASManagement
Expand Down Expand Up @@ -41,12 +41,13 @@ def create_score_definition(
score_def_name: str,
model: Union[str, dict],
table_name: str,
use_cas_gateway: Optional[bool] = False,
use_cas_gateway: Optional[bool] = True,
table_file: Union[str, Path] = None,
description: str = "",
server_name: str = "cas-shared-default",
library_name: str = "Public",
model_version: Union[str, dict] = "latest",
input_mapping: Optional[Dict] = None,
):
"""Creates the score definition service.

Expand All @@ -70,6 +71,8 @@ def create_score_definition(
The library within the CAS server the table exists in. Defaults to "Public".
model_version: str, optional
The user-chosen version of the model. Deafaults to "latest".
input_mapping: list, optional
A list of dictionaries mapping variables from the data table to the variables in the model if they are different. Defaults to None.

Returns
-------
Expand Down Expand Up @@ -101,11 +104,18 @@ def create_score_definition(
try:
inputMapping = []
for input_item in model.get("inputVariables"):
var = {
"mappingValue": input_item["name"],
"mappingType": "datasource",
"variableName": input_item["name"],
}
if input_mapping and input_item["name"] in input_mapping:
var = {
"mappingValue": input_mapping[input_item["name"]],
"mappingType": "datasource",
"variableName": input_item["name"],
}
else:
var = {
"mappingValue": input_item["name"],
"mappingType": "datasource",
"variableName": input_item["name"],
}
inputMapping.append(var)

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

save_score_def = {
"name": model_name, # used to be score_def_name
"name": score_def_name, # used to be score_def_name
"description": description,
"objectDescriptor": {
"uri": object_uri,
Expand Down
2 changes: 1 addition & 1 deletion src/sasctl/_services/score_execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def poll_score_execution_state(

@classmethod
def get_score_execution_results(
cls, score_execution: Union[dict, str], use_cas_gateway: False
cls, score_execution: Union[dict, str], use_cas_gateway: True
):
"""Generates an output table for the score_execution results.

Expand Down
4 changes: 3 additions & 1 deletion src/sasctl/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -980,8 +980,9 @@ def score_model_with_cas(
server_name: str = "cas-shared-default",
library_name: str = "Public",
model_version: str = "latest",
use_cas_gateway: bool = False,
use_cas_gateway: bool = True,
timeout: int = 300,
input_mapping: dict = None,
):
score_definition = sd.create_score_definition(
score_def_name,
Expand All @@ -993,6 +994,7 @@ def score_model_with_cas(
library_name=library_name,
model_version=model_version,
use_cas_gateway=use_cas_gateway,
input_mapping=input_mapping,
)
score_execution = se.create_score_execution(score_definition.id)
score_execution_poll = se.poll_score_execution_state(score_execution, timeout)
Expand Down
Loading