how to calculate conditional probability

37 Ansichten (letzte 30 Tage)
elisa ewin
elisa ewin am 19 Jul. 2017
Bearbeitet: Andrei Bobrov am 19 Jul. 2017
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?

Akzeptierte Antwort

Andrei Bobrov
Andrei Bobrov am 19 Jul. 2017
Bearbeitet: Andrei Bobrov am 19 Jul. 2017
[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'})];

Weitere Antworten (0)

Kategorien

Mehr zu Data Exploration finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by