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?
댓글 수: 0
채택된 답변
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
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Exploration에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!