I have imported a Python model into a model repository successfully. However, when I ran a scoring test for this model, the scoring test failed. The corresponding sas log contains information like the following. What should I do?
ERROR: Line 92: DS2 "pymas" package encountered a failure in the 'execute' method.
To figure out what has gone wrong for the above error, you should get corresponding cas log at /opt/sas/viya/config/var/log/cas/default from the machine that runs the cas worker. Then search for the following string: mas2py.py.
Check this line and it could contain something like the following:
File "/opt/sas/viya/home/SASFoundation/misc/embscoreeng/mas2py.py", line 900, in invoke
out = up[1].get(func)[0](up[0])(*args)
File "/tmp/tmpw8y5zu1_/model_exec_c62e2a82-3f3b-4458-978e-e7ce3d45bbff.py", line 8, in scoreGradientBoosting
return GradientBoostingScore.scoreGradientBoosting(LOAN, MORTDUE, VALUE, YOJ, DEROG, DELINQ, CLAGE, NINQ, CLNO, DEBTINC)
File "/models/resources/viya/97cd94c3-00c0-4489-a25c-b999b48716ea/GradientBoostingScore.py", line 27, in scoreGradientBoosting
prediction = _thisModelFit.predict(inputArray)
File "/opt/sas/viya/home/sas-pyconfig/default_py/lib/python3.8/site-packages/sklearn/ensemble/_gb.py", line 1449, in predict
raw_predictions = self.decision_function(X)
File "/opt/sas/viya/home/sas-pyconfig/default_py/lib/python3.8/site-packages/sklearn/ensemble/_gb.py", line 1405, in decision_function
raw_predictions = self._raw_predict(X)
File "/opt/sas/viya/home/sas-pyconfig/default_py/lib/python3.8/site-packages/sklearn/ensemble/_gb.py", line 817, in _raw_predict
raw_predictions = self._raw_predict_init(X)
File "/opt/sas/viya/home/sas-pyconfig/default_py/lib/python3.8/site-packages/sklearn/ensemble/_gb.py", line 810, in _raw_predict_init
raw_predictions = self._loss.get_init_raw_predictions(X, self.init_).astype(
AttributeError: 'GradientBoostingClassifier' object has no attribute '_loss'
This should provide you enough information to identify the cause for your issue.
To make sure your Python program works correctly outside SAS Model Manager, you can create a new Python program by adding one line at the end of the original Python program to call the scoring function, then run this modified Python program on the cas worker machine with the configured Python environment and make sure it works without any error.
For example, the last line of the modified Python program looks like the following.
import math
import pickle
import pandas as pd
import numpy as np
import settings
with open(settings.pickle_path + 'DecisionTreeClassifier.pickle', 'rb') as _pFile:
_thisModelFit = pickle.load(_pFile)
def scoreDecisionTreeClassifier(LOAN, MORTDUE, VALUE, YOJ, DEROG, DELINQ, CLAGE, NINQ, CLNO, DEBTINC):
"Output: EM_EVENTPROBABILITY, EM_CLASSIFICATION"
...
scoreDecisionTreeClassifier(10000, 30000,20000,9,0,2,101.5,1,8,29.0)
Keep in mind that you should use the Python you configured (SAS Help Center: Configuring Python for SAS Intelligent Decisioning) to run your modified program.
You need to check /opt/sas/viya/config/etc/cas/default/cas_usermods.settings on the cas worker machine. It should contain something like the following:
# configure for pymas
export MAS_M2PATH=/opt/sas/viya/home/SASFoundation/misc/embscoreeng/mas2py.py
export MAS_PYPATH=/usr/bin/python3
When you run your Python program on the cas worker machine, you should use
/usr/bin/python3 <Your modified Python file>
If you run the above command successfully without any error, then hopefully you should be able to run your scoring test successfully.
There is still a chance that the scoring test fails due to some records in the scoring test input table may trigger an exception in the Python program. I strongly suggest that you only use a table with one record that has the same value as the one you used in your modified Python program.
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
Data Literacy is for all, even absolute beginners. Jump on board with this free e-learning and boost your career prospects.