拨浪鼓将字符串加载到WEKA的矢量文件中

时间:2011-08-04 15:02:30

标签: r file-io machine-learning weka text-mining

我一直在使用WEKA做一些文本分类工作,我想尝试一下 出R。

问题是我无法将String加载到由其创建的Vector ARFF文件中 WEKA的字符串解析器进入Rattle。

查看日志我得到类似的内容:

/Error in scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings,

: scan() expected 'a real', got '2281}'/

我的ARFF数据文件看起来有点像这样:

@relation 'reviewData'

@attribute polarity {0,2}
.....
@attribute $$ numeric
@attribute we numeric
@attribute wer numeric
@attribute win numeric
@attribute work numeric

@data
{0 2,63 1,71 1,100 1,112 1,140 1,186 1,228 1}
{14 1,40 1,48 1,52 1,61 1,146 1}
{2 1,41 1,43 1,57 1,71 1,79 1,106 1,108 1,133 1,146 1,149 1,158 1,201 1}
{0 2,6 1,25 1,29 1,42 1,49 1,69 1,82 1,108 1,116 1,138 1,140 1,155 1}
..../

我是如何将其转换为R可读格式的?

干杯!

1 个答案:

答案 0 :(得分:0)

保存StringToWordVector属性过滤器的结果后,它将保存为sparse ARFF文件。

您需要检查Rattle是否支持阅读此格式。如果没有,您可以应用SparseToNonSparse实例过滤器,它会将其转换为密集矩阵格式(文件大小会大得多)。

示例:如果稀疏数据如下:

sparse.arff

@relation name
@attribute word1 numeric
@attribute word2 numeric
..
@attribute word10 numeric
@data
{0 1,3 3,8 1,9 1}
{2 2,5 1,8 1,9 1}

它将转换为:

nonsparse.arff

@relation name
@attribute word1 numeric
@attribute word2 numeric
..
@attribute word10 numeric
@data
1,0,0,3,0,0,0,0,1,1
0,0,2,0,0,1,0,0,1,1