Repository: biolab/orange3

Issue:
VizRank in Scatter Plot crashes on anneal dataset
```
.../orange3/Orange/preprocess/score.py:167: RuntimeWarning: invalid value encountered in true_divide
  P = D / np.sum(D, axis=0)
.../orange3/Orange/preprocess/score.py:231: RuntimeWarning: invalid value encountered in true_divide
  np.array([a.is_discrete for a in data.domain.attributes], dtype=np.int32)))
/usr/lib/python3/dist-packages/numpy/lib/nanfunctions.py:319: RuntimeWarning: All-NaN slice encountered
  warnings.warn("All-NaN slice encountered", RuntimeWarning)
/usr/lib/python3/dist-packages/numpy/lib/nanfunctions.py:220: RuntimeWarning: All-NaN axis encountered
  warnings.warn("All-NaN axis encountered", RuntimeWarning)
.../orange3/Orange/preprocess/score.py:231: RuntimeWarning: divide by zero encountered in true_divide
  np.array([a.is_discrete for a in data.domain.attributes], dtype=np.int32)))
.../orange3/Orange/preprocess/score.py:231: RuntimeWarning: invalid value encountered in true_divide
  np.array([a.is_discrete for a in data.domain.attributes], dtype=np.int32)))
/usr/lib/python3/dist-packages/numpy/lib/nanfunctions.py:598: RuntimeWarning: Mean of empty slice
  warnings.warn("Mean of empty slice", RuntimeWarning)
/usr/lib/python3/dist-packages/numpy/lib/nanfunctions.py:1057: RuntimeWarning: Degrees of freedom <= 0 for slice.
  warnings.warn("Degrees of freedom <= 0 for slice.", RuntimeWarning)
--------------------------------------------------------------------------------
ValueError                                    Traceback (most recent call last):
  File ".../orange3/Orange/widgets/visualize/owscatterplot.py", line 507, in toggle
    self.run()
  File ".../orange3/Orange/widgets/visualize/owscatterplot.py", line 536, in run
    ind = knn.kneighbors(return_distance=False)
  File ".../orange3/local/lib/python3.4/site-packages/sklearn/neighbors/base.py", line 339, in kneighbors
    (train_size, n_neighbors)
ValueError: Expected n_neighbors <= 2. Got 11
/usr/lib/python3/dist-packages/numpy/lib/nanfunctions.py:319: RuntimeWarning: All-NaN slice encountered
  warnings.warn("All-NaN slice encountered", RuntimeWarning)
/usr/lib/python3/dist-packages/numpy/lib/nanfunctions.py:220: RuntimeWarning: All-NaN axis encountered
  warnings.warn("All-NaN axis encountered", RuntimeWarning)
.../orange3/Orange/preprocess/score.py:231: RuntimeWarning: divide by zero encountered in true_divide
  np.array([a.is_discrete for a in data.domain.attributes], dtype=np.int32)))
.../orange3/Orange/preprocess/score.py:231: RuntimeWarning: invalid value encountered in true_divide
  np.array([a.is_discrete for a in data.domain.attributes], dtype=np.int32)))
/usr/lib/python3/dist-packages/numpy/lib/nanfunctions.py:598: RuntimeWarning: Mean of empty slice
  warnings.warn("Mean of empty slice", RuntimeWarning)
/usr/lib/python3/dist-packages/numpy/lib/nanfunctions.py:1057: RuntimeWarning: Degrees of freedom <= 0 for slice.
  warnings.warn("Degrees of freedom <= 0 for slice.", RuntimeWarning)
--------------------------------------------------------------------------------
ValueError                                    Traceback (most recent call last):
  File ".../orange3/Orange/widgets/visualize/owscatterplot.py", line 507, in toggle
    self.run()
  File ".../orange3/Orange/widgets/visualize/owscatterplot.py", line 536, in run
    ind = knn.kneighbors(return_distance=False)
  File ".../orange3/local/lib/python3.4/site-packages/sklearn/neighbors/base.py", line 339, in kneighbors
    (train_size, n_neighbors)
ValueError: Expected n_neighbors <= 2. Got 11
/usr/lib/python3/dist-packages/numpy/lib/nanfunctions.py:319: RuntimeWarning: All-NaN slice encountered
  warnings.warn("All-NaN slice encountered", RuntimeWarning)
/usr/lib/python3/dist-packages/numpy/lib/nanfunctions.py:220: RuntimeWarning: All-NaN axis encountered
  warnings.warn("All-NaN axis encountered", RuntimeWarning)
.../orange3/Orange/preprocess/score.py:231: RuntimeWarning: divide by zero encountered in true_divide
  np.array([a.is_discrete for a in data.domain.attributes], dtype=np.int32)))
.../orange3/Orange/preprocess/score.py:231: RuntimeWarning: invalid value encountered in true_divide
  np.array([a.is_discrete for a in data.domain.attributes], dtype=np.int32)))
/usr/lib/python3/dist-packages/numpy/lib/nanfunctions.py:598: RuntimeWarning: Mean of empty slice
  warnings.warn("Mean of empty slice", RuntimeWarning)
/usr/lib/python3/dist-packages/numpy/lib/nanfunctions.py:1057: RuntimeWarning: Degrees of freedom <= 0 for slice.
  warnings.warn("Degrees of freedom <= 0 for slice.", RuntimeWarning)
--------------------------------------------------------------------------------
ValueError                                    Traceback (most recent call last):
  File ".../orange3/Orange/widgets/visualize/owscatterplot.py", line 507, in toggle
    self.run()
  File ".../orange3/Orange/widgets/visualize/owscatterplot.py", line 536, in run
    ind = knn.kneighbors(return_distance=False)
  File ".../orange3/local/lib/python3.4/site-packages/sklearn/neighbors/base.py", line 339, in kneighbors
    (train_size, n_neighbors)
ValueError: Expected n_neighbors <= 2. Got 11
```



