Class: RFModel

Inherits:
VectorModel show all
Defined in:
lib/rbbt/vector/model/random_forest.rb

Instance Attribute Summary

Attributes inherited from VectorModel

#directory, #eval_model, #extract_features, #factor_levels, #features, #labels, #model_file, #names, #train_model

Instance Method Summary collapse

Methods inherited from VectorModel

R_eval, R_run, R_train, #__load_method, #add, #add_list, #clear, #cross_validation, #eval, #eval_list, f1_metrics, #run, #save_models, #train

Constructor Details

#initialize(dir) ⇒ RFModel

Returns a new instance of RFModel.



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/rbbt/vector/model/random_forest.rb', line 3

def initialize(dir)
  super(dir)

  @extract_features = Proc.new{|element|
    element
  }

  @train_model ="rbbt.require(\"randomForest\");\nmodel = randomForest(as.factor(label) ~ ., data = features);\n  EOF\n \n  @eval_model =<<-EOF\nrbbt.require(\"randomForest\");\npred = names(model$forest$xlevels)\nfor (p in pred) { \nif (class(features[[p]]) == \"factor\") { \n    features[[p]] = factor(features[[p]], levels=model$forest$xlevels[[p]])\n  } \n}\nlabel = predict(model, features);\n  EOF\nend\n"