-
Notifications
You must be signed in to change notification settings - Fork 170
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 decision tree classifier
- Loading branch information
Darius Morawiec
committed
Sep 25, 2017
1 parent
a9e8a96
commit a404c4f
Showing
5 changed files
with
48 additions
and
3 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
8 changes: 8 additions & 0 deletions
8
sklearn_porter/classifier/DecisionTreeClassifier/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,8 @@ | ||
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/DecisionTreeClassifier/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 @@ | ||
def self.{method_name} (atts) | ||
classes = Array.new({n_classes}, 0) | ||
{branches} | ||
|
||
pos = classes.each_with_index.select {{|e, i| e==classes.max}}.map &:last | ||
return pos.min | ||
end |
18 changes: 18 additions & 0 deletions
18
tests/classifier/DecisionTreeClassifier/DecisionTreeClassifierRubyTest.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.tree import DecisionTreeClassifier | ||
|
||
from ..Classifier import Classifier | ||
from ...language.Ruby import Ruby | ||
|
||
|
||
class DecisionTreeClassifierRubyTest(Ruby, Classifier, TestCase): | ||
|
||
def setUp(self): | ||
super(DecisionTreeClassifierRubyTest, self).setUp() | ||
self.mdl = DecisionTreeClassifier(random_state=0) | ||
|
||
def tearDown(self): | ||
super(DecisionTreeClassifierRubyTest, self).tearDown() |