来自 LibSVM 的无意义的输出



我正在使用 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);

有人知道输出毫无意义的原因在哪里吗?

提前谢谢你!

  1. 检查您的功能文件,一切是否井井有条? 没有 nan's、inf 或非常大的数字?
  2. 你的训练数据是有偏差的吗?即你对一个类有很多值,但对另一个类几乎没有任何值。

最新更新