how to calculate conditional probability

37 次查看(过去 30 天)
Hi! I have a cell array (values, attached) that contains in the first column a series
of words and in the second, the categories in which the words are included.
I want to calculate the conditional probability: a measure of the probability of an
event given that another event has occurred.
In this example I want to know: Prob(sunny|n); Prob(sunny|y); Prob(rain|n); Prob(rain|y); Prob(overcast|n); Prob(overcast|y)
Can you help me, please?

采纳的回答

Andrei Bobrov
Andrei Bobrov 2017-7-19
编辑:Andrei Bobrov 2017-7-19
[a,~,c] = unique(values,'stable');
d = reshape(c,[],2);
dm = min(d(:,2));
ny = accumarray(d(:,2) - dm + 1,1);
[a1,~,c1] = unique(d,'rows');
P = accumarray(c1,1)./ny(a1(:,2) - dm + 1);
with use table:
T1 = table(values(:,1),values(:,2),'v',{'weather','par'});
[g,name] = findgroups(T1);
[g1,name1] = findgroups(T1.par);
[~,ii] = ismember(name.par,name1);
ny = accumarray(g1,1);
P = [name,table(accumarray(g,1)./ny(ii),'v',{'probability'})];

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Data Exploration 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by