如何将参数传递给“Matlab Weka接口”

时间:2012-11-20 13:28:08

标签: matlab options weka

我已经从here安装了“Matlab Weka Interface”。我使用BayesNet的代码如下,但它会引发异常。请帮我解释如何通过选项。

代码:

    try
    classifierNo=classifierNo+1;
    wekaClassifierName = 'bayes.BayesNet';
    wekaClassifierConfig = {'-D -Q weka.classifiers.bayes.net.search.local.K2 -- -P 1 -S BAYES -E weka.classifiers.bayes.net.estimate.SimpleEstimator -- -A 0.5'};

    for i = 1:10
        test = (indices == i); 
        train = ~test;
        testSize = sum(test);

        if testOriginal==0
            train = [num2cell(mskMat(train,:)),irisLabels(train,:)];
            test  = [num2cell(global_origMat(test,:)),irisLabels(test,:)];

            %Convert to weka format
            train = matlab2weka('iTrain',featureNames,train,classIndex);
            test =  matlab2weka('iTest',featureNames,test);

            %Train the classifier
            nb = trainWekaClassifier(train,wekaClassifierName,wekaClassifierConfig);

            %Test the classifier
            predicted = wekaClassify(test,nb);

            %The actual class labels (i.e. indices thereof)
            actual = test.attributeToDoubleArray(classIndex-1); 

            correctRate = sum(actual == predicted)/testSize;
        else
            train = [num2cell(global_origMat(train,:)),irisLabels(train,:)];
            test  = [num2cell(global_origMat(test,:)),irisLabels(test,:)];

            %Convert to weka format
            train = matlab2weka('iTrain',featureNames,train,classIndex);
            test =  matlab2weka('iTest',featureNames,test);

            %Train the classifier
            nb = trainWekaClassifier(train,wekaClassifierName,wekaClassifierConfig);

            %Test the classifier
            predicted = wekaClassify(test,nb);

            %The actual class labels (i.e. indices thereof)
            actual = test.attributeToDoubleArray(classIndex-1); 

            correctRate = sum(actual == predicted)/testSize;
        end
    end

    fprintf ('%f \n\t\t\t\t\t\t',correctRate);
    sumCorrect(classifierNo)=sumCorrect(classifierNo)+correctRate;
    repeatClassifier(classifierNo) = repeatClassifier(classifierNo) + 1;
end

错误如下:

Error using weka.classifiers.bayes.BayesNet/setOptions
Java exception occurred:
java.lang.Exception: Illegal options: -D -Q weka.classifiers.bayes.net.search.local.K2 -- -P 1 -S BAYES -E
weka.classifiers.bayes.net.estimate.SimpleEstimator -- -A 0.5

    at weka.core.Utils.checkForRemainingOptions(Utils.java:482)

    at weka.classifiers.bayes.BayesNet.setOptions(BayesNet.java:510)"

1 个答案:

答案 0 :(得分:0)

错误表示您使用变量wekaClassifierConfig中的无效参数传递。我不熟悉这个包,所以我不知道哪个参数是坏的,我首先回到文档或逐个删除参数,看看哪一个导致错误。