Sha256: 1772d3c1fe0808ec09ec651087041989436f5af7bb12817e5bd95591f1102017

Contents?: true

Size: 755 Bytes

Versions: 11

Compression:

Stored size: 755 Bytes

Contents

require 'rbbt/vector/model'
class RFModel < VectorModel
  def initialize(dir)
    super(dir)

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

    @train_model =<<-EOF
rbbt.require("randomForest");
model = randomForest(as.factor(label) ~ ., data = features);
    EOF
 
    @eval_model =<<-EOF
rbbt.require("randomForest");
pred = names(model$forest$xlevels)
for (p in pred) { 
  if (is.factor(features[[p]])) { 
      features[[p]] = factor(features[[p]], levels=model$forest$xlevels[[p]])
    } 
}
label = predict(model, features);
    EOF
  end

  def importance
    TmpFile.with_file do |tmp|
      tsv = R.run <<-EOF
load(file="#{model_file}");
rbbt.tsv.write('#{tmp}', model$importance)
      EOF
      TSV.open(tmp)
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
rbbt-dm-1.2.7 lib/rbbt/vector/model/random_forest.rb
rbbt-dm-1.2.6 lib/rbbt/vector/model/random_forest.rb
rbbt-dm-1.2.4 lib/rbbt/vector/model/random_forest.rb
rbbt-dm-1.2.3 lib/rbbt/vector/model/random_forest.rb
rbbt-dm-1.2.1 lib/rbbt/vector/model/random_forest.rb
rbbt-dm-1.1.63 lib/rbbt/vector/model/random_forest.rb
rbbt-dm-1.1.62 lib/rbbt/vector/model/random_forest.rb
rbbt-dm-1.1.61 lib/rbbt/vector/model/random_forest.rb
rbbt-dm-1.1.60 lib/rbbt/vector/model/random_forest.rb
rbbt-dm-1.1.59 lib/rbbt/vector/model/random_forest.rb
rbbt-dm-1.1.58 lib/rbbt/vector/model/random_forest.rb