-
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.
Duplicate templates for the ExtraTreesClassifier
- Loading branch information
Darius Morawiec
committed
Oct 31, 2017
1 parent
407c505
commit a17c77c
Showing
29 changed files
with
129 additions
and
67 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
2 changes: 1 addition & 1 deletion
2
...traTreesClassifier/templates/c/method.txt → ...lassifier/templates/c/embedded.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
1 change: 1 addition & 0 deletions
1
...rn_porter/estimator/classifier/ExtraTreesClassifier/templates/c/embedded.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 @@ | ||
classes[{method_name}(features)]++; |
2 changes: 1 addition & 1 deletion
2
...sClassifier/templates/c/single_method.txt → ...er/templates/c/embedded.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
1 change: 0 additions & 1 deletion
1
sklearn_porter/estimator/classifier/ExtraTreesClassifier/templates/c/method_calls.txt
This file was deleted.
Oops, something went wrong.
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
2 changes: 1 addition & 1 deletion
2
...TreesClassifier/templates/java/method.txt → ...sifier/templates/java/embedded.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
1 change: 1 addition & 0 deletions
1
...porter/estimator/classifier/ExtraTreesClassifier/templates/java/embedded.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 @@ | ||
classes[{class_name}.{method_name}(features)]++; |
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
1 change: 0 additions & 1 deletion
1
sklearn_porter/estimator/classifier/ExtraTreesClassifier/templates/java/method_calls.txt
This file was deleted.
Oops, something went wrong.
63 changes: 58 additions & 5 deletions
63
sklearn_porter/estimator/classifier/ExtraTreesClassifier/templates/js/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 |
---|---|---|
@@ -1,13 +1,66 @@ | ||
var {class_name} = function() {{ | ||
var {class_name} = function(data) {{ | ||
|
||
{method} | ||
var Tree = function(lChilds, rChilds, thresholds, indices, classes) {{ | ||
this.lChilds = lChilds; | ||
this.rChilds = rChilds; | ||
this.thresholds = thresholds; | ||
this.indices = indices; | ||
this.classes = classes; | ||
|
||
this.predict = function(features, node) {{ | ||
if (this.thresholds[node] != -2) {{ | ||
if (features[this.indices[node]] <= this.thresholds[node]) {{ | ||
return this.predict(features, this.lChilds[node]); | ||
}} else {{ | ||
return this.predict(features, this.rChilds[node]); | ||
}} | ||
}} | ||
return findMax(this.classes[node]); | ||
}}; | ||
}}; | ||
|
||
var findMax = function(nums) {{ | ||
var index = 0; | ||
for (var i = 0; i < nums.length; i++) {{ | ||
index = nums[i] > nums[index] ? i : index; | ||
}} | ||
return index; | ||
}}; | ||
|
||
this.trees = Array(); | ||
for (var i = 0; i < data.length; i++) {{ | ||
var tree = new Tree(data[i]['left_childs'], data[i]['right_childs'], | ||
data[i]['thresholds'], data[i]['indices'], | ||
data[i]['classes']); | ||
this.trees.push(tree); | ||
}} | ||
|
||
this.{method_name} = function(features) {{ | ||
var nClasses = this.trees[0].classes.length; | ||
var classes = new Array(nClasses).fill(0); | ||
for (var i = 0; i < trees.length; i++) {{ | ||
classes[trees[i].predict(features)]++; | ||
}} | ||
return findMax(classes); | ||
}}; | ||
|
||
}}; | ||
|
||
if (typeof process !== 'undefined' && typeof process.argv !== 'undefined') {{ | ||
if (process.argv.length - 2 == {n_features}) {{ | ||
var argv = process.argv.slice(2); | ||
var prediction = new {class_name}().{method_name}(argv); | ||
if (process.argv.length - 2 === {n_features}) {{ | ||
|
||
// Features: | ||
var features = process.argv.slice(2); | ||
|
||
// Parameters: | ||
var data = [ | ||
{model_data} | ||
]; | ||
|
||
// Prediction: | ||
var clf = new {class_name}(data); | ||
var prediction = clf.{method_name}(features); | ||
console.log(prediction); | ||
|
||
}} | ||
}} |
28 changes: 28 additions & 0 deletions
28
sklearn_porter/estimator/classifier/ExtraTreesClassifier/templates/js/embedded.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,28 @@ | ||
var {class_name} = function() {{ | ||
|
||
var findMax = function(nums) {{ | ||
var index = 0; | ||
for (var i = 0; i < nums.length; i++) {{ | ||
index = nums[i] > nums[index] ? i : index; | ||
}} | ||
return index; | ||
}}; | ||
|
||
var trees = new Array(); | ||
|
||
{method} | ||
|
||
}}; | ||
|
||
if (typeof process !== 'undefined' && typeof process.argv !== 'undefined') {{ | ||
if (process.argv.length - 2 == {n_features}) {{ | ||
|
||
// Features: | ||
var features = process.argv.slice(2); | ||
|
||
// Prediction: | ||
var prediction = new {class_name}().{method_name}(features); | ||
console.log(prediction); | ||
|
||
}} | ||
}} |
8 changes: 8 additions & 0 deletions
8
sklearn_porter/estimator/classifier/ExtraTreesClassifier/templates/js/embedded.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,8 @@ | ||
{methods} | ||
this.{method_name} = function(features) {{ | ||
var classes = new Array({n_classes}).fill(0); | ||
for (var i = 0; i < trees.length; i++) {{ | ||
classes[trees[i](features)]++; | ||
}} | ||
return findMax(classes); | ||
}} |
1 change: 1 addition & 0 deletions
1
...n_porter/estimator/classifier/ExtraTreesClassifier/templates/js/embedded.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 @@ | ||
classes[{method_name}(features)]++; |
6 changes: 6 additions & 0 deletions
6
..._porter/estimator/classifier/ExtraTreesClassifier/templates/js/embedded.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 @@ | ||
trees.push(function(features) {{ | ||
var classes = new Array({n_classes}); | ||
{tree_branches} | ||
|
||
return findMax(classes); | ||
}}); |
20 changes: 0 additions & 20 deletions
20
sklearn_porter/estimator/classifier/ExtraTreesClassifier/templates/js/method.txt
This file was deleted.
Oops, something went wrong.
1 change: 0 additions & 1 deletion
1
sklearn_porter/estimator/classifier/ExtraTreesClassifier/templates/js/method_calls.txt
This file was deleted.
Oops, something went wrong.
12 changes: 0 additions & 12 deletions
12
sklearn_porter/estimator/classifier/ExtraTreesClassifier/templates/js/single_method.txt
This file was deleted.
Oops, something went wrong.
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
...aTreesClassifier/templates/php/method.txt → ...ssifier/templates/php/embedded.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
1 change: 1 addition & 0 deletions
1
..._porter/estimator/classifier/ExtraTreesClassifier/templates/php/embedded.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 @@ | ||
$classes[{class_name}::{method_name}($features)]++; |
2 changes: 1 addition & 1 deletion
2
...lassifier/templates/php/single_method.txt → .../templates/php/embedded.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
1 change: 0 additions & 1 deletion
1
sklearn_porter/estimator/classifier/ExtraTreesClassifier/templates/php/method_calls.txt
This file was deleted.
Oops, something went wrong.
10 changes: 0 additions & 10 deletions
10
sklearn_porter/estimator/classifier/ExtraTreesClassifier/templates/ruby/class.txt
This file was deleted.
Oops, something went wrong.
10 changes: 10 additions & 0 deletions
10
sklearn_porter/estimator/classifier/ExtraTreesClassifier/templates/ruby/embedded.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} | ||
features = ARGV.collect {{ |i| i.to_f }} | ||
puts {class_name}.{method_name}(features) | ||
end |
2 changes: 1 addition & 1 deletion
2
...TreesClassifier/templates/ruby/method.txt → ...sifier/templates/ruby/embedded.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
1 change: 1 addition & 0 deletions
1
...porter/estimator/classifier/ExtraTreesClassifier/templates/ruby/embedded.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}(features); classes[idx] = classes[idx] + 1 |
2 changes: 1 addition & 1 deletion
2
...assifier/templates/ruby/single_method.txt → ...templates/ruby/embedded.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
1 change: 0 additions & 1 deletion
1
sklearn_porter/estimator/classifier/ExtraTreesClassifier/templates/ruby/method_calls.txt
This file was deleted.
Oops, something went wrong.