Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/350.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Weka对Java中的tweet进行分类_Java_Twitter_Machine Learning_Classification - Fatal编程技术网

使用Weka对Java中的tweet进行分类

使用Weka对Java中的tweet进行分类,java,twitter,machine-learning,classification,Java,Twitter,Machine Learning,Classification,我有一些推特要做情绪分析。因此,我使用Twitter4J获取tweet,然后我决定使用Weka库来使用KMeans、naivebayes、SVM等方法 首先,我手动将tweets移动到文本文件中,并自己编写它们的类。这是我的训练数据。在我的代码中,我阅读了这个文件,并试图训练和测试我的模型。但是我弄错了 "Exception in thread "main" weka.core.UnsupportedAttributeTypeException: Cannot handle string att

我有一些推特要做情绪分析。因此,我使用Twitter4J获取tweet,然后我决定使用Weka库来使用KMeans、naivebayes、SVM等方法

首先,我手动将tweets移动到文本文件中,并自己编写它们的类。这是我的训练数据。在我的代码中,我阅读了这个文件,并试图训练和测试我的模型。但是我弄错了

"Exception in thread "main" weka.core.UnsupportedAttributeTypeException: Cannot handle string attributes!" 
为了修复它,我使用了StringToOrdVector过滤器,但它也不起作用。这是我的密码:

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;

import weka.classifiers.Classifier;
import weka.classifiers.Evaluation;
import weka.classifiers.bayes.NaiveBayes;
import weka.classifiers.lazy.IBk;
import weka.classifiers.meta.FilteredClassifier;
import weka.core.Attribute;
import weka.core.FastVector;
import weka.core.Instance;
import weka.core.Instances;
import weka.filters.unsupervised.attribute.StringToWordVector;

public class Driver {
    public static BufferedReader readDataFile(String filename) {
        BufferedReader inputReader = null;

        try {
            inputReader = new BufferedReader(new FileReader(filename));
        } catch (FileNotFoundException ex) {
            System.err.println("File not found: " + filename);
        }

        return inputReader;
    }

    public static void main(String[] args) throws Exception{
    BufferedReader datafile = readDataFile("file.txt");

     Instances data = new Instances(datafile);
     data.setClassIndex(data.numAttributes() - 1);



     FilteredClassifier fc = new FilteredClassifier();

     /
     Classifier cModel = (Classifier)new IBk();   

     cModel.buildClassifier(data);

     StringToWordVector swv = new StringToWordVector();
     fc.setFilter(swv);
     fc.setClassifier(cModel);


     // Test the model
     Evaluation eTest = new Evaluation(data);
     eTest.evaluateModel(cModel, data);

     // Print the result à la Weka explorer:
     String strSummary = eTest.toSummaryString();
     System.out.println(strSummary);

     // Get the confusion matrix
     double[][] cmMatrix = eTest.confusionMatrix();
     for(int row_i=0; row_i<cmMatrix.length; row_i++){
         for(int col_i=0; col_i<cmMatrix.length; col_i++){
             System.out.print(cmMatrix[row_i][col_i]);
             System.out.print("|");
         }
         System.out.println();
     }
}
}
然而,这些推特是土耳其语的。那么,你认为我走对了吗?还是我应该做更复杂的事?比如先把词干去掉,等等


如果您对我的问题有任何帮助,我们将不胜感激

阅读错误消息:

Cannot handle string attributes!
显然是指这一行:

@attribute tweetMsg string

分类器
IBk
不支持
string
属性。

我看到了,但我已经尝试过其他分类器,如Naive Bayes、J48、Logistic等。它们都不起作用。我想问的是这样做是否正确?是的,因为您没有解决string属性的问题。在训练分类器之前,需要对其进行矢量化。
@attribute tweetMsg string