Skip to content

Commit

Permalink
Fixed bug in ACP caused by supplying significance=None. for regressio…
Browse files Browse the repository at this point in the history
…n problems
  • Loading branch information
donlnz committed Apr 24, 2015
1 parent 5fa71a4 commit e4ccec4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
2 changes: 1 addition & 1 deletion nonconformist/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@

# Authors: Henrik Linusson

__version__ = '1.1.0'
__version__ = '1.1.1'

__all__ = ['icp', 'nc', 'acp']
27 changes: 20 additions & 7 deletions nonconformist/acp.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,11 +215,24 @@ def predict(self, x, significance=None):
"""
is_regression = self.cp_class.get_problem_type() == 'regression'

f = lambda p, x: p.predict(x, significance if is_regression else None)
predictions = np.dstack([f(p, x) for p in self.predictors])
predictions = self.agg_func(predictions)

if significance and not is_regression:
return predictions >= significance
n_examples = x.shape[0]

if is_regression and significance is None:
signs = np.arange(0.01, 1.0, 0.01)
pred = np.zeros((n_examples, 2, signs.size))
for i, s in enumerate(signs):
predictions = np.dstack([p.predict(x, s)
for p in self.predictors])
predictions = self.agg_func(predictions)
pred[:, :, i] = predictions
return pred
else:
return predictions
f = lambda p, x: p.predict(x,
significance if is_regression else None)
predictions = np.dstack([f(p, x) for p in self.predictors])
predictions = self.agg_func(predictions)

if significance and not is_regression:
return predictions >= significance
else:
return predictions

0 comments on commit e4ccec4

Please sign in to comment.