【问题标题】:Classification of word2vec using weka使用weka对word2vec进行分类
【发布时间】:2017-07-21 09:10:36
【问题描述】:
我已经在大约 70k 个句子的语料库上训练了一个 word2vec 模型。每个句子都包含一个独特的关键字,例如“abc-2011-100”,然后是描述它的某些特征。现在,我必须为每个 abc id 进行分类。像 abc-2011-100 属于 abc_category_1。 abc-2999-0000 属于 abc_category_20 等等。一个类别可以有多个分配给它的 abc id。我有大约 70000 个唯一的 abc Id。在这 70000 个中,有 5000 个已被适当分类。现在我想检查我对已经分类的 5000 个 id 的分类准确性。为此,我将 80% 作为训练数据,20% 用于检查准确性。我可以将每个 abc id 描述为一个 d 维向量。使用这些信息,我如何使用 weka 来运行这个分类任务。?请任何输入将不胜感激。
【问题讨论】:
标签:
machine-learning
classification
weka
word2vec
multilabel-classification
【解决方案1】:
见here。
首先,读入你的 csv/arff:
import weka.core.Instances;
import java.io.BufferedReader;
import java.io.FileReader;
...
BufferedReader reader = new BufferedReader(new FileReader("yourData.arff"));
Instances data = new Instances(reader);
reader.close();
// setting class attribute
data.setClassIndex(data.numAttributes() - 1); // This is category for you
然后实例化并训练一个分类器
import weka.classifiers.trees.J48;
...
String[] options = new String[1];
options[0] = "-U"; // unpruned tree
J48 tree = new J48(); // new instance of tree
tree.setOptions(options); // set the options
tree.buildClassifier(data); // build classifier
运行交叉验证来评估学习者
import weka.classifiers.Evaluation;
import java.util.Random;
...
Evaluation eval = new Evaluation(data);
eval.crossValidateModel(tree, data, 10, new Random(1));
或者在不同的集合上进行训练和测试
import weka.core.Instances;
import weka.classifiers.Evaluation;
import weka.classifiers.trees.J48;
...
/* train and test are of type Instances (see above) */
// train classifier
Classifier cls = new J48();
cls.buildClassifier(train);
// evaluate classifier and print some statistics
Evaluation eval = new Evaluation(train);
eval.evaluateModel(cls, test);
System.out.println(eval.toSummaryString("\nResults\n======\n", false));