Skip to content

Commit

Permalink
owsilhouetteplot: Always output scores
Browse files Browse the repository at this point in the history
  • Loading branch information
lanzagar committed Feb 14, 2020
1 parent 5c36a87 commit 2f794bd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 25 deletions.
32 changes: 11 additions & 21 deletions Orange/widgets/visualize/owsilhouetteplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ class Outputs:
#: A fixed size for an instance bar
bar_size = settings.Setting(3)
#: Add silhouette scores to output data
add_scores = settings.Setting(False)
auto_commit = settings.Setting(True)

pending_selection = settings.Setting(None, schema_only=True)
Expand Down Expand Up @@ -178,9 +177,6 @@ def __init__(self):

gui.separator(self.buttonsArea)
box = gui.vBox(self.buttonsArea, "Output")
# Thunk the call to commit to call conditional commit
gui.checkBox(box, self, "add_scores", "Add silhouette scores",
callback=lambda: self.commit())
gui.auto_send(box, self, "auto_commit", box=False)
# Ensure that the controlArea is not narrower than buttonsArea
self.controlArea.layout().addWidget(self.buttonsArea)
Expand Down Expand Up @@ -499,28 +495,22 @@ def commit(self):
else:
scores = self._silhouette

silhouette_var = None
if self.add_scores:
var = self.cluster_var_model[self.cluster_var_idx]
silhouette_var = Orange.data.ContinuousVariable(
"Silhouette ({})".format(escape(var.name)))
domain = Orange.data.Domain(
self.data.domain.attributes,
self.data.domain.class_vars,
self.data.domain.metas + (silhouette_var, ))
data = self.data.transform(domain)
else:
domain = self.data.domain
data = self.data
var = self.cluster_var_model[self.cluster_var_idx]
silhouette_var = Orange.data.ContinuousVariable(
"Silhouette ({})".format(escape(var.name)))
domain = Orange.data.Domain(
self.data.domain.attributes,
self.data.domain.class_vars,
self.data.domain.metas + (silhouette_var, ))
data = self.data.transform(domain)

if np.count_nonzero(selectedmask):
selected = self.data.from_table(
domain, self.data, np.flatnonzero(selectedmask))

if self.add_scores:
if selected is not None:
selected[:, silhouette_var] = np.c_[scores[selectedmask]]
data[:, silhouette_var] = np.c_[scores]
if selected is not None:
selected[:, silhouette_var] = np.c_[scores[selectedmask]]
data[:, silhouette_var] = np.c_[scores]

self.Outputs.selected_data.send(selected)
self.Outputs.annotated_data.send(create_annotated_table(data, indices))
Expand Down
4 changes: 0 additions & 4 deletions Orange/widgets/visualize/tests/test_owsilhouetteplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ def test_no_data(self):
def test_outputs_add_scores(self):
# check output when appending scores
self.send_signal(self.widget.Inputs.data, self.data)
self.widget.controls.add_scores.setChecked(1)
selected_indices = self._select_data()
selected = self.get_output(self.widget.Outputs.selected_data)
annotated = self.get_output(self.widget.Outputs.annotated_data)
Expand All @@ -63,7 +62,6 @@ def test_insufficient_clusters(self):
self.assertTrue(self.widget.Error.singleton_clusters_all.is_shown())

def test_unknowns_in_labels(self):
self.widget.controls.add_scores.setChecked(1)
data = self.data[[0, 1, 2, 50, 51, 52, 100, 101, 102]]
data.Y[::3] = np.nan
valid = ~np.isnan(data.Y.flatten())
Expand All @@ -83,7 +81,6 @@ def test_unknowns_in_labels(self):
np.testing.assert_almost_equal(scores_1, scores[valid], decimal=12)

def test_nan_distances(self):
self.widget.controls.add_scores.setChecked(1)
self.widget.distance_idx = 2
self.assertEqual(self.widget.Distances[self.widget.distance_idx][0],
'Cosine')
Expand Down Expand Up @@ -157,7 +154,6 @@ def test_bad_data_range(self):
[16, nan, nan],
"nyy"))
)
self.widget.controls.add_scores.setChecked(1)
self.send_signal(self.widget.Inputs.data, table)

def test_saved_selection(self):
Expand Down

0 comments on commit 2f794bd

Please sign in to comment.