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]OWFreeViz: Fix optimization for data with missing values #3358

Merged
merged 1 commit into from
Nov 6, 2018
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
15 changes: 8 additions & 7 deletions Orange/widgets/visualize/owfreeviz.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,12 +353,12 @@ def prepare_projection_data(self):
self._X = self._Y = self.valid_data = None
return

self._X = self.data.X.copy()
self._X -= np.nanmean(self._X, axis=0)
span = np.ptp(self._X[self.valid_data], axis=0)
self._X = self.data.X[self.valid_data]
self._X -= np.mean(self._X, axis=0)
span = np.ptp(self._X, axis=0)
self._X[:, span > 0] /= span[span > 0].reshape(1, -1)

self._Y = self.data.Y
self._Y = self.data.Y[self.valid_data]
if self.data.domain.class_var.is_discrete:
self._Y = self._Y.astype(int)

Expand All @@ -370,9 +370,10 @@ def init_embedding_coords(self):
def get_embedding(self):
if self.data is None:
return None
embedding = np.dot(self._X, self.projection)
embedding /= \
np.max(np.linalg.norm(embedding[self.valid_data], axis=1)) or 1
EX = np.dot(self._X, self.projection)
EX /= np.max(np.linalg.norm(EX, axis=1)) or 1
embedding = np.zeros((len(self.data), 2), dtype=np.float)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the original data had missing values, and the embedding is not available for all points, I think it is better to assign missing values to those points as the embedding too (instead of zeros).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, while I doubt these projections will ever be generalized to more than 2D, I would still prefer to not make implicit assumptions like that in the code and use EX.shape[1] instead of 2

embedding[self.valid_data] = EX
return embedding

def get_anchors(self):
Expand Down
2 changes: 1 addition & 1 deletion Orange/widgets/visualize/tests/test_owfreeviz.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def test_error_msg(self):
self.assertFalse(self.widget.Error.not_enough_class_vars.is_shown())

def test_optimization(self):
self.send_signal(self.widget.Inputs.data, self.data)
self.send_signal(self.widget.Inputs.data, self.heart_disease)
self.widget.btn_start.click()

def test_optimization_cancelled(self):
Expand Down
1 change: 1 addition & 0 deletions Orange/widgets/visualize/utils/widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,7 @@ def clear(self):
self.data = None
self.valid_data = None
self.selection = None
self.graph.selection = None

def onDeleteWidget(self):
super().onDeleteWidget()
Expand Down