2014-03-27 67 views
0

我一直在嘗試使用斯坦福Weka的MISVM。不過,我不斷收到錯誤無法處理數字屬性weka svm

@relation 'SpamDetectionTrainingSet' 
@attribute 'checkin' real 
@attribute 'tips' real 
@attribute 'badges' real 
@attribute 'friends' real 
@attribute 'mayors' real 
@attribute 'lists' real 
@attribute 'target' {'spam','nonspam'} 
@data 
1165,36,1,1,4,47,nonspam 
8521,492,620,7,74,144,nonspam 
5408,189,306,0,27,121,nonspam 
0,43,319,0,0,0,spam 

我已經看到了前面的問題解決方案

weka.classifiers.mi.MISVM: Cannot handle numeric attributes!

我的訓練集文件(file.arff)。一個要點,我從他們觀察到的是保持名義上的target attribute。我的目標屬性是標稱只有

我的源代碼

import weka.core.Instances; 
import weka.core.Utils; 
import weka.core.converters.ConverterUtils.DataSink; 
import weka.core.converters.ConverterUtils.DataSource; 
public class SVM 
{ 
    /* Read the Data in ARFF format */ 
    DataSource train,unknown,test; 
    Instances trainData,unknownData; 
    public SVM() 
    { 
     try { 
      /* Loading the Data */ 
      train  = new DataSource("/home/hduser/file.arff"); 
      trainData = train.getDataSet(); 
      trainData.setClassIndex(trainData.numAttributes()-1); 

      /* Set Option for SVM Algorithm */ 
      String[] opt = Utils.splitOptions("-N 1 -D"); 

      /*Training */ 
      weka.classifiers.mi.MISVM rf = new weka.classifiers.mi.MISVM(); 

      rf.setOptions(opt); 
      System.out.println(rf.getFilterType()); 

      rf.buildClassifier(trainData); 

      /* Classify Users */ 
      unknown  = new DataSource("/home/hduser/fileTest1.arff"); 
      unknownData = unknown.getDataSet(); 
      unknownData.setClassIndex(unknownData.numAttributes()-1); 

      Instances copy = new Instances(unknownData); 

      for(int i=0;i<unknownData.numInstances();i++) 
      { 
       System.out.println("Hello "); 
       double value = rf.classifyInstance(unknownData.instance(i)); 
       copy.instance(i).setClassValue(value); 
      } 

      DataSink.write("/home/hduser/output1.arff", copy); 
     } 
     catch (Exception e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } 
    } 
    public static void main(String[] args) 
    { 
     SVM r = new SVM(); 
    } 
} 

完整的錯誤信息:

weka.core.UnsupportedAttributeTypeException: weka.classifiers.mi.MISVM: Cannot handle numeric attributes! 
    at weka.core.Capabilities.test(Capabilities.java:954) 
    at weka.core.Capabilities.test(Capabilities.java:869) 
    at weka.core.Capabilities.test(Capabilities.java:1085) 
    at weka.core.Capabilities.test(Capabilities.java:1023) 
    at weka.core.Capabilities.testWithFail(Capabilities.java:1302) 
    at weka.classifiers.mi.MISVM.buildClassifier(MISVM.java:607) 
    at SVM.<init>(SVM.java:28) 
    at SVM.main(SVM.java:53) 

回答

1

的問題是file.arff:

@data 
1165,36,1,1,4,47,nonspam 
8521,492,620,7,74,144,nonspam 
5408,189,306,0,27,121,nonspam 
0,43,319,0,0,0,spam 

不能有數字值。

更改數據集,或更改分類器