|
10 | 10 | import array
|
11 | 11 |
|
12 | 12 | import numpy as np
|
13 |
| -from numpy.lib.stride_tricks import as_strided |
14 | 13 | import scipy.sparse as sp
|
15 | 14 |
|
16 | 15 | from ..base import BaseEstimator, TransformerMixin
|
@@ -552,14 +551,26 @@ def transform(self, y):
|
552 | 551 | return yt.toarray()
|
553 | 552 |
|
554 | 553 | 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 | + """ |
555 | 567 | indices = array.array('i')
|
556 | 568 | indptr = array.array('i', [0])
|
557 | 569 | for labels in y:
|
558 | 570 | indices.extend(set(class_mapping[label] for label in labels))
|
559 | 571 | indptr.append(len(indices))
|
560 | 572 | # 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) |
563 | 574 | return sp.csr_matrix((data, indices, indptr),
|
564 | 575 | shape=(len(indptr) - 1, len(class_mapping)))
|
565 | 576 |
|
|
0 commit comments