|
27 | 27 |
|
28 | 28 | from scipy.sparse import coo_matrix |
29 | 29 | from scipy.sparse import csr_matrix |
30 | | -from scipy.spatial.distance import hamming as sp_hamming |
31 | 30 |
|
32 | 31 | from ..preprocessing import LabelBinarizer, label_binarize |
33 | 32 | from ..preprocessing import LabelEncoder |
@@ -640,7 +639,8 @@ def f1_score(y_true, y_pred, labels=None, pos_label=1, average='binary', |
640 | 639 |
|
641 | 640 | References |
642 | 641 | ---------- |
643 | | - .. [1] `Wikipedia entry for the F1-score <http://en.wikipedia.org/wiki/F1_score>`_ |
| 642 | + .. [1] `Wikipedia entry for the F1-score |
| 643 | + <http://en.wikipedia.org/wiki/F1_score>`_ |
644 | 644 |
|
645 | 645 | Examples |
646 | 646 | -------- |
@@ -1386,11 +1386,9 @@ class 2 1.00 0.67 0.80 3 |
1386 | 1386 | last_line_heading = 'avg / total' |
1387 | 1387 |
|
1388 | 1388 | if target_names is None: |
1389 | | - width = len(last_line_heading) |
1390 | 1389 | target_names = ['%s' % l for l in labels] |
1391 | | - else: |
1392 | | - width = max(len(cn) for cn in target_names) |
1393 | | - width = max(width, len(last_line_heading), digits) |
| 1390 | + name_width = max(len(cn) for cn in target_names) |
| 1391 | + width = max(name_width, len(last_line_heading), digits) |
1394 | 1392 |
|
1395 | 1393 | headers = ["precision", "recall", "f1-score", "support"] |
1396 | 1394 | fmt = '%% %ds' % width # first column: class name |
@@ -1508,8 +1506,10 @@ def hamming_loss(y_true, y_pred, classes=None, sample_weight=None): |
1508 | 1506 | weight_average = np.mean(sample_weight) |
1509 | 1507 |
|
1510 | 1508 | if y_type.startswith('multilabel'): |
1511 | | - n_differences = count_nonzero(y_true - y_pred, sample_weight=sample_weight) |
1512 | | - return (n_differences / (y_true.shape[0] * len(classes) * weight_average)) |
| 1509 | + n_differences = count_nonzero(y_true - y_pred, |
| 1510 | + sample_weight=sample_weight) |
| 1511 | + return (n_differences / |
| 1512 | + (y_true.shape[0] * len(classes) * weight_average)) |
1513 | 1513 |
|
1514 | 1514 | elif y_type in ["binary", "multiclass"]: |
1515 | 1515 | return _weighted_sum(y_true != y_pred, sample_weight, normalize=True) |
|
0 commit comments