Skip to content

Commit 373fa98

Browse files
committed
Code cleanup
1 parent 5d8ff22 commit 373fa98

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

Orange/evaluation/scoring.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,8 @@ class AUC(ClassificationScore):
200200
is_binary = True
201201
long_name = "Area under ROC curve"
202202

203-
def calculate_weights(self, results):
203+
@staticmethod
204+
def calculate_weights(results):
204205
classes = np.unique(results.actual)
205206
class_cases = [sum(results.actual == class_)
206207
for class_ in classes]
@@ -212,14 +213,14 @@ def calculate_weights(self, results):
212213
else:
213214
return weights / wsum
214215

215-
def single_class_auc(self, results, target):
216+
@staticmethod
217+
def single_class_auc(results, target):
216218
y = np.array(results.actual == target, dtype=int)
217219
return np.fromiter(
218220
(skl_metrics.roc_auc_score(y, probabilities[:, int(target)])
219221
for probabilities in results.probabilities),
220222
dtype=np.float64, count=len(results.predicted))
221223

222-
223224
def multi_class_auc(self, results):
224225
classes = np.unique(results.actual)
225226
weights = self.calculate_weights(results)
@@ -285,14 +286,15 @@ def compute_score(self, results, eps=1e-15, normalize=True,
285286
class Specificity(ClassificationScore):
286287
is_binary = True
287288

288-
def calculate_weights(self, results):
289+
@staticmethod
290+
def calculate_weights(results):
289291
classes, counts = np.unique(results.actual, return_counts=True)
290292
n = np.array(results.actual).shape[0]
291293
return counts / n, classes
292294

293295
@staticmethod
294296
def specificity(y_true, y_pred):
295-
tn, fp, fn, tp = confusion_matrix(y_true, y_pred).ravel()
297+
tn, fp, _, _ = confusion_matrix(y_true, y_pred).ravel()
296298
return tn / (tn + fp)
297299

298300
def single_class_specificity(self, results, target):
@@ -306,7 +308,7 @@ def single_class_specificity(self, results, target):
306308
def multi_class_specificity(self, results):
307309
weights, classes = self.calculate_weights(results)
308310
scores = np.array([self.single_class_specificity(results, class_)
309-
for class_ in classes])
311+
for class_ in classes])
310312
return np.sum(scores.T * weights, axis=1)
311313

312314
def compute_score(self, results, target=None, average="binary"):

0 commit comments

Comments
 (0)