【问题标题】:one valid observation in each class is required每个班级都需要一个有效的观察结果
【发布时间】:2012-11-09 22:42:44
【问题描述】:

我收到此错误:

Warning: TRAINING can only contain
non-negative integers when
'Distribution' is set to 'mn'. Rows of
TRAINING with invalid values will be
removed. 
> In NaiveBayes.fit at 317
??? Error using ==>

??? Error using ==>
NaiveBayes.fit>mnfit at 647
At least one valid observation in each
class is required.

Error in ==> NaiveBayes.fit at 496
            obj =  mnfit(obj,training,
            gindex);

这就是我所拥有的:

training_data = Testdata; 
target_class = TestDataLabels;

%# train model
nb = NaiveBayes.fit(training_data, target_class, 'Distribution', 'mn');

%# prediction
class1 = nb.predict(UnseenTestdata); 

%# performance
cmat1 = confusionmat(UnseenTestDataLabels, class1);
acc1 = 100*sum(diag(cmat1))./sum(cmat1(:));
fprintf('Classifier1:\naccuracy = %.2f%%\n', acc1);
fprintf('Confusion Matrix:\n'), disp(cmat1)

如果有人想知道,数据集是 4940201x42。

【问题讨论】:

    标签: matlab


    【解决方案1】:

    你有两个问题。

    首先,对于多项分布,MATLAB 希望您的数据具有非负整数值。其次,似乎至少对于您的某些课程,您没有任何有效的观察结果。这可能是因为 NAN、INF 或 Testdata 行中的非正值。

    实际上,正如错误所说 - “无效行将被删除”......所以我打赌无效行被删除......

    【讨论】:

    • 这是否意味着任何带小数的东西,因为我看不到任何负数,如果它们被删除为什么会抛出第二个错误?
    • “整数”通常意味着没有小数,是的:)。第二个错误是(可能)因为您不再有来自某个类的示例(target_class 的唯一值),因此分类器无事可做。
    • 啊,好吧,你认为我的选择是什么,向上和向下舍入还是删除?
    • 这取决于您的数据、应用程序等。如果您的数据不是多项式的,为什么要使用多项式分布?您可以尝试指定不同的分布。查看帮助:帮助 NaiveBayes.fit
    • 因为这篇帖子here,我已更改为多项式,它解决了我的问题,但由于预测错误,我想添加更多数据,所以我重新添加了一些额外的列。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-23
    • 2021-11-13
    • 2021-10-31
    • 1970-01-01
    • 1970-01-01
    • 2015-07-16
    相关资源
    最近更新 更多