title: Understanding sklearn's KNNImputer
body: <p>I was going through its documentation and it says</p>
  
  <blockquote>
    <p>Each sample’s missing values are imputed using the mean value from
    n_neighbors nearest neighbors found in the training set. Two samples
    are close if the features that neither are missing are close.</p>
  </blockquote>
  
  <p>Now, playing around with a toy dataset, i.e.</p>
  
  <pre><code>&gt;&gt;&gt;X = [[1, 2, nan], [3, 4, 3], [nan, 6, 5], [8, 8, 7]]
  &gt;&gt;&gt;X
  
     [[ 1.,  2., nan],
      [ 3.,  4.,  3.],
      [nan,  6.,  5.],
      [ 8.,  8.,  7.]]
  </code></pre>
  
  <p>And we make a KNNImputer as follows:</p>
  
  <pre><code>imputer = KNNImputer(n_neighbors=2)
  </code></pre>
  
  <p>The question is, how does it fill the <code>nan</code>s while having <code>nan</code>s in 2 of the columns? For example, if it is to fill the <code>nan</code> in the 3rd column of the 1st row, how will it choose which features are the closest since one of the rows has <code>nan</code> in the first column as well? When I do <code>imputer.fit_transform(X)</code> it gives me</p>
  
  <pre><code>array([[1. , 2. , 4. ],
         [3. , 4. , 3. ],
         [5.5, 6. , 5. ],
         [8. , 8. , 7. ]])
  </code></pre>
  
  <p>which means for filling out the <code>nan</code> in row 1, the nearest neighbors were the second and the third row. How did it calculate the euclidean distance between the first and the third row?</p>