2016-11-23 190 views
0

我的数据格式如下:随机森林的二进制数据

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 

我是新来的数据分析,我想知道我的分析可以在这个数据格式实现。是否有可能有随机森林和修剪树状图?

什么找到办法如何找到群/组,看到一个树状图中的列ST1,STR2,STR3等

+0

还不是很清楚。你想 (1)在每种股票类型(A,B,C)中查找集群? OR (2)在str1,str2,str3 ...中查找对应于股票标签的模式? –

+0

@sandipan这是您提到 – Jake

回答

1

试试这个,用决策树(有一些DF与100行随机生成的测试,并同样的内在张力结构):正是你想做的事

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) 

enter image description here

+0

非常感谢您的答案的第二种情况。不幸的是,我收到一个错误:在plot.new()中出现错误:图边距过大可能是因为我在df中有很多行和列。 – Jake

+0

你也可以打印树。更新我的帖子 –

+0

为你的情节边际错误看到这个:http://stackoverflow.com/questions/12766166/error-in-plot-new-figure-margins-too-large-in-r –