-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(JAQPOT-334): add jaqpot internal ID (#27)
* chore: delete comment * feat: return all probabilities instead of the max * feat: return jaqpotInternalId with the dataset * refactor: predict_sklearn for jaqpotInternalId * chore: rename to jaqpotInternalMetadata * feat: return a predictions dict
- Loading branch information
1 parent
fa455e8
commit 8cce802
Showing
3 changed files
with
31 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,41 @@ | ||
from ..entities.prediction_request import PredictionRequestPydantic | ||
from ..helpers import model_decoder, json_to_predreq | ||
from ..helpers.predict_methods import predict_onnx, predict_proba_onnx | ||
import numpy as np | ||
|
||
|
||
def sklearn_post_handler(request: PredictionRequestPydantic): | ||
model = model_decoder.decode(request.model["rawModel"]) | ||
data_entry_all = json_to_predreq.decode(request) | ||
data_entry_all, JaqpotInternalId = json_to_predreq.decode(request) | ||
prediction = predict_onnx(model, data_entry_all, request) | ||
task = request.model["task"].lower() | ||
if task == "binary_classification" or task == "multiclass_classification": | ||
probabilities = predict_proba_onnx(model, data_entry_all, request) | ||
else: | ||
probabilities = [None for _ in range(len(prediction))] | ||
|
||
results = {} | ||
for i, feature in enumerate(request.model["dependentFeatures"]): | ||
key = feature["key"] | ||
values = [ | ||
str(item[i]) if len(request.model["dependentFeatures"]) > 1 else str(item) | ||
for item in prediction | ||
] | ||
results[key] = values | ||
final_all = [] | ||
for jaqpot_id in JaqpotInternalId: | ||
if len(request.model["dependentFeatures"]) == 1: | ||
prediction = prediction.reshape(-1, 1) | ||
jaqpot_id = int(jaqpot_id) | ||
results = { | ||
feature["key"]: int(prediction[jaqpot_id, i]) | ||
if isinstance( | ||
prediction[jaqpot_id, i], (np.int16, np.int32, np.int64, np.longlong) | ||
) | ||
else float(prediction[jaqpot_id, i]) | ||
if isinstance( | ||
prediction[jaqpot_id, i], (np.float16, np.float32, np.float64) | ||
) | ||
else prediction[jaqpot_id, i] | ||
for i, feature in enumerate(request.model["dependentFeatures"]) | ||
} | ||
results["jaqpotInternalId"] = jaqpot_id | ||
results["jaqpotInternalMetadata"] = { | ||
"AD": None, | ||
"Probabilities": probabilities[jaqpot_id], | ||
} | ||
final_all.append(results) | ||
|
||
results["Probabilities"] = [str(prob) for prob in probabilities] | ||
results["AD"] = [None for _ in range(len(prediction))] | ||
|
||
final_all = {"predictions": [dict(zip(results, t)) for t in zip(*results.values())]} | ||
|
||
return final_all | ||
return {"predictions": final_all} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters