Skip to content

Commit

Permalink
Merge pull request #2566 from thocevar/tree
Browse files Browse the repository at this point in the history
[FIX] Tree: Reintroduce preprocessors.
  • Loading branch information
janezd authored Sep 14, 2017
2 parents 9b9bec1 + 445dfd1 commit e131cbe
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
4 changes: 2 additions & 2 deletions Orange/classification/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ class TreeLearner(Learner):
def __init__(
self, *args, binarize=False, max_depth=None,
min_samples_leaf=1, min_samples_split=2, sufficient_majority=0.95,
**kwargs):
super().__init__(*args, **kwargs)
preprocessors=None, **kwargs):
super().__init__(preprocessors=preprocessors)
self.params = {}
self.binarize = self.params['binarize'] = binarize
self.min_samples_leaf = self.params['min_samples_leaf'] = min_samples_leaf
Expand Down
15 changes: 13 additions & 2 deletions Orange/tests/test_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@
# pylint: disable=missing-docstring

import unittest
from unittest.mock import Mock

import numpy as np
import sklearn.tree as skl_tree
from sklearn.tree._tree import TREE_LEAF

from Orange.data import Table
from Orange.classification import SklTreeLearner
from Orange.classification import SklTreeLearner, TreeLearner
from Orange.regression import SklTreeRegressionLearner


class TestTreeLearner(unittest.TestCase):
class TestSklTreeLearner(unittest.TestCase):
def test_classification(self):
table = Table('iris')
learn = SklTreeLearner()
Expand All @@ -28,6 +29,16 @@ def test_regression(self):
self.assertTrue(np.all(table.Y.flatten() == pred))


class TestTreeLearner(unittest.TestCase):
def test_uses_preprocessors(self):
iris = Table('iris')
mock_preprocessor = Mock(return_value=iris)

tree = TreeLearner(preprocessors=[mock_preprocessor])
tree(iris)
mock_preprocessor.assert_called_with(iris)


class TestDecisionTreeClassifier(unittest.TestCase):
@classmethod
def setUpClass(cls):
Expand Down

0 comments on commit e131cbe

Please sign in to comment.