-
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 PHP variation of the RandomForestClassifier estimator
- Loading branch information
Darius Morawiec
committed
Sep 26, 2017
1 parent
db63686
commit faac38d
Showing
7 changed files
with
82 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
14 changes: 14 additions & 0 deletions
14
sklearn_porter/classifier/RandomForestClassifier/templates/php/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,14 @@ | ||
<?php | ||
|
||
class {class_name} {{ | ||
|
||
{method} | ||
|
||
}} | ||
|
||
if ($argc > 1) {{ | ||
array_shift($argv); | ||
$prediction = {class_name}::{method_name}($argv); | ||
fwrite(STDOUT, $prediction); | ||
exit(0); | ||
}} |
15 changes: 15 additions & 0 deletions
15
sklearn_porter/classifier/RandomForestClassifier/templates/php/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,15 @@ | ||
{methods} | ||
public static function {method_name}($atts) {{ | ||
$n_classes = {n_classes}; | ||
$classes = array_fill(0, $n_classes, 0); | ||
{method_calls} | ||
$class_idx = 0; | ||
$class_val = $classes[0]; | ||
for ($i = 0; $i < $n_classes; $i++) {{ | ||
if ($classes[$i] > $class_val) {{ | ||
$class_idx = $i; | ||
$class_val = $classes[$i]; | ||
}} | ||
}} | ||
return $class_idx; | ||
}} |
1 change: 1 addition & 0 deletions
1
sklearn_porter/classifier/RandomForestClassifier/templates/php/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}($atts)]++; |
14 changes: 14 additions & 0 deletions
14
sklearn_porter/classifier/RandomForestClassifier/templates/php/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,14 @@ | ||
public static function {method_name}_{method_id}($atts) {{ | ||
$n_classes = {n_classes}; | ||
$classes = array_fill(0, $n_classes, 0); | ||
{tree_branches} | ||
$class_idx = 0; | ||
$class_val = $classes[0]; | ||
for ($i = 0; $i < $n_classes; $i++) {{ | ||
if ($classes[$i] > $class_val) {{ | ||
$class_idx = $i; | ||
$class_val = $classes[$i]; | ||
}} | ||
}} | ||
return $class_idx; | ||
}} |
27 changes: 27 additions & 0 deletions
27
tests/classifier/RandomForestClassifier/RandomForestClassifierPHPTest.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,27 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
import unittest | ||
from unittest import TestCase | ||
|
||
from sklearn.ensemble import RandomForestClassifier | ||
|
||
from ..Classifier import Classifier | ||
from ...language.PHP import PHP | ||
|
||
|
||
class RandomForestClassifierPHPTest(PHP, Classifier, TestCase): | ||
|
||
def setUp(self): | ||
super(RandomForestClassifierPHPTest, self).setUp() | ||
self.mdl = RandomForestClassifier(n_estimators=100, random_state=0) | ||
|
||
def tearDown(self): | ||
super(RandomForestClassifierPHPTest, self).tearDown() | ||
|
||
@unittest.skip('The generated code would be too large.') | ||
def test_existing_features_w_digits_data(self): | ||
pass | ||
|
||
@unittest.skip('The generated code would be too large.') | ||
def test_random_features_w_digits_data(self): | ||
pass |