RF source code test in windows

1. Task: test random forest source code package 

    edited by http://blog.csdn.net/qianzhihehhjj

2. Test platform: windows 7 64bit with R 3.1.3 and visual studio 2013.

2. Prerequisite: Rtools, RF source package

    install Rtools  http://m.blog.csdn.net/article/details?id=49203569  , remember to check the 'add system path                   automatically', or you have to add it manually.

   download RF source package in https://cran.r-project.org/web/packages/randomForest/index.html . In this case, this package is put under F drive. The package name is "randomForestsr", the source code is inR andsrc folder. Details are shown below:


    3. Steps

Reference of steps: http://djmjsj.blog.163.com/blog/static/13443616320148209531654/


1) generate dll file for c and f file

Method 1: use cmd command window

different command for 32 and 64 bit


open system command prompt, set path to your package.

eg: in this case package path is F:\randomForestsr

then, your command will be:

f:
cd randomForeststsr</span>

R --arch x64 CMD SHLIB -o randomForest.dll rf.c regrf.c regTree.c classTree.c rfsub.f rfutils.c

Now the randomForest.dll is generated.

Method 2: use R

http://djmjsj.blog.163.com/blog/static/134436163201481975711228/


Method 2 is more automatic.



2) test in R 

First, for training, sourcerandomForest.R, randomForest.default.R, randomForest.formula.R.These files can be found  under folder R of the package.



Second, test  R code. Here I take one example from  http://www.bios.unc.edu/~dzeng/BIOS740/randomforest.pdf.

dyn.load('F:/randomForestsr/src/rf.dll') #load your dll file</span>


library(MASS)
data(fgl)
set.seed(17)
fgl.rf <- randomForest(type ~ ., data = fgl,mtry = 2, importance = TRUE,do.trace = 100)

#dyn.unload('F:/randomForestsr/src/rf.dll') #unload it if you use just once</span>

The result is shown as below:


Third, for predicting, same steps as training. Sourcepredict.randomForest.R first.


-----

I express my gratitude to authors of the references.




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值