I'm new to R and to RPy. I'm trying to use the RPart module in R to make a 
classification tree. 
I think I've managed to compute the tree but now I need to use the results in 
my Python program. I need to be able to traverse the tree. I've already spent 3 
days on it with little progress and need to get it done by monday.  I would 
appreciate some help with this. Here's the Python program I have so far: The 
toy example has y as the dependent variable and x1, x2 as the explanatory ones.

    import rpy
    rpy.r.library("rpart")
    
    y=[5,6,5.1,6.1,4.9,5.9,5.2,6.2]
    x1=['A','B','A','B','A','B','A','B']
    x2=[2,3,2,3,2,3,2,3]
    
    rpy.r.assign('y',y)
    rpy.r.assign('x1',x1)
    rpy.r.assign('x2',x2)
    
    rpy.r('gdata=data.frame(y=y,x1=x1,x2=x2)')
    
    fit = rpy.r.rpart(formula='y ~ x1 + x2 ')
    print fit
------------------------------------------------------------------------------------------------------------------------
The output is:

{'control': {'cp': 0.01, 'minsplit': 20.0, 'surrogatestyle': 0.0, 
'usesurrogate': 2.0, 'maxdepth': 30.0, 'xval': 10.0, 'maxsurrogate': 5.0, 
'maxcompete': 4.0, 'minbucket': 7.0}, 'functions': {'text': <Robj object at 
0x0047B2C0>, 'summary': <Robj object at 0x0047B2B0>}, 'terms': <Robj object at 
0x0047B2A0>, 'cptable': array([[ 0.01,  0.  ,  1.  ]]), 'parms': 0.0, 'frame': 
{'nsurrogate': 0, 'yval': 5.5499999999999998, 'dev': 2.0999999999999996, 'n': 
8, 'complexity': 0.01, 'wt': 8.0, 'var': '<leaf>', 'ncompete': 0.0}, 'call': 
<Robj object at 0x0047B290>, 'y': {'1': 5.0, '3': 5.0999999999999996, '2': 6.0, 
'5': 4.9000000000000004, '4': 6.0999999999999996, '7': 5.2000000000000002, '6': 
5.9000000000000004, '8': 6.2000000000000002}, 'ordered': {'x2': False, 'x1': 
False}, 'where': {'1': 1, '3': 1, '2': 1, '5': 1, '4': 1, '7': 1, '6': 1, '8': 
1}, 'method': 'anova'}
-------------------------------------------------------------------------------------------------------------------------

Besides traversing the tree, I'd like to know how to read in the data from a 
csv file.

Thanks!






      
____________________________________________________________________________________
Be a better friend, newshound, and 
know-it-all with Yahoo! Mobile.  Try it now.  
http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ
-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference 
Don't miss this year's exciting event. There's still time to save $100. 
Use priority code J8TL2D2. 
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
rpy-list mailing list
rpy-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rpy-list

Reply via email to