<p dir="auto">It seems a bit out of date.</p>
<h4 dir="auto">Steps/Code to Reproduce</h4>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import numpy as np
from sklearn.neighbors import LocalOutlierFactor
c=np.array([[0,0],[0,1],[1,1],[3,0]])
k=2 #numNeighbours
clf = LocalOutlierFactor(n_neighbors=k, n_jobs=-1,algorithm='brute',metric='manhattan').fit(c) 
Z = clf._decision_function(c)
print(-Z)
[ 0.875  0.875  0.875  1.5  ]"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-s1">numpy</span> <span class="pl-k">as</span> <span class="pl-s1">np</span>
<span class="pl-k">from</span> <span class="pl-s1">sklearn</span>.<span class="pl-s1">neighbors</span> <span class="pl-k">import</span> <span class="pl-v">LocalOutlierFactor</span>
<span class="pl-s1">c</span><span class="pl-c1">=</span><span class="pl-s1">np</span>.<span class="pl-en">array</span>([[<span class="pl-c1">0</span>,<span class="pl-c1">0</span>],[<span class="pl-c1">0</span>,<span class="pl-c1">1</span>],[<span class="pl-c1">1</span>,<span class="pl-c1">1</span>],[<span class="pl-c1">3</span>,<span class="pl-c1">0</span>]])
<span class="pl-s1">k</span><span class="pl-c1">=</span><span class="pl-c1">2</span> <span class="pl-c">#numNeighbours</span>
<span class="pl-s1">clf</span> <span class="pl-c1">=</span> <span class="pl-v">LocalOutlierFactor</span>(<span class="pl-s1">n_neighbors</span><span class="pl-c1">=</span><span class="pl-s1">k</span>, <span class="pl-s1">n_jobs</span><span class="pl-c1">=</span><span class="pl-c1">-</span><span class="pl-c1">1</span>,<span class="pl-s1">algorithm</span><span class="pl-c1">=</span><span class="pl-s">'brute'</span>,<span class="pl-s1">metric</span><span class="pl-c1">=</span><span class="pl-s">'manhattan'</span>).<span class="pl-en">fit</span>(<span class="pl-s1">c</span>) 
<span class="pl-v">Z</span> <span class="pl-c1">=</span> <span class="pl-s1">clf</span>.<span class="pl-en">_decision_function</span>(<span class="pl-s1">c</span>)
<span class="pl-en">print</span>(<span class="pl-c1">-</span><span class="pl-v">Z</span>)
[ <span class="pl-c1">0.875</span>  <span class="pl-c1">0.875</span>  <span class="pl-c1">0.875</span>  <span class="pl-c1">1.5</span>  ]</pre></div>
<p dir="auto">However, the result should be: [  0.875  1.333 0.875  2. ]  if you work it out by hand (assuming a sample can't be the 1st nearest neighbour to itself). So, I think there is something wrong with the LOF implementation. Could somebody confirm either way?</p>