我正在使用 java libsvm,我创建了我的模型,现在我想用字符串数组来评估它,我已经为双精度数组完成了
但我不知道如何评估字符串数组,我希望有人能帮助我
提前致谢,
此代码适用于双打数组
private double evaluate(Neighbor features, svm_model model) {
svm_node[] nodes = new svm_node[features.getDocument().getAttributes().size()];
Iterator<String> iteraitor = features.getDocument().getAttributes().keySet().iterator();
int i = 0;
while (iteraitor.hasNext()) {
svm_node node = new svm_node();
node.index = i;
String key = (String) iteraitor.next();
node.value = (features.getDocument().getAttributes().get(key));
nodes[i] = node;
i++;
}
int totalClasses = 2;
int[] labels = new int[totalClasses];
svm.svm_get_labels(model, labels);
double[] prob_estimates = new double[totalClasses];
double v = svm.svm_predict_probability(model, nodes, prob_estimates);
for (int j = 0; j < totalClasses; j++) {
System.out.print("(" + labels[j] + ":" + prob_estimates[j] + ")");
}
// System.out.println("(Actual:" + features[0] + " Prediction:" + v + ")");
return v;
}