Skip to content
This repository
Browse code

an simple test case for KNeighborsClassifier.predict_proba()

  • Loading branch information...
commit 8b5142a58a734129ffa65937abce030c732cc604 1 parent 7bb3c6d
kernc kernc authored

Showing 1 changed file with 23 additions and 0 deletions. Show diff stats Hide diff stats

  1. +23 0 sklearn/neighbors/tests/test_neighbors.py
23 sklearn/neighbors/tests/test_neighbors.py
@@ -189,6 +189,29 @@ def test_kneighbors_classifier(n_samples=40,
189 189 assert_array_equal(y_pred, y[:n_test_pts])
190 190
191 191
  192 +def test_kneighbors_classifier_predict_proba():
  193 + """Test KNeighborsClassifier.predict_proba() method"""
  194 + X = np.array([[0,2,0],
  195 + [0,2,1],
  196 + [2,0,0],
  197 + [2,2,0],
  198 + [0,0,2],
  199 + [0,0,1]])
  200 + y = np.array([4, 4, 5, 5, 1, 1])
  201 + cls = neighbors.KNeighborsClassifier(n_neighbors=3, p=1) # cityblock dist
  202 + cls.fit(X, y)
  203 + y_prob = cls.predict_proba(X)
  204 + real_prob = np.array([[0, 2./3, 1./3],
  205 + [1./3, 2./3, 0],
  206 + [1./3, 0, 2./3],
  207 + [0, 1./3, 2./3],
  208 + [2./3, 1./3, 0],
  209 + [2./3, 1./3, 0]])
  210 + assert_array_equal(real_prob, y_prob)
  211 +
  212 +
  213 +
  214 +
192 215 def test_radius_neighbors_classifier(n_samples=40,
193 216 n_features=5,
194 217 n_test_pts=10,

6 comments on commit 8b5142a

Andreas Mueller
Owner

pep8?

Alexandre Gramfort
Owner

shame ... feel free to fix it if not already done

Andreas Mueller
Owner

did it ;)

kernc
kernc commented on 8b5142a

argh, sorry. I forgot. :<
I don't get what's wrong with spaces on blank lines.

Alexandre Gramfort
Owner
Mathieu Blondel
Owner

When 40 people work together to make each release, it's important to have a little bit of style consistency...

Please sign in to comment.
Something went wrong with that request. Please try again.