ImportError: 未找到名为arff的模块

这里有一个简单的代码示例,来自于这个链接,用于在Python中读取arff文件(注释掉的那个代码也不起作用):

import arfffor row in arff.load('heart_train.arff'):        print(row.sex)  

这是我收到的错误信息:

python id3.py Traceback (most recent call last):  File "id3.py", line 1, in <module>    import arffImportError: No module named arff

“heart_train” arff文件数据如下所示:

@relation cleveland-14-heart-disease@attribute 'age' real@attribute 'sex' { female, male}@attribute 'cp' { typ_angina, asympt, non_anginal, atyp_angina}@attribute 'trestbps' real@attribute 'chol' real@attribute 'fbs' { t, f}@attribute 'restecg' { left_vent_hyper, normal, st_t_wave_abnormality}@attribute 'thalach' real@attribute 'exang' { no, yes}@attribute 'oldpeak' real@attribute 'slope' { up, flat, down}@attribute 'ca' real@attribute 'thal' { fixed_defect, normal, reversable_defect}@attribute 'class' { negative, positive}@data63,male,typ_angina,145,233,t,left_vent_hyper,150,no,2.3,down,0,fixed_defect,negative37,male,non_anginal,130,250,f,normal,187,no,3.5,down,0,normal,negative41,female,atyp_angina,130,204,f,left_vent_hyper,172,no,1.4,up,0,normal,negative56,male,atyp_angina,120,236,f,normal,178,no,0.8,up,0,normal,negative57,female,asympt,120,354,f,normal,163,yes,0.6,up,0,normal,negative57,male,asympt,140,192,f,normal,148,no,0.4,flat,0,fixed_defect,negative...

回答:

您应该将脚本从arff.py重命名为其他名称,例如arfftest.py。因为Python无法导入您需要的arff模块,原因是它的名称与您的应用程序文件名相同。

如果您尚未安装arff包本身,请使用pip或easy_install进行安装:

pip install arff# or easy_install arff# or pypm install arff

Related Posts

L1-L2正则化的不同系数

我想对网络的权重同时应用L1和L2正则化。然而,我找不…

使用scikit-learn的无监督方法将列表分类成不同组别,有没有办法?

我有一系列实例,每个实例都有一份列表,代表它所遵循的不…

f1_score metric in lightgbm

我想使用自定义指标f1_score来训练一个lgb模型…

通过相关系数矩阵进行特征选择

我在测试不同的算法时,如逻辑回归、高斯朴素贝叶斯、随机…

可以将机器学习库用于流式输入和输出吗?

已关闭。此问题需要更加聚焦。目前不接受回答。 想要改进…

在TensorFlow中,queue.dequeue_up_to()方法的用途是什么?

我对这个方法感到非常困惑,特别是当我发现这个令人费解的…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注