how to calculate conditional probability

37 ビュー (過去 30 日間)
elisa ewin
elisa ewin 2017 年 7 月 19 日
編集済み: Andrei Bobrov 2017 年 7 月 19 日
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 Center および File ExchangeData Exploration についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by