Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b2fe367

Browse files
jnothmanogrisel
authored andcommitted
DOC comment on _transform interface
Also avoid stride trick
1 parent 4dfde8b commit b2fe367

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

sklearn/preprocessing/label.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import array
1111

1212
import numpy as np
13-
from numpy.lib.stride_tricks import as_strided
1413
import scipy.sparse as sp
1514

1615
from ..base import BaseEstimator, TransformerMixin
@@ -552,14 +551,26 @@ def transform(self, y):
552551
return yt.toarray()
553552

554553
def _transform(self, y, class_mapping):
554+
"""Transforms the label sets with a given mapping
555+
556+
Parameters
557+
----------
558+
y : iterable of iterables
559+
class_mapping : Mapping
560+
Maps from label to column index in label indicator matrix
561+
562+
Returns
563+
-------
564+
y_indicator : sparse CSR matrix, shape (n_samples, n_classes)
565+
Label indicator matrix
566+
"""
555567
indices = array.array('i')
556568
indptr = array.array('i', [0])
557569
for labels in y:
558570
indices.extend(set(class_mapping[label] for label in labels))
559571
indptr.append(len(indices))
560572
# virtual array of len(indices) 1s:
561-
data = as_strided(np.array([1], dtype=int), strides=(0,),
562-
shape=(len(indices),))
573+
data = np.ones(len(indices), dtype=int)
563574
return sp.csr_matrix((data, indices, indptr),
564575
shape=(len(indptr) - 1, len(class_mapping)))
565576

0 commit comments

Comments
 (0)