解法如下,公式參考https://en.wikipedia.org/wiki/Precision_and_recall:
Accuracy = T / (P+N)
# 因 (P+N) = 1 ==> T = 0.9926 ==> F = 1 - T = 0.0074
# Precision = tp / P = 0.9805 ==> tp = 0.9805 * P, fp = 0.0195 * P
# fn = F - fp = F - 0.0195 * P = 0.0074 - 0.0195 * P
# Recall = tp / (tp + fn) = 0.9804
==> (0.9805 * P) / (0.9805 * P + (0.0074 - 0.0195 * P)) = 0.9804 (利用程式1)
==> P = 0.1892, N = 1 - 0.1892 = 0.8108
# NPV = tn / (tn +fn) = (T - tp) / N = (0.9926 - 0.9805) / 0.8108 = 0.01492
# specificity = tn / (tn + fp) = (T - tp) / (T - tp + P - tp) = 0.9954495603486425 (利用程式2)
# Specificity = tn / (tn +fp) = (T - Recall) = 0.9926 - 0.9804 = 0.0122
程式1:
from sympy.solvers import solve
from sympy import Symbol
P = Symbol('P', real=True)
solve([(0.9805 * P) / (0.9805 * P + (0.0074 - 0.0195 * P)) - 0.9804])
程式2:
T = 0.9926
P = 0.1892
tp = 0.9805 * P
(T - tp) / (T - tp + P - tp)