Skip to content

Commit 06a2dba

Browse files
gustavocidornelaswhoseoyster
authored andcommitted
Completes OPEN-3870 Allow specification of a prediction threshold for binary classifiers
1 parent ca8ce5b commit 06a2dba

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

openlayer/schemas.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,23 @@ class ModelSchema(ma.Schema):
139139
),
140140
required=True,
141141
)
142+
predictionThreshold = ma.fields.Float(
143+
allow_none=True,
144+
validate=ma.validate.Range(
145+
min=0.0,
146+
max=1.0,
147+
),
148+
load_default=None,
149+
)
150+
151+
@ma.validates_schema
152+
def validates_prediction_threshold_and_class_names(self, data, **kwargs):
153+
"""Validates whether a prediction threshold was specified for a
154+
binary classification model."""
155+
if data["predictionThreshold"] and len(data["classNames"]) != 2:
156+
raise ma.ValidationError(
157+
"`predictionThreshold` can only be specified for binary classification models."
158+
)
142159

143160

144161
class ProjectSchema(ma.Schema):

0 commit comments

Comments
 (0)