Skip to main content
 首页 » 编程设计

python之如何使用 Python 库读取稀疏 ARFF 数据

2025年01月19日9mengfanrong

数据部分是这样的:{60 1,248 1,279 1,316 1}。当我使用 Python LIAC-ARFF 库时,出现如下错误:ValueError: {60 1 value not in ('0', '1')。

当我使用普通的 ARFF 文件时,它工作正常。

我正在使用 MULAN 网站上著名的 delicious.arff 数据集。

我还需要使用其他方法吗?谁能帮忙?

请您参考如下方法:

您可以使用 function scikit-multilearn provides for loading ARFF data .

使用示例 - 第一个参数是 ARFF 文件,格式是 MULAN,因此标签在末尾 (label_location="end")。 delicious 数据集中有 983 个标签,delicious 输入数据的特征是整数,输入数据已经是标称的,因为 delicious 中的输入空间是一袋词。请记住,您应该始终阅读相关论文中的数据集是什么(MULAN 网站上提供了数据集的原始论文信息):

from skmultilearn.dataset import load_from_arff 
 
X, y = load_from_arff("/home/user/data/delicious-train.arff",  
    # number of labels 
    labelcount=983,  
    # MULAN format, labels at the end of rows in arff data, using 'end' for label_location 
    # 'start' is also available for MEKA format 
    label_location='end',  
    # bag of words 
    input_feature_type='int', encode_nominal=False,  
    # sometimes the sparse ARFF loader is borked, like in delicious, 
    # scikit-multilearn converts the loaded data to sparse representations,  
    # so disabling the liac-arff sparse loader 
    # but you may set load_sparse to True if this fails 
    load_sparse=False,  
    # this decides whether to return attribute names or not, usually  
    # you don't need this 
    return_attribute_definitions=False) 

返回了什么?

>>> print(X, y) 
(<12920x500 sparse matrix of type '<type 'numpy.int64'>' with 6460000 stored elements in LInked List format>, 
<12920x983 sparse matrix of type '<type 'numpy.int64'>' with 12700360 stored elements in LInked List format>)