title: Tuning leaf_size to decrease time consumption in Scikit-Learn KNN
body: <p>I was trying to implement KNN for handwritten character recognition where I found out that the execution of code was taking a lot of time. When added parameter leaf_size with value 400, I observed that time taken by code to execute was significantly reduced.</p>
  
  <p>Original Code:</p>
  
  <pre><code>knn = KNeighborsClassifier(n_neighbors=3)
  </code></pre>
  
  <p>New Code:</p>
  
  <pre><code>knn = KNeighborsClassifier(n_neighbors=3,leaf_size=400)
  </code></pre>
  
  <p>I have read few documentation and articles regarding the leaf_size parameter of the KDtree/Balltree but couldn't find any good enough reference on how to safely tune this parameter without any accuracy and information loss.  </p>
  
  <p>It would be very kind if someone could share some insights regarding the above issue. </p>
  
  <p>Related Articles I referred to:<br>
  1.) <a href="http://scikit-learn.org/stable/modules/generated/sklearn.neighbors.KDTree.html" rel="noreferrer">http://scikit-learn.org/stable/modules/generated/sklearn.neighbors.KDTree.html</a><br>
  2.) <a href="https://jakevdp.github.io/blog/2013/04/29/benchmarking-nearest-neighbor-searches-in-python/" rel="noreferrer">https://jakevdp.github.io/blog/2013/04/29/benchmarking-nearest-neighbor-searches-in-python/</a><br>
  3.) <a href="http://scikit-learn.org/stable/modules/generated/sklearn.neighbors.KNeighborsClassifier.html" rel="noreferrer">http://scikit-learn.org/stable/modules/generated/sklearn.neighbors.KNeighborsClassifier.html</a></p>