类标签缺失 weka的StringToWordVector类解析

weka的StringToWordVector类解析

weka的StringToWordVector类可以将给定的文档格式的内容转换为vms模型的内容,而后者是文本分类必须的模块。按照weka要求,生成arff格式的文本:

 

Java代码   收藏代码
  1. @relation D__java_weka_data  
  2. @attribute text string  
  3. @attribute class {test1,test2,test3}  
  4. @data  
  5. 'here we go go go go to do ',test1  
  6. 'Mostly, I expect we are interested in indexing XPath queries',test1  
  7. 'so what do you think you can do anything?',test2  
  8. 'Sparse ARFF files are very similar to ARFF files',test3  
 

按照StringToWordVector类的命令格式,设定options:

 

Java代码   收藏代码
  1. String[] options = { "-C""-T""-i""data//train.arff""-o","data//res_train.arff""-c""last"};  

 

生成结果如下:

 

Java代码   收藏代码
  1. @relation 'D_java_weka_data-weka.filters.unsupervised.attribute.StringToWordVector-R1-W1000-prune-rate-1.0-C-T-N0-stemmerweka.core.stemmers.NullStemmer-M1-tokenizerweka.core.tokenizers.WordTokenizer -delimiters \" \\r\\n\\t.,;:\\\'\\\"()?!\"'  
  2.   
  3. @attribute class {test1,test2,test3}  
  4. @attribute I numeric  
  5. @attribute Mostly numeric  
  6. @attribute XPath numeric  
  7. @attribute are numeric  
  8. @attribute do numeric  
  9. @attribute expect numeric  
  10. @attribute go numeric  
  11. @attribute here numeric  
  12. @attribute in numeric  
  13. @attribute indexing numeric  
  14. @attribute interested numeric  
  15. @attribute queries numeric  
  16. @attribute to numeric  
  17. @attribute we numeric  
  18. @attribute anything numeric  
  19. @attribute can numeric  
  20. @attribute so numeric  
  21. @attribute think numeric  
  22. @attribute what numeric  
  23. @attribute you numeric  
  24. @attribute ARFF numeric  
  25. @attribute Sparse numeric  
  26. @attribute files numeric  
  27. @attribute similar numeric  
  28. @attribute very numeric  
  29.   
  30. @data  
  31.   
  32.   
  33. {5 0.693147,7 1.609438,8 0.693147,13 0.693147,14 0.693147}  
  34.   
  35. {1 0.693147,2 0.693147,3 0.693147,4 0.693147,6 0.693147,9 0.693147,10 0.693147,11 0.693147,12 0.693147,14 0.693147}  
  36.   
  37. {0 test2,5 1.098612,15 0.693147,16 0.693147,17 0.693147,18 0.693147,19 0.693147,20 1.098612}  
  38.   
  39. {0 test3,4 0.693147,13 0.693147,21 1.098612,22 0.693147,23 1.098612,24 0.693147,25 0.693147}  

 

可以发现在dataset中attribute-class中少了test1的label。

 

StringToWordVector类在转化过程中经历了如下的步骤:首先将文档中attribute为string的属性,按给定的tokenizer 分词,并生成m_dictionary,可以按照数字 look up word,为了保证最后attribute value的形式统一,对于attribute非string的属性,其值在设定的时候为test1:attribute value = 0; test2: attribute value = 1; test3: attribute value = 2。在转化完成之后,新生成的instance传入SparseInstance,剔除掉value = 0的元素。所以test1的属性段就被剔除了。

 

究其根本,还是instance 类在设计的时候没考虑好attribute为class的时候,在以后sparse会将其value=0的剔除.

 

Bug修补方法:

 

重写SparseInstance方法,指定attribute.value(0)的字段不做sparse,当然这只是暂时的策略,最根本的还是要修改instance类中attribute value的赋值方法,但由于instance类是Weka中核心类,改起来牵扯的地方太多,还是这个方便点。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值