我正在使用LibSVM为我的大学使用C ++支持向量机。 为此,我希望能够解析充满文档和标签的.csv文件。 这到目前为止工作得很好,但作为输出我得到
C = nan
obj = nan, rho = nan
nSV = 0, nBSV = 0
Total nSV = 0
这看起来好像没有生成好的数据。
我打赌我犯了一个初学者的错误但却无法弄清楚出了什么问题。下面显示了我如何创建节点,以及我使用的Document类,它应该被分析。
class Document {
public:
double docID;
double label;
std::string text;
Document(double docID, double label, std::string aText);
}
...
std::vector<Feature> features = getFeatures();
documents = getDocuments();
int documentCount = documents.size();
int featureCount = features.size();
svm_node** nodesList = new svm_node*[documentCount];
double* labelList = new double[documentCount];
for (int j = 0; j < documentCount; j++){
nodesList[j] = new svm_node[featureCount];
Document currentDocument = documents[j];
for (int i = 0; i < featureCount; i++) {
svm_node node;
node.index = i + 1;
node.value = features[i].analyse(currentDocument.docID);
nodesList[j][i] = node;
}
labelList[j] = currentDocument.label;
}
problem->l = documentCount;
problem->x = nodesList;
problem->y = labelList;
param->svm_type = NU_SVC;
param->kernel_type = LINEAR;
param->degree = 3;
param->gamma = 0.0625;
param->coef0 = 0;
param->nu = 0.25;
param->cache_size = 100;
param->C = 1;
param->eps = 1e-3;
param->p = 0.1;
param->shrinking = 1;
param->probability = 0;
param->nr_weight = 0;
param->weight = new double[2];
param->weight_label = new int[2];
param->weight[0] = 1;
param->weight_label[0] = 1;
param->weight[1] = 1;
param->weight_label[1] = 1;
svm_check_parameter(problem, param);
model = svm_train(problem, param);
有人知道输出无意义的原因在哪里吗?
提前谢谢!
答案 0 :(得分:0)