Spaces:
Running
Running
Commit
·
8b0574e
1
Parent(s):
1d0ae2e
fix: wrong 2nd model threshold
Browse files
core-model-prediction/prediction.py
CHANGED
@@ -58,16 +58,17 @@ def process_instance(data: PredictRequest):
|
|
58 |
secondary_model_probability = secondary_model.predict(
|
59 |
secondary_model_features)
|
60 |
|
|
|
|
|
61 |
return {
|
62 |
-
"predicted_class": "AI" if secondary_model_probability >
|
63 |
"main_model_probability": str(main_model_probability),
|
64 |
"secondary_model_probability": str(secondary_model_probability),
|
65 |
-
"confidence": get_confidence(main_model_probability, secondary_model_probability)
|
66 |
}
|
67 |
|
68 |
|
69 |
-
def get_confidence(main_model_output: float, secondary_model_output: int):
|
70 |
-
threshold = 0.54
|
71 |
if (main_model_output >= 0.8 and secondary_model_output >= threshold) or (main_model_output <= 0.2 and secondary_model_output <= 1 - threshold):
|
72 |
return 'High Confidence'
|
73 |
elif (0.5 < main_model_output < 0.8 and secondary_model_output >= threshold) or (0.2 < main_model_output <= 0.5 and secondary_model_output < threshold):
|
|
|
58 |
secondary_model_probability = secondary_model.predict(
|
59 |
secondary_model_features)
|
60 |
|
61 |
+
second_model_threshold = 0.54
|
62 |
+
|
63 |
return {
|
64 |
+
"predicted_class": "AI" if secondary_model_probability > second_model_threshold else "HUMAN",
|
65 |
"main_model_probability": str(main_model_probability),
|
66 |
"secondary_model_probability": str(secondary_model_probability),
|
67 |
+
"confidence": get_confidence(main_model_probability, secondary_model_probability, second_model_threshold)
|
68 |
}
|
69 |
|
70 |
|
71 |
+
def get_confidence(main_model_output: float, secondary_model_output: int, threshold: float):
|
|
|
72 |
if (main_model_output >= 0.8 and secondary_model_output >= threshold) or (main_model_output <= 0.2 and secondary_model_output <= 1 - threshold):
|
73 |
return 'High Confidence'
|
74 |
elif (0.5 < main_model_output < 0.8 and secondary_model_output >= threshold) or (0.2 < main_model_output <= 0.5 and secondary_model_output < threshold):
|