Skip to content

Commit

Permalink
Merge pull request #942 from VesnaT/scatterplot_fix
Browse files Browse the repository at this point in the history
OWScatterplot: Fixup
  • Loading branch information
lanzagar committed Dec 21, 2015
2 parents 33ad543 + 535e56b commit a2b158e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
13 changes: 9 additions & 4 deletions Orange/widgets/visualize/owscatterplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ def set_data(self, data):
self.vizrank._initialize()
self.vizrank_button.setEnabled(
self.data is not None and self.data.domain.class_var is not None
and len(self.data.domain.attributes) > 1)
and len(self.data.domain.attributes) > 1 and len(self.data) > 1)
self.openContext(self.data)

def add_data(self, time=0.4):
Expand Down Expand Up @@ -515,6 +515,10 @@ def _initialize(self):
self.information(
0, 'At least 2 unique features are needed.')
return
if len(self.parent_widget.data) < 2:
self.information(
0, 'At least 2 instances are needed.')
return
self.button.setEnabled(True)

def on_selection_changed(self, selected, deselected):
Expand All @@ -535,7 +539,6 @@ def toggle(self):
def run(self):
graph = self.parent_widget.graph
y_full = self.parent_widget.data.Y
norm = 1 / (len(y_full) * self.k)
if not self.attrs:
self.attrs = self.score_heuristic()
if not self.progress:
Expand All @@ -555,11 +558,13 @@ def run(self):
valid = graph.get_valid_list([ind1, ind2])
X = X[:, valid].T
y = y_full[valid]
knn = NearestNeighbors(n_neighbors=self.k).fit(X)
n_neighbors = min(self.k, len(X) - 1)
knn = NearestNeighbors(n_neighbors=n_neighbors).fit(X)
ind = knn.kneighbors(return_distance=False)
if isinstance(self.parent_widget.data.domain.class_var,
DiscreteVariable):
score = norm * np.sum(y[ind] == y.reshape(-1, 1))
score = np.sum(y[ind] == y.reshape(-1, 1)) / (
len(y_full) * n_neighbors)
else:
score = r2_score(y, np.mean(y[ind], axis=1))
pos = bisect_left(self.scores, score)
Expand Down
2 changes: 1 addition & 1 deletion Orange/widgets/visualize/owscatterplotgraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ def __init__(self, min_v, max_v):
:type max_v: float
"""
super().__init__()
dif = max_v - min_v
dif = max_v - min_v if max_v != min_v else 1
decimals = -floor(log10(dif))
resolution = 10 ** -decimals
bins = ceil(dif / resolution)
Expand Down

0 comments on commit a2b158e

Please sign in to comment.