Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] Preprocess: Fix reporting for remove sparse and impute #6212

Merged
merged 1 commit into from
Nov 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 19 additions & 5 deletions Orange/widgets/data/owpreprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from Orange.preprocess import Continuize, ProjectPCA, RemoveNaNRows, \
ProjectCUR, Scale as _Scale, Randomize as _Randomize, RemoveSparse
from Orange.widgets import widget, gui
from Orange.widgets.utils.localization import pl
from Orange.widgets.settings import Setting
from Orange.widgets.utils.overlay import OverlayWidget
from Orange.widgets.utils.sql import check_sql_input
Expand Down Expand Up @@ -253,9 +254,9 @@ def createinstance(params):
def __repr__(self):
return self.Continuizers[self.__treatment]

class RemoveSparseEditor(BaseEditor):

options = ["missing", "zeros"]
class RemoveSparseEditor(BaseEditor):
options = ["missing values", "zeros"]

def __init__(self, parent=None, **kwargs):
super().__init__(parent, **kwargs)
Expand All @@ -266,11 +267,9 @@ def __init__(self, parent=None, **kwargs):
self.setLayout(QVBoxLayout())

self.layout().addWidget(QLabel("Remove features with too many"))
options = ["missing values",
"zeros"]
self.filter_buttons = QButtonGroup(exclusive=True)
self.filter_buttons.buttonClicked.connect(self.filterByClicked)
for idx, option, in enumerate(options):
for idx, option, in enumerate(self.options):
btn = QRadioButton(self, text=option, checked=idx == 0)
self.filter_buttons.addButton(btn, id=idx)
self.layout().addWidget(btn)
Expand Down Expand Up @@ -354,6 +353,15 @@ def createinstance(params):
threshold = params.pop('percThresh', 5) / 100
return RemoveSparse(threshold, filter0)

def __repr__(self):
desc = f"remove features with too many {self.options[self.filter0]}, threshold: "
if self.useFixedThreshold:
desc += f"{self.fixedThresh} {pl(self.fixedThresh, 'instance')}"
else:
desc += f"{self.percThresh} %"
return desc


class ImputeEditor(BaseEditor):
(NoImputation, Constant, Average,
Model, Random, DropRows, DropColumns) = 0, 1, 2, 3, 4, 5, 6
Expand Down Expand Up @@ -727,6 +735,12 @@ def createinstance(params):
# further implementations
raise NotImplementedError

def __repr__(self):
if self.__strategy == self.Fixed:
return f"select {self.__k} {pl(self.__k,'feature')}"
else:
return f"select {self.__p} % features"


def index_to_enum(enum, i):
"""Enums, by default, are not int-comparable, so use an ad-hoc mapping of
Expand Down
20 changes: 19 additions & 1 deletion Orange/widgets/data/tests/test_owpreprocess.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Test methods with long descriptive names can omit docstrings
# pylint: disable=missing-docstring,unsubscriptable-object
import unittest

import numpy as np

from Orange.data import Table
Expand Down Expand Up @@ -231,6 +233,13 @@ def test_editor(self):
self.assertIsInstance(p, fss.SelectRandomFeatures)
self.assertEqual(p.k, 0.25)

def test_repr(self):
widget = owpreprocess.RandomFeatureSelectEditor()
for strategy in (owpreprocess.RandomFeatureSelectEditor.Fixed,
owpreprocess.RandomFeatureSelectEditor.Percentage):
widget.setStrategy(strategy)
repr(widget)


class TestRandomizeEditor(WidgetTest):
def test_editor(self):
Expand Down Expand Up @@ -281,8 +290,8 @@ def test_editor(self):
self.assertEqual(p.rank, 5)
self.assertEqual(p.max_error, 0.5)

class TestRemoveSparseEditor(WidgetTest):

class TestRemoveSparseEditor(WidgetTest):
def test_editor(self):
widget = owpreprocess.RemoveSparseEditor()
self.assertEqual(
Expand All @@ -304,3 +313,12 @@ def test_editor(self):
self.assertIsInstance(p, RemoveSparse)
self.assertEqual(p.threshold, 30)
self.assertFalse(p.filter0)

def test_repr(self):
widget = owpreprocess.RemoveSparseEditor()
for widget.useFixedThreshold in (False, True):
repr(widget)


if __name__ == "__main__":
unittest.main()