Skip to content

Commit

Permalink
Outliers: Semi-interruptible widget
Browse files Browse the repository at this point in the history
  • Loading branch information
VesnaT committed Feb 12, 2020
1 parent 1c296be commit 697695a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
14 changes: 12 additions & 2 deletions Orange/widgets/data/owoutliers.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from Orange.classification import OneClassSVMLearner, EllipticEnvelopeLearner,\
LocalOutlierFactorLearner, IsolationForestLearner
from Orange.data import Table
from Orange.data.util import progress_callback
from Orange.widgets import gui
from Orange.widgets.settings import Setting
from Orange.widgets.utils.concurrent import TaskState, ConcurrentWidgetMixin
Expand All @@ -31,8 +32,16 @@ def run(data: Table, learner: Learner, state: TaskState) -> Results:
if not data:
return results

model = learner(data)
pred = model(data) # type: Table
def callback(i: float, status=""):
state.set_progress_value(i * 100)
if status:
state.set_status(status)
if state.is_interruption_requested():
raise Exception

callback(0, "Initializing...")
model = learner(data, progress_callback(callback, end=0.6))
pred = model(data, progress_callback(callback, start=0.6, end=0.99))

col = pred.get_column_view(model.outlier_var)[0]
inliers_ind = np.where(col == 1)[0]
Expand All @@ -41,6 +50,7 @@ def run(data: Table, learner: Learner, state: TaskState) -> Results:
results.inliers = data[inliers_ind]
results.outliers = data[outliers_ind]
results.annotated_data = pred
callback(1)
return results


Expand Down
6 changes: 3 additions & 3 deletions Orange/widgets/data/tests/test_owoutliers.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
class TestRun(unittest.TestCase):
def test_results(self):
iris = Table("iris")
learner = LocalOutlierFactorLearner()

res = run(iris, learner, Mock())
state = Mock()
state.is_interruption_requested = Mock(return_value=False)
res = run(iris, LocalOutlierFactorLearner(), state)
self.assertIsInstance(res.inliers, Table)
self.assertIsInstance(res.outliers, Table)
self.assertIsInstance(res.annotated_data, Table)
Expand Down

0 comments on commit 697695a

Please sign in to comment.