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
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.