forked from viggin/yan-prtools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
classf_rf_tr.m
34 lines (29 loc) · 1.06 KB
/
classf_rf_tr.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
function [model] = classf_rf_tr(X,Y,param)
%Random forest.
%
% X : each row is a sample.
% Y : a column vector, class labels for X starting from 1.
% PARAM: struct of parameters. The beginning part of this code (before
% defParam) explains each parameter, and also sets the default parameters.
% You can change parameter p to x by setting PARAM.p = x. For parameters
% that are not set, default values will be used.
% Return:
% MODEL: a struct containing coefficients.
% Dependence: RandomForest toolbox by Abhishek Jaiantilal
% https://code.google.com/p/randomforest-matlab/
%
% Ke YAN, 2016, Tsinghua Univ. http://yanke23.com, [email protected]
nTrees = 300;
mtry = floor(sqrt(size(X,2))); % number of predictors sampled for spliting at each node.
showVerboseInfo = 0;
defParam
%% matlab built-in. slow.
% b = TreeBagger(numTrees,X,Y,'Method','regression',...
% 'OOBVarImp','on');
% plot(oobError(b));
% regrs_value = predict(b,Xtest);
%% Andy Liaw et al.'s
addpath RandomForest-v0.02\RF_Class_C
opt.do_trace = showVerboseInfo;
model = classRF_train(X,Y,nTrees,mtry,opt);
end