/*----------------------------------------------------------*/ /* Weather data set with numeric attributes */ /* T. Mitchell, Machine Learning, McGraw-Hill, 1997 */ /*----------------------------------------------------------*/ example(1, no, [outlook=sunny, temp=85,humidity=85,windy=f]). example(2, no, [outlook=sunny, temp=80,humidity=90,windy=t]). example(3, yes,[outlook=overcast,temp=83,humidity=86,windy=f]). example(4, yes,[outlook=rainy, temp=70,humidity=96,windy=f]). example(5, yes,[outlook=rainy, temp=68,humidity=80,windy=f]). example(6, no, [outlook=rainy, temp=65,humidity=70,windy=t]). example(7, yes,[outlook=overcast,temp=64,humidity=65,windy=t]). example(8, no, [outlook=sunny, temp=72,humidity=95,windy=f]). example(9, yes,[outlook=sunny, temp=69,humidity=70,windy=f]). example(10,yes,[outlook=rainy, temp=75,humidity=80,windy=f]). example(11,yes,[outlook=sunny, temp=75,humidity=70,windy=t]). example(12,yes,[outlook=overcast,temp=72,humidity=90,windy=t]). example(13,yes,[outlook=overcast,temp=81,humidity=75,windy=f]). example(14,no, [outlook=rainy, temp=71,humidity=91,windy=t]). /* Extracts from the above data provided for convinient access */ /* Nominal-only data */ nominal(1, no, [outlook=sunny, windy=f]). nominal(2, no, [outlook=sunny, windy=t]). nominal(3, yes, [outlook=overcast, windy=f]). nominal(4, yes, [outlook=rainy, windy=f]). nominal(5, yes, [outlook=rainy, windy=f]). nominal(6, no, [outlook=rainy, windy=t]). nominal(7, yes, [outlook=overcast, windy=t]). nominal(8, no, [outlook=sunny, windy=f]). nominal(9, yes, [outlook=sunny, windy=f]). nominal(10, yes, [outlook=rainy, windy=f]). nominal(11, yes, [outlook=sunny, windy=t]). nominal(12, yes, [outlook=overcast, windy=t]). nominal(13, yes, [outlook=overcast, windy=f]). nominal(14, no, [outlook=rainy, windy=t]). /*-----------------------------------------------------------*/ /* Numeric data extracted from the original set of examples */ /*-----------------------------------------------------------*/ /* temp_sample(, ) */ temp_sample([83, 70, 68, 64, 69, 75, 75, 72, 81], [85, 80, 65, 72, 71]). /* humidity_sample(, ) */ humidity_sample([86, 96, 80, 65, 70, 80, 70, 90, 75], [85, 90, 70, 95, 91]). temp(1, no, 85). temp(2, no, 80). temp(3, yes, 83). temp(4, yes, 70). temp(5, yes, 68). temp(6, no, 65). temp(7, yes, 64). temp(8, no, 72). temp(9, yes, 69). temp(10, yes, 75). temp(11, yes, 75). temp(12, yes, 72). temp(13, yes, 81). temp(14, no, 71). humidity(1, no, 85). humidity(2, no, 90). humidity(3, yes, 86). humidity(4, yes, 96). humidity(5, yes, 80). humidity(6, no, 70). humidity(7, yes, 65). humidity(8, no, 95). humidity(9, yes, 70). humidity(10, yes, 80). humidity(11, yes, 70). humidity(12, yes, 90). humidity(13, yes, 75). humidity(14, no, 91). %---------------------------------------------- % Examples of using the data set with stats.pl %---------------------------------------------- %-------------------------------------------------------- % Compute the probability density of 67 for both classes % P(67|Yes) = 0.0402995 % P(67|No) = 0.0317938 %-------------------------------------------------------- /* ?- temp_sample(Yes,No),p(67,Yes,PYes),p(67,No,PNo). Yes = [83, 70, 68, 64, 69, 75, 75, 72, 81] No = [85, 80, 65, 72, 71] PYes = 0.0402995 PNo = 0.0317938 */ %----------------------------------------------------- % Compute the probability density of values from temp %----------------------------------------------------- /* ?- temp_sample(Yes,No),temp(N,Class,X),p(X,Yes,PYes),p(X,No,PNo). Yes = [83, 70, 68, 64, 69, 75, 75, 72, 81] No = [85, 80, 65, 72, 71] N = 1 Class = no X = 85 PYes = 0.00973071 PNo = 0.0212165 ; Yes = [83, 70, 68, 64, 69, 75, 75, 72, 81] No = [85, 80, 65, 72, 71] N = 2 Class = no X = 80 PYes = 0.0339635 PNo = 0.0399971 ; ... */ % Predict and compute probabilities with nominal and mixed attributes % Note that bayes.pl works only with discrete probabilities (nominal attributes) /* ?- nominal(N,C,E),bayes(E,P),write(N-C-P),nl,fail. 1-no-yes 2-no-no 3-yes-yes 4-yes-yes 5-yes-yes 6-no-no 7-yes-yes 8-no-yes 9-yes-yes 10-yes-yes 11-yes-no 12-yes-yes 13-yes-yes 14-no-no ?- nominal(N,C,E),probs(E,P),write(N-C-P),nl,fail. 1-no-[no/0.0857143, yes/0.0952381] 2-no-[no/0.128571, yes/0.047619] 3-yes-[no/0, yes/0.190476] 4-yes-[no/0.0571429, yes/0.142857] 5-yes-[no/0.0571429, yes/0.142857] 6-no-[no/0.0857143, yes/0.0714286] 7-yes-[no/0, yes/0.0952381] 8-no-[no/0.0857143, yes/0.0952381] 9-yes-[no/0.0857143, yes/0.0952381] 10-yes-[no/0.0571429, yes/0.142857] 11-yes-[no/0.128571, yes/0.047619] 12-yes-[no/0, yes/0.0952381] 13-yes-[no/0, yes/0.190476] 14-no-[no/0.0857143, yes/0.0714286] */ % Computing probabilities with all 4 attributes (nominal and numeric) /* ?- temp_sample(TY,TN),humidity_sample(HY,HN),temp(N,C,T),humidity(N,C,H), p(T,TY,PTY),p(T,TN,PTN),p(H,HY,PHY),p(H,HN,PHN), % Compute densities nominal(N,C,E),probs(E,[no/PN,yes/PY]), % Compute discrete probs LY is PTY*PHY*PY, LN is PTN*PHN*PN, % Compute likelihoods PPY is LY/(LY+LN), PPN is LN/(LY+LN), % Normalize write(N-PPY-PPN),nl,fail. % Print 1-0.292919-0.707081 2-0.154835-0.845165 3-1-0 4-0.576106-0.423894 5-0.791622-0.208378 6-0.711311-0.288689 7-1-0 8-0.388032-0.611968 9-0.791346-0.208654 10-0.779496-0.220504 11-0.535425-0.464575 12-1-0 13-1-0 14-0.380395-0.619605 */