繁体   English   中英

了解scikit-learn中的数据格式

[英]Understanding format of data in scikit-learn

我正在尝试在Python 3.x中使用scikit-learn处理多标签文本分类。 我有libsvm格式的数据,正在使用load_svmlight_file模块加载。 数据格式是这样的。

  • 314523,165538,76255 1:1 2:1 3:1 4:1 5:1 6:1 7:1 8:1 9:1 10:1 11:1 12:2 13:1
  • 410523,230296,368303,75145 8:1 19:2 22:1 24:1 29:1 63:1 68:1 69:3 76:1 82:1 83:1 84:1

这些行中的每一行对应一个文档。 前三个数字是标签,接下来的条目是要素编号及其值。 每个特征对应一个词。

我正在使用此脚本加载数据。

from sklearn.datasets import load_svmlight_file

X,Y = load_svmlight_file("train.csv", multilabel = True, zero_based = True)

我的问题是,当我通过执行诸如print (X[0])查看数据格式时,得到了此输出。

(0,1)1.0

(0,2)1.0

(0,3)1.0

(0,4)1.0

(0,5)1.0

(0,6)1.0

(0,7)1.0

(0,8)1.0

(0,9)1.0

(0,10)1.0

(0,11)1.0

(0,12)2.0

(0,13)1.0

我不了解这种格式的含义。 格式不应该是这样的。

> 1  2  3  4  5  6  7  8  9  10  11  12  13

> 1  1  1  1  1  1  1  1  1   1   1   2   1

我是scikit的新手。 我希望在这方面有所帮助。

这与多标签分类本身无关。 您从load_svmlight_file获得的特征矩阵XSciPy CSR矩阵 ,如文档中所述,并且它们以一种非常不幸的格式打印:

>>> from scipy.sparse import csr_matrix
>>> X = csr_matrix([[0, 0, 1], [2, 3, 0]])
>>> X
<2x3 sparse matrix of type '<type 'numpy.int64'>'
    with 3 stored elements in Compressed Sparse Row format>
>>> X.toarray()
array([[0, 0, 1],
       [2, 3, 0]])
>>> print(X)
  (0, 2)    1
  (1, 0)    2
  (1, 1)    3

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM