BookmarkSubscribeRSS Feed

Running a scoring test for a Python model fails in SAS Model Manager 15.4

Started ‎03-28-2023 by
Modified ‎03-28-2023 by
Views 767

Question

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.

Answer

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. 

 scoreDecisionTreeClassifier(LOAN, MORTDUE, VALUE, YOJ, DEROG, DELINQ, CLAGE, NINQ, CLNO, DEBTINC)
Please do not add the above line to the original Python program you registered in a model repository.
 
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.

 

Version history
Last update:
‎03-28-2023 04:07 PM
Updated by:
Contributors

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!

Free course: Data Literacy Essentials

Data Literacy is for all, even absolute beginners. Jump on board with this free e-learning  and boost your career prospects.

Get Started

Article Labels
Article Tags