title: Detect outliers or noise data in each group in Python
body: <p>I'm working for a data which have 3 columns: <code>type</code>, <code>x</code>, <code>y</code>, let's say <code>x</code> and <code>y</code> are correlated and they not normalizedly distributed, I want groupby <code>type</code> and filter <code>outliers</code> or <code>noise</code> data points in <code>x</code> and <code>y</code>. Could someone recommend me statitics or machine learning methods to filter outliers or noise data? How can I do that in Python? </p>
  
  <p>I'm considering to use <code>DBSCAN</code> from <code>scikit-learn</code>, is it appropriate method ?</p>
  
  <p>Type1:
  <a href="https://i.stack.imgur.com/nfoCF.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/nfoCF.png" alt="type1"></a>
  Type2:
  <a href="https://i.stack.imgur.com/wnuex.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/wnuex.png" alt="enter image description here"></a>
  Type3:
  <a href="https://i.stack.imgur.com/mlMJD.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/mlMJD.png" alt="enter image description here"></a></p>
  
  <pre><code>df1 = df.loc[df['type'] == '3']
  
  data= df1[["x", "y"]]
  data.plot.scatter(x = "x", y = "y")
  
  from sklearn.cluster import DBSCAN
  outlier_detection = DBSCAN(
    eps = 0.5,
    metric="euclidean",
    min_samples = 3,
    n_jobs = -1)
  clusters = outlier_detection.fit_predict(data)
  
  from matplotlib import cm
  cmap = cm.get_cmap('Accent')
  data.plot.scatter(
    x = "iSearchCount",
    y = "iGuaPaiCount",
    c = clusters,
    cmap = cmap,
    colorbar = False
  )
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/DNXv8.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/DNXv8.png" alt="enter image description here"></a></p>