Skip to content

Commit

Permalink
Merge pull request #598 from markotoplak/predictmiss
Browse files Browse the repository at this point in the history
Ability to learn without and predict wih missing values
  • Loading branch information
VesnaT committed Dec 15, 2015
2 parents 4b5cdb1 + 3e38da6 commit 21b7059
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Orange/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ class SklLearner(Learner, metaclass=WrapperMeta):
name = 'skl learner'
preprocessors = [Continuize(),
RemoveNaNColumns(),
SklImpute(force=False)]
SklImpute()]

@property
def params(self):
Expand Down
6 changes: 1 addition & 5 deletions Orange/preprocess/preprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,17 +148,13 @@ def __call__(self, data):
class SklImpute(Preprocess):
__wraps__ = skl_preprocessing.Imputer

def __init__(self, strategy='mean', force=True):
def __init__(self, strategy='mean'):
self.strategy = strategy
self.force = force

def __call__(self, data):
from Orange.data.sql.table import SqlTable
if isinstance(data, SqlTable):
return Impute()(data)

if not self.force and not np.isnan(data.X).any():
return data
self.imputer = skl_preprocessing.Imputer(strategy=self.strategy)
X = self.imputer.fit_transform(data.X)
# Create new variables with appropriate `compute_value`, but
Expand Down
2 changes: 1 addition & 1 deletion Orange/projection/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class SklProjector(Projector, metaclass=WrapperMeta):
_params = {}
name = 'skl projection'
preprocessors = [Orange.preprocess.Continuize(),
Orange.preprocess.SklImpute(force=False)]
Orange.preprocess.SklImpute()]

@property
def params(self):
Expand Down
2 changes: 1 addition & 1 deletion Orange/regression/linear.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class PolynomialLearner(Learner):
name = 'poly learner'
preprocessors = [Continuize(),
RemoveNaNColumns(),
SklImpute(force=False)]
SklImpute()]

def __init__(self, learner, degree=1, preprocessors=None):
super().__init__(preprocessors=preprocessors)
Expand Down
10 changes: 9 additions & 1 deletion Orange/tests/test_classification.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ class ExpandProbabilitiesTest(unittest.TestCase):
def prepareTable(self, rows, attr, vars, class_var_domain):
attributes = ["Feature %i" % i for i in range(attr)]
classes = ["Class %i" % i for i in range(vars)]
attr_vars = [DiscreteVariable(name=a) for a in attributes]
attr_vars = [DiscreteVariable(name=a, values=range(2))
for a in attributes]
class_vars = [DiscreteVariable(name=c,
values=range(class_var_domain))
for c in classes]
Expand Down Expand Up @@ -219,6 +220,13 @@ def test_continuous(lf):
assert(all(tree(strlist) == tree(Orange.data.Table(table.domain, strlist))))


class UnknownValuesInPrediction(unittest.TestCase):
def test_unknown(self):
table = Table("iris")
tree = LogisticRegressionLearner()(table)
tree([1, 2, None])


class LearnerAccessibility(unittest.TestCase):
def setUp(self):
Variable._clear_all_caches()
Expand Down

0 comments on commit 21b7059

Please sign in to comment.