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

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

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