Discussion:
Apparently we fixed that, and now we get another error.

```
Traceback (most recent call last):
  File "/Users/janezdemsar/Dropbox/orange3/Orange/widgets/visualize/owscatterplot.py", line 525, in toggle
    self.run()
  File "/Users/janezdemsar/Dropbox/orange3/Orange/widgets/visualize/owscatterplot.py", line 553, in run
    knn = NearestNeighbors(n_neighbors=n_neighbors).fit(X)
  File "/Users/janezdemsar/env/o3/lib/python3.5/site-packages/sklearn/neighbors/base.py", line 816, in fit
    return self._fit(X)
  File "/Users/janezdemsar/env/o3/lib/python3.5/site-packages/sklearn/neighbors/base.py", line 221, in _fit
    X = check_array(X, accept_sparse='csr')
  File "/Users/janezdemsar/env/o3/lib/python3.5/site-packages/sklearn/utils/validation.py", line 407, in check_array
    context))
ValueError: Found array with 0 sample(s) (shape=(0, 2)) while a minimum of 1 is required.
```

@janezd @kernc I reckon nobody has yet attended to the issue? Is is something we can fix promptly?


Resolving patch:
diff --git a/Orange/widgets/visualize/owscatterplot.py b/Orange/widgets/visualize/owscatterplot.py
--- a/Orange/widgets/visualize/owscatterplot.py
+++ b/Orange/widgets/visualize/owscatterplot.py
@@ -546,6 +546,9 @@ def run(self):
                     X = graph.scaled_data[[ind1, ind2], :]
                     valid = graph.get_valid_list([ind1, ind2])
                     X = X[:, valid].T
+                    if X.shape[0] < self.k:
+                        self.progress.advance()
+                        continue
                     y = y_full[valid]
                     n_neighbors = min(self.k, len(X) - 1)
                     knn = NearestNeighbors(n_neighbors=n_neighbors).fit(X)


Test patch: