Skip to content
This repository was archived by the owner on Sep 9, 2020. It is now read-only.
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
9 changes: 8 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
1.15.3 (2019 Jan 7)
===================

Bugfixes
--------
* Added support for ``--max_prediction_explanations`` on DataRobot 4.3.x .

1.15.2 (2018 Dec 17)
=====================

Expand All @@ -17,7 +24,7 @@ Enhancements

Enhancements
------------
* Added new argument ``-max_prediction_explanations`` that allows batch scoring with predictions explanations and adds ``explanation_N_feature`` and ``explanation_N_strength`` to each row in output document (where ``N ∈ (1, max_prediction_explanations)`` )
* Added new argument ``--max_prediction_explanations`` that allows batch scoring with predictions explanations and adds ``explanation_N_feature`` and ``explanation_N_strength`` to each row in output document (where ``N ∈ (1, max_prediction_explanations)`` )

1.14.2 (2018 Nov 14)
====================
Expand Down
2 changes: 1 addition & 1 deletion datarobot_batch_scoring/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '1.15.2'
__version__ = '1.15.3'
14 changes: 11 additions & 3 deletions datarobot_batch_scoring/api_response_handlers/pred_api_v10.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,24 @@ def format_data(result, batch, **opts):
written_fields = out_fields[1:]
comb = [row[1:] for row in pred]

if 'predictionExplanations' in single_row:
num_reason_codes = len(single_row['predictionExplanations'])
prediction_explanations_keys = ('predictionExplanations', 'reasonCodes',
None)

def _find_prediction_explanations_key():
return [key for key in prediction_explanations_keys
if key in single_row or key is None][0]

prediction_explanations_key = _find_prediction_explanations_key()
if prediction_explanations_key:
num_reason_codes = len(single_row[prediction_explanations_key])
for num in range(1, num_reason_codes + 1):
written_fields += [
'explanation_{0}_feature'.format(num),
'explanation_{0}_strength'.format(num)
]
for in_row, out_row in zip(result, comb):
reason_codes = []
for raw_reason_code in in_row['predictionExplanations']:
for raw_reason_code in in_row[prediction_explanations_key]:
reason_codes += [
raw_reason_code['feature'],
raw_reason_code['strength']
Expand Down
11 changes: 9 additions & 2 deletions datarobot_batch_scoring/batch_scoring.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,15 @@ def run_batch_predictions(base_url, base_headers, user, pwd,
endpoint = base_url + '/'.join((pid, lid))

if max_prediction_explanations:
endpoint += '/predictionExplanations?maxCodes=' + \
str(max_prediction_explanations)
if deployment_id is not None:
# Deployment routes only support predictionExplanations.
endpoint += '/predictionExplanations?maxCodes='
else:
# For non-deployment routes we use the old reasonCodesRoutes
# to support 4.3.x releases.
endpoint += '/reasonCodesPredictions?maxCodes='

endpoint += str(max_prediction_explanations)
else:
if deployment_id is not None:
endpoint += '/predictions'
Expand Down
4 changes: 4 additions & 0 deletions tests/liveserver_fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,8 @@ def post_auth():
@app.route('/predApi/v1.0/<pid>/<lid>/predict', methods=["POST"])
@app.route('/predApi/v1.0/<pid>/<lid>/predictionExplanations',
methods=["POST"])
@app.route('/predApi/v1.0/<pid>/<lid>/reasonCodesPredictions',
methods=["POST"])
@app.route('/api/v1/<pid>/<lid>/predict', methods=["POST"])
def predict_sinc(pid, lid):
return _predict(lid)
Expand All @@ -205,6 +207,8 @@ def predict_deployment_aware(deployment_id):
@app.route('/predApi/v1.0/<import_id>/predict', methods=["POST"])
@app.route('/predApi/v1.0/<import_id>/predictionExplanations',
methods=["POST"])
@app.route('/predApi/v1.0/<import_id>/reasonCodesPredictions',
methods=["POST"])
@app.route('/api/v1/<import_id>/predict', methods=["POST"])
def predict_transferable(import_id):
return _predict(import_id)
Expand Down