贝叶斯网络在Matlab(BNT)中的分类 [英] Bayes Network for classification in Matlab (BNT)

查看:193
本文介绍了贝叶斯网络在Matlab(BNT)中的分类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是交易.因此,我按照BNT手册中的说明创建了一个BN,它是洒水器,但我为冬季和夏季添加了一个节点类.像这样:

this is the deal. So I have created a BN following the instructions from the BNT manual, is the sprinkler one but I have added a node Class for Winter and Summer. Like this:

 
       Cloudy------
     /      \     |
Sprinkler   Rain  |
       \    /   | |   
        Wet     Class

仅取决于天气的类别是阴天还是下雨.具有与 http://bnt.googlecode.com/svn/相同的规范trunk/docs/usage.html#basics

Where class depends only on wether is cloudy or raining. With the same specification as http://bnt.googlecode.com/svn/trunk/docs/usage.html#basics

该类也是二进制的,表是:

And the class is also binary, the table is:


C R Class prob
---------------
1  1  1    0
2  1  1    0.4
1  2  1    0.4
2  2  1    0.9
etc.

所以我使用var_elimination_eng的问题是因为出于某种原因jtree无法正常工作,所以在输入下雨的证据后我得到了marg.T:

So my question using the var_elimination_eng because for some reason jtree is not working, I get this the marg.T after entering evidence for rainy:

ans =

 0.800000000000000
 0.200000000000000

这是正确的吗?我执行得还好吗?还是我错过了什么?谢谢.

Is this correct? Did I implemented ok? Or did I miss something? Thanks.

相同的假设1 = false =冬天,2 = true =夏天

Same assumption 1=false=Winter, 2=true=Summer

是的,类节点的CPT是8个条目

So yes the CPT of the class node is 8 entries


C R Class prob
---------------
1  1  1    0
2  1  1    0.4
1  2  1    0.4
2  2  1    0.9
1  1  2    1
2  1  2    0.6
1  2  2    0.6
2  2  2    0.6
2  2  2    0.1

这些是1-相反.代码是:

These are 1 - Oposite. The code is:

N = 5
dag = zeros(N,N)
C = 1; S = 2; R = 3; W = 4; Class = 5 
dag(C, [S R]) = 1
dag( R, W)  = 1
dag(S, W) = 1
dag(C, Class) = 1
dag(R, Class) = 1
discrete_nodes = 1:N
nodes_size = 2*ones(1,N)
bnet = mk_bnet(dag, nodes_size, names, {'Clody', 'S', 'R', 'W', 'Class'},  'discrete', discrete_nodes)
bnet.CPD{C} = tabular_CPD(bnet, C, [0.5 0.5])
bnet.CPD{R} = tabular_CPD(bnet, R, [0.8 0.2 0.2 0.8])
bnet.CPD{S} = tabular_CPD(bnet, S, [0.5 0.9 0.5 0.1]) 
bnet.CPD{W} = tabular_CPD(bnet, W, [1 0.1 0.1 0.01 0 0.9 0.9 0.99])
bnet.CPD{Class} = tabular_CPD(bnet, Class, [0 0.4 0.4 0.9 1 0.6 0.6 0.1])
evidence = cell(1, N)
evidence{R} = 2
engine = var_elim_inf_engine(bnet)
[engine loglik] = enter_evidence(engine, evidence)
marg = marginal_nodes(engine, R)
marg = marginal_nodes(engine, Class)
marg.T

这是我使用的代码,至于jtree,它给了我关于matlab的错误,该错误已经消失了,但是,我认为变量elimin在我现在阅读时更容易理解.

This is the code I used, as for the jtree, it was giving me some error on matlab which has disappeared, but, I think variable elimin is easier to understand as I'm reading it now.

谢谢.

推荐答案

在这种情况下,类别"的条件概率表(CPT)应该包含8(2 * 2 * 2)个元素.对于二进制变量,推理引擎的后输出(marg.T)似乎正确.

The conditional probability table (CPT) for 'class' should have 8 (2*2*2) elements in this case. The posterior output (marg.T) of the inference engine seems right for a binary variable.

其内容为:类节点处于0.8的概率处于状态1,概率为0.2处于状态2".从这一点开始,由用户决定是将类别"指定为状态1还是状态2.

It reads as: "with 0.8 probability the 'class' node is in state 1, and with 0.2 probability it is in state 2". From this point on, it is up to the user to decide whether to appoint 'class' to state 1 or 2.

在分类时,在最简单(但不太建议)的情况下,您可以将后验概率阈值定义为0.5并说:

When it comes to classification, in the simplest (and not very advisable) case, you can define a posterior probability threshold of 0.5 and say:

if P(class=1)> 0.5
class = 1
else
class = 2
end

在评估二进制分类的性能时,您可以查看预测精度或ROC曲线下面积(AUC)或执行

In assessing the performance of your binary classification, you can look into predictive accuracy or Area Under the ROC curve (AUC) or do more intelligent things that take into account the prior probabilities of the 'class' states.

P.S..您说联结树引擎在这种情况下不起作用,但应该起作用.您可能会遗漏一点,BNT工具箱.zip文件中应该有一个junction_tree示例(我不完全记得.m文件的名称).如果使用结点树推理引擎,您将看到与变量消除相同的答案.

P.S. You say the junction tree engine does not work in this case, but it should. You may be missing a point, there should be a junction_tree example (I don't exactly remember what the name of the .m file was) in the BNT toolbox .zip file. If you use the junction tree inference engine, you will see that you get the same answer as with variable elimination.

这篇关于贝叶斯网络在Matlab(BNT)中的分类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