Python arff中的错误输出
我正在使用Python脚本并将结果(使用ntlk计算)写入arff文件。需要进入arff文件的信息是字母和单词(没有数字)。但是,每当我运行脚本时,都会得到一个包含零的arff文件。。像这样:Python arff中的错误输出,python,arff,Python,Arff,我正在使用Python脚本并将结果(使用ntlk计算)写入arff文件。需要进入arff文件的信息是字母和单词(没有数字)。但是,每当我运行脚本时,都会得到一个包含零的arff文件。。像这样: 0,0.0,0.0,0 这是我写入arff的代码片段: for fileid in corpus.fileids(): cat = str(fileid.split('/')[0]) text = corpus.words(fileid)
0,0.0,0.0,0
这是我写入arff的代码片段:
for fileid in corpus.fileids():
cat = str(fileid.split('/')[0])
text = corpus.words(fileid)
text2 = corpus.raw(fileid)
text3 = ngrams(text2, 3)
text4 = ngrams(text2, 4)
lijst = [frequencycount(text, freq)] + [frequencycount(text3, chartrigramfreq)] + [frequencycount(text4, chartetragramfreq)]
merged = list(itertools.chain.from_iterable(lijst))
merged2 = ','.join(merged)
filet.write("%s\n" % merged2)
counter += 1
print counter, fileid, time()-tijd
filet.close()
你能修复缩进,让它显示你在脚本中看到它的方式吗?@brionius我认为这应该更好!这段代码将打印frequencycount()返回的任何内容,如果该函数返回一个数字,那么这将是打印的内容。@JohnDoe更好。能否显示脚本的输出(stdout-它打印到命令行的内容)?如果您能让它
打印文本、text2、text3、merged2
就在文件之前,这也会很有帮助。编写
语句并发布输出。您正在手动以ARFF格式编写。为什么没有使用为python编写的ARFF包。我使用了LIAC-ARFF
,易于阅读和修改。