def transform(self, X, y=None):
if self.selector == 'KeepAll':
return X
if scipy.sparse.issparse(X):
if X.getformat() == 'csr':
# convert to a csc (column) matrix, rather than a csr (row) matrix
X = X.tocsc()
# Slice that column matrix to only get the relevant columns that we already calculated in fit:
X = X[:, self.index_mask]
# convert back to a csr matrix
return X.tocsr()
# If this is a dense matrix:
else:
pruned_X = [list(itertools.compress(row, self.support_mask)) for row in X]
return pruned_X
评论列表
文章目录