# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

import numpy as np
import random

mu, sigma = 1, 0.1
distribution = list(mu + sigma * np.random.randn(100))
distribution.append(200)
distribution.append(1000)

# +
import matplotlib.pyplot as plt

plt.hist(distribution[:-2], 50, density=True, facecolor='g', alpha=0.75)
plt.show()
# -

# ## Standard deviation and mean

print("Mean ",np.mean(distribution))
print("STD ",np.std(distribution))


def select_outliers_std(distribution):
    mean = np.mean(distribution)
    std = np.std(distribution)
    list_outliers = []
    for i in distribution:
        if i > (mean+(3*std)) or i < (mean-(3*std)):
            list_outliers.append(i)
    return list_outliers


select_outliers_std(distribution)


# ## IQR Rule

def select_outliers(distribution):
    median_data = np.median(distribution)
    Q1 = np.percentile(distribution, 25, interpolation="midpoint")
    Q3 = np.percentile(distribution, 75, interpolation="midpoint")
    IQR = Q3 - Q1
    list_outliers = []
    for v in distribution:
        if v > (median_data + (1.5 * IQR)) or v < (median_data - (1.5 * IQR)):
            list_outliers.append(v)
    return list_outliers


list_res = select_outliers(distribution)
list_res.sort()
list_res

StarcoderdataJupyterScriptsDedupFiltered