How to get number of occurrences in R for Naive Bayes Classification -
i pretty new r , trying analyse example dataset started naive bayes classification.
day outlook temperature humidity wind play 1 sunny hot high weak no 2 sunny hot high strong no 3 overcast hot high weak yes 4 rain mild high weak yes 5 rain cool normal weak yes 6 rain cool normal strong no 7 overcast cool normal strong yes 8 sunny mild high weak no 9 sunny cool normal weak yes 10 rain mild normal weak yes 11 sunny mild normal strong yes 12 overcast mild high strong yes 13 overcast hot normal weak yes 14 rain mild high strong no
i have been able use table()
function number of occurrences of each value categorical variables outlook, temperature, humidity, wind , play. proceed next stage need calculate corresponding number of occurrences of each value of categorical variables particular target class value of yes , no. example know number of occurrences of x(outlook=sunny,play=no) 2 above dataset, command should use desired result?
note: know naive bayes 1 calculates probability more interested in getting frequency in case.
are looking this:
by(df[-1], df$play, sapply, table)
? (assuming df
dataframe.)
result:
df$play: no $outlook overcast rain sunny 0 2 3 $temperature cool hot mild 1 2 2 $humidity high normal 4 1 $wind strong weak 3 2 $play no yes 5 0 ----------------------------------------------------------------------------------------------------------------------------- df$play: yes $outlook overcast rain sunny 4 3 2 $temperature cool hot mild 3 2 4 $humidity high normal 3 6 $wind strong weak 3 6 $play no yes 0 9
Comments
Post a Comment