Jake - 7 months ago 36
R Question

# Random forest for binary data

My data have the following format:

``````stock st1 str2 str3 str4 str5 str6 str7 str8
A 1 0   0   0   1   0   0   0
A 0 0   0   0   0   0   0   0
A 1 0   0   0   0   0   0   0
B 0 0   0   0   0   0   0   0
B 1 0   0   0   1   0   0   0
C 0 0   0   0   0   0   0   0
C 1 0   0   0   1   0   0   1
C 0 0   0   0   0   0   0   0
C 0 0   0   0   0   0   0   0
C 1 0   0   0   1   0   0   1
A 0 0   0   0   0   0   0   0
A 0 0   0   0   0   0   0   0
A 0 0   0   0   0   0   0   0
A 1 0   0   0   0   0   0   0
A 0 0   0   0   0   0   0   0
B 0 0   0   0   0   0   0   0
B 0 0   0   0   0   0   0   0
C 1 0   0   0   0   0   0   0
``````

I am new to data analysis and I would like to know what analysis I could implement in this data format. Is it possible to have random forest and a pruning dendogram?

what find a way how to find clusters/groups and see in a dendogram the columns st1,str2,str3 etc.

Try this, with decision tree (tested with some randomly generated df with 100 rows, with the same sturcture):

``````head(df)
stock str1 str2 str3 str4 str5 str6 str7 str8
1     B    1    0    1    0    0    0    1    0
2     B    1    1    1    1    1    1    1    1
3     A    0    1    1    1    0    0    0    0
4     B    0    0    0    1    0    1    1    0
5     C    1    0    0    0    1    1    1    0
6     B    1    1    1    1    0    0    1    1

library(rpart)
tr <- rpart(stock~., df) # you can prune this tree with the cp param / with CV

print(tr)

n= 100

node), split, n, loss, yval, (yprob)
* denotes terminal node

1) root 100 63 C (0.33000000 0.30000000 0.37000000)
2) str5=1 49 27 A (0.44897959 0.16326531 0.38775510)
4) str8=0 32 15 A (0.53125000 0.06250000 0.40625000)
8) str6=0 15  5 A (0.66666667 0.06666667 0.26666667) *
9) str6=1 17  8 C (0.41176471 0.05882353 0.52941176) *
5) str8=1 17 11 B (0.29411765 0.35294118 0.35294118) *
3) str5=0 51 29 B (0.21568627 0.43137255 0.35294118)
6) str8=0 27 12 B (0.18518519 0.55555556 0.25925926) *
7) str8=1 24 13 C (0.25000000 0.29166667 0.45833333)
14) str7=0 12  6 C (0.41666667 0.08333333 0.50000000) *
15) str7=1 12  6 B (0.08333333 0.50000000 0.41666667) *

library(rpart.plot)
prp(tr)
``````

Source (Stackoverflow)