将numpy稀疏矩阵转储到libsvm后,形状不一样

问题描述 投票:1回答:1

我具有以libsvm格式转储的numpy稀疏矩阵。 VC是使用CountVectorizer创建的,其中词汇表的大小为85731vc <1315689x85731 sparse matrix of type '<type 'numpy.int64'>' with 38911625 stored elements in Compressed Sparse Row format>

但是当我重新加载libsvm文件时,我看到形状有所不同。两列不见了:data[0] <1315689x85729 sparse matrix of type '<type 'numpy.float64'>' with 38911625 stored elements in Compressed Sparse Row format>

我不知道为什么会这样?我还将VC稀疏矩阵加载为dmatrix。同一期2栏消失。

希望有更多经验的人可以指出问题。

谢谢

python numpy scikit-learn libsvm sklearn-pandas
1个回答
0
投票

我怀疑您的最后两列仅包含0。加载libsvm文件时,它通常没有任何指示列数的内容。它是col_num:val的稀疏格式,将通过观察到的最高列数来学习最大列数。如果最后两列中只有0,那么在此转换中它们将被删除。

© www.soinside.com 2019 - 2024. All rights reserved.