【问题标题】:Meaningless output from LibSVMLibSVM 的无意义输出
【发布时间】:2015-03-22 18:10:48
【问题描述】:

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

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

提前感谢您!

【问题讨论】:

    标签: c++ libsvm


    【解决方案1】:
    1. 检查您的功能文件,一切正常吗?没有 nan、inf 或非常大的数字?
    2. 您的训练数据是否存在偏差?也就是说,一个类有很多值,但另一个类几乎没有。

    【讨论】:

      猜你喜欢
      • 2015-03-09
      • 2014-01-14
      • 2014-01-11
      • 2014-09-09
      • 2015-08-20
      • 2017-09-01
      • 2012-01-08
      • 2013-05-14
      • 2016-07-24
      相关资源
      最近更新 更多