Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Ruby variation of the RandomForestClassifier estimator
- Loading branch information
Showing
7 changed files
with
52 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
sklearn_porter/classifier/RandomForestClassifier/templates/ruby/class.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
class {class_name} | ||
|
||
{method} | ||
|
||
end | ||
|
||
if ARGV.length == {n_features} | ||
atts = ARGV.collect {{ |i| i.to_f }} | ||
puts {class_name}.{method_name}(atts) | ||
end |
7 changes: 7 additions & 0 deletions
7
sklearn_porter/classifier/RandomForestClassifier/templates/ruby/method.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{methods} | ||
def self.{method_name} (atts) | ||
classes = Array.new({n_classes}, 0) | ||
{method_calls} | ||
pos_max = classes.each_with_index.select {{|e, i| e==classes.max}}.map &:last | ||
return pos_max.min | ||
end |
1 change: 1 addition & 0 deletions
1
sklearn_porter/classifier/RandomForestClassifier/templates/ruby/method_calls.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
idx = {class_name}.{method_name}(atts); classes[idx] = classes[idx] + 1 |
6 changes: 6 additions & 0 deletions
6
sklearn_porter/classifier/RandomForestClassifier/templates/ruby/single_method.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
def self.{method_name}_{method_id} (atts) | ||
classes = Array.new({n_classes}, 0) | ||
{tree_branches} | ||
pos_max = classes.each_with_index.select {{|e, i| e==classes.max}}.map &:last | ||
return pos_max.min | ||
end |
18 changes: 18 additions & 0 deletions
18
tests/classifier/RandomForestClassifier/RandomForestClassifierRubyTest.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
from unittest import TestCase | ||
|
||
from sklearn.ensemble import RandomForestClassifier | ||
|
||
from ..Classifier import Classifier | ||
from ...language.Ruby import Ruby | ||
|
||
|
||
class RandomForestClassifierRubyTest(Ruby, Classifier, TestCase): | ||
|
||
def setUp(self): | ||
super(RandomForestClassifierRubyTest, self).setUp() | ||
self.mdl = RandomForestClassifier(n_estimators=20, random_state=0) | ||
|
||
def tearDown(self): | ||
super(RandomForestClassifierRubyTest, self).tearDown() |