Skip to content

Commit af68989

Browse files
authored
Merge pull request #4067 from VesnaT/owcorrelations_cont_target
[ENH] Correlations: Include continuous class and meta variables
2 parents 05b3cdb + afe68a0 commit af68989

File tree

2 files changed

+28
-9
lines changed

2 files changed

+28
-9
lines changed

Orange/widgets/data/owcorrelations.py

+10-6
Original file line numberDiff line numberDiff line change
@@ -262,8 +262,8 @@ class Warning(OWWidget.Warning):
262262

263263
def __init__(self):
264264
super().__init__()
265-
self.data = None
266-
self.cont_data = None
265+
self.data = None # type: Table
266+
self.cont_data = None # type: Table
267267

268268
# GUI
269269
box = gui.vBox(self.mainArea)
@@ -347,9 +347,9 @@ def set_data(self, data):
347347
self.Warning.not_enough_inst()
348348
else:
349349
domain = data.domain
350-
cont_attrs = [a for a in domain.attributes if a.is_continuous]
351-
cont_dom = Domain(cont_attrs, domain.class_vars, domain.metas)
352-
cont_data = Table.from_table(cont_dom, data)
350+
cont_vars = [a for a in domain.class_vars + domain.metas +
351+
domain.attributes if a.is_continuous]
352+
cont_data = Table.from_table(Domain(cont_vars), data)
353353
remover = Remove(Remove.RemoveConstant)
354354
cont_data = remover(cont_data)
355355
if remover.attr_results["removed"]:
@@ -365,7 +365,11 @@ def set_data(self, data):
365365

366366
def set_feature_model(self):
367367
self.feature_model.set_domain(self.cont_data and self.cont_data.domain)
368-
self.feature = None
368+
data = self.data
369+
if self.cont_data and data.domain.has_continuous_class:
370+
self.feature = self.cont_data.domain[data.domain.class_var.name]
371+
else:
372+
self.feature = None
369373

370374
def apply(self):
371375
self.vizrank.initialize()

Orange/widgets/data/tests/test_owcorrelations.py

+18-3
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ def setUpClass(cls):
2828
cls.data_cont = Table("iris")
2929
cls.data_disc = Table("zoo")
3030
cls.data_mixed = Table("heart_disease")
31+
cls.housing = Table("housing")
3132

3233
def setUp(self):
3334
self.widget = self.create_widget(OWCorrelations)
@@ -86,7 +87,7 @@ def test_input_data_one_instance(self):
8687
self.assertFalse(self.widget.Warning.not_enough_inst.is_shown())
8788

8889
def test_input_data_with_constant_features(self):
89-
"""Check correlation table for dataset with a constant columns"""
90+
"""Check correlation table for dataset with constant columns"""
9091
np.random.seed(0)
9192
# pylint: disable=no-member
9293
X = np.random.randint(3, size=(4, 3)).astype(float)
@@ -118,6 +119,20 @@ def test_input_data_with_constant_features(self):
118119
self.send_signal(self.widget.Inputs.data, None)
119120
self.assertFalse(self.widget.Information.removed_cons_feat.is_shown())
120121

122+
def test_input_data_cont_target(self):
123+
"""Check correlation table for dataset with continuous class variable"""
124+
data = self.housing[:5, 11:]
125+
self.send_signal(self.widget.Inputs.data, data)
126+
time.sleep(0.1)
127+
self.process_events()
128+
self.assertEqual(self.widget.vizrank.rank_model.rowCount(), 2)
129+
self.assertEqual(self.widget.controls.feature.count(), 4)
130+
self.assertEqual(self.widget.controls.feature.currentText(), "MEDV")
131+
132+
data = self.housing[:5, 13:]
133+
self.send_signal(self.widget.Inputs.data, data)
134+
self.assertTrue(self.widget.Warning.not_enough_vars.is_shown())
135+
121136
def test_output_data(self):
122137
"""Check dataset on output"""
123138
self.send_signal(self.widget.Inputs.data, self.data_cont)
@@ -230,8 +245,8 @@ def test_feature_combo(self):
230245
self.assertEqual(len(feature_combo.model()), len(cont_attributes) + 1)
231246

232247
self.wait_until_stop_blocking()
233-
self.send_signal(self.widget.Inputs.data, Table("housing"))
234-
self.assertEqual(len(feature_combo.model()), 14)
248+
self.send_signal(self.widget.Inputs.data, self.housing)
249+
self.assertEqual(len(feature_combo.model()), 15)
235250

236251
def test_select_feature(self):
237252
"""Test feature selection"""

0 commit comments

Comments
 (0)