title: How to correctly identify anomalies using Isolation Forest and resulting scores?
body: <p>I'm trying to detect outliers in a dataframe using the Isolation Forest algorithm from sklearn.</p>
  
  <p>Here's the code I'm using to set up the algorithm:</p>
  
  <pre><code>iForest = IsolationForest(n_estimators=100, max_samples=256, contamination='auto', random_state=1, behaviour='new')
  iForest.fit(dataset)
  scores = iForest.decision_function(dataset)
  </code></pre>
  
  <p>Now, since I don't know what a good value for the contamination could be, I would like to check my scores and decide where to draw the line based on the distribution of the scores. Here's the code for the graph and the graph itself:</p>
  
  <pre><code>plt.figure(figsize=(12, 8))
  plt.hist(scores, bins=50);
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/10G8g.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/10G8g.png" alt="enter image description here"></a></p>
  
  <p>Is it correct to assume that negative scores indicate outliers in my dataframe? I can't find a good explanation on the range of the IF scores and how these scores work (why do I get negative scores?).</p>
  
  <p>Additionally, is there a way to attach these scores to the original dataset and manually check rows with negative scores to see if they make sense?</p>
  
  <p>Thanks!</p>