-
-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathdiff_157.patch
More file actions
35 lines (31 loc) · 2.72 KB
/
Copy pathdiff_157.patch
File metadata and controls
35 lines (31 loc) · 2.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
diff --git a/models/calibration.py b/models/calibration.py
index ddc0e33..7e49cfc 100644
--- a/models/calibration.py
+++ b/models/calibration.py
@@ -65,7 +65,13 @@ def calculate_ece(
def fit_temperature(self, y_true: np.ndarray, y_prob: np.ndarray) -> float:
"""Find the optimal temperature T using negative log likelihood minimization."""
- from scipy.optimize import minimize
+ try:
+ from scipy.optimize import minimize
+ except ImportError:
+ import warnings
+ warnings.warn("scipy not found, skipping temperature fitting")
+ self.temperature = 1.0
+ return 1.0
y_true = np.array(y_true)
y_prob = np.array(y_prob)
@@ -89,7 +95,14 @@ def nll_loss(t):
def fit_platt(self, y_true: np.ndarray, y_prob: np.ndarray) -> Tuple[float, float]:
"""Find Platt scaling parameters A and B using logistic regression."""
- from scipy.optimize import minimize
+ try:
+ from scipy.optimize import minimize
+ except ImportError:
+ import warnings
+ warnings.warn("scipy not found, skipping Platt scaling")
+ self.platt_a = 1.0
+ self.platt_b = 0.0
+ return self.platt_a, self.platt_b
y_true = np.array(y_true)
y_prob = np.array(y_prob)