【问题标题】:Rattle loading String to Vector file from WEKA拨浪鼓将字符串从 WEKA 加载到矢量文件
【发布时间】:2011-08-04 15:02:30
【问题描述】:

一直在用WEKA做一些文本分类的工作,想试试 出R。

问题是我无法将字符串加载到由创建的 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 可读格式?

干杯!

【问题讨论】:

  • 您是否尝试过使用read.arff 命令?
  • 这是 RWeka 包中的 read.arff 函数。 install.packages("RWeka") 应该安装它。
  • @Spacedman - 在foreign 中也有一个,并且查看源代码它们看起来并不完全相同。不过,我也没有使用过,所以我无法评论哪个更可取。
  • 你右边的Rattle好像用了外国包里的read.arff。反正有没有强制它在 RWeka 中使用 read.arff ?我尝试加载 RWeka lib 并分离外部但没有运气,R 只是重新附加外部

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


【解决方案1】:

当您保存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

【讨论】:

  • 感谢这项工作,但是加载大量文件非常痛苦。有什么解决办法吗?
  • @NightWol:由于稀疏的 ARFF 格式很简单,您可以自己在 R 中解析文件,并将其存储在 sparse matrix
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-05-16
  • 1970-01-01
  • 2016-07-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多