FIX array_equal for numpy < 1.8.1
This commit is contained in:
parent
628ed2c867
commit
fecd35567e
|
|
@ -28,6 +28,7 @@ from ..utils import column_or_1d, check_array
|
|||
from ..utils.multiclass import type_of_target
|
||||
from ..utils.fixes import isclose
|
||||
from ..utils.fixes import bincount
|
||||
from ..utils.fixes import array_equal
|
||||
from ..utils.stats import rankdata
|
||||
from ..utils.sparsefuncs import count_nonzero
|
||||
|
||||
|
|
@ -295,11 +296,11 @@ def _binary_clf_curve(y_true, y_score, pos_label=None, sample_weight=None):
|
|||
# ensure binary classification if pos_label is not specified
|
||||
classes = np.unique(y_true)
|
||||
if (pos_label is None and
|
||||
not (np.array_equal(classes, [0, 1]) or
|
||||
np.array_equal(classes, [-1, 1]) or
|
||||
np.array_equal(classes, [0]) or
|
||||
np.array_equal(classes, [-1]) or
|
||||
np.array_equal(classes, [1]))):
|
||||
not (array_equal(classes, [0, 1]) or
|
||||
array_equal(classes, [-1, 1]) or
|
||||
array_equal(classes, [0]) or
|
||||
array_equal(classes, [-1]) or
|
||||
array_equal(classes, [1]))):
|
||||
raise ValueError("Data is not binary and pos_label is not specified")
|
||||
elif pos_label is None:
|
||||
pos_label = 1.
|
||||
|
|
|
|||
|
|
@ -375,3 +375,17 @@ else:
|
|||
if (not exist_ok or e.errno != errno.EEXIST
|
||||
or not os.path.isdir(name)):
|
||||
raise
|
||||
|
||||
|
||||
if np_version < (1, 8, 1):
|
||||
def array_equal(a1, a2):
|
||||
# copy-paste from numpy 1.8.1
|
||||
try:
|
||||
a1, a2 = np.asarray(a1), np.asarray(a2)
|
||||
except:
|
||||
return False
|
||||
if a1.shape != a2.shape:
|
||||
return False
|
||||
return bool(np.asarray(a1 == a2).all())
|
||||
else:
|
||||
from numpy import array_equal
|
||||
|
|
|
|||
|
|
@ -19,10 +19,9 @@ from scipy.sparse import lil_matrix
|
|||
import numpy as np
|
||||
|
||||
from ..externals.six import string_types
|
||||
|
||||
from .validation import check_array
|
||||
|
||||
from ..utils.fixes import bincount
|
||||
from ..utils.fixes import array_equal
|
||||
|
||||
|
||||
def _unique_multiclass(y):
|
||||
|
|
@ -283,7 +282,7 @@ def _check_partial_fit_first_call(clf, classes=None):
|
|||
|
||||
elif classes is not None:
|
||||
if getattr(clf, 'classes_', None) is not None:
|
||||
if not np.array_equal(clf.classes_, unique_labels(classes)):
|
||||
if not array_equal(clf.classes_, unique_labels(classes)):
|
||||
raise ValueError(
|
||||
"`classes=%r` is not the same as on last call "
|
||||
"to partial_fit, was: %r" % (classes, clf.classes_))
|
||||
|
|
|
|||
Loading…
Reference in New Issue