جلسه 15 – Outlier & Z-score

What is an outlier

داده ای که تفاوت معناداری از سایر داده ها داشته باشد را outlier گوییم

An outlier is a data point in a data set that is distant from all other observations. A data point that lies outside the overall distribution of the dataset.

معیار outlier بودن:

دو معیار برای شناسایی outlier داریم:

  1. Data point that falls outside of 1.5 times of an interquartile range above the 3rd quartile and below the 1st quartile

اگر دیتا زیر 25 درصد اول یا بالای ربع سوم (3rd quartile) قرار بگیرد، outlier خواهد بود

  1. Data point that falls outside of 3 standard deviations. we can use a z score and if the z score falls outside of 2 standard deviation

اگر نمودار نرمال یا استاندارد داده ها را رسم کنیم، داده ای که بیرون از 3sd قرار بگیرد را outlier گوییم. همچنین با استفاده از Z score اگر داده در بیرون از 2sd قرار بگیرد ، outlier خواهد بود.

پیدا کردن outlier:

روش های زیر برای پیدا کردن outlier وجود دارد:

  1. Using scatter plots
  2. Box plot – نمونه یک
  3. using z score
  4. using the IQR interquantile range

تابع زیر مقادیر outlier رابرای ما پیدا میکند:

outliers=[]
def detect_outliers(data):
    
    threshold=3
    mean = np.mean(data)
    std =np.std(data)
    
    
    for i in data:
        z_score= (i - mean)/std 
        if np.abs(z_score) > threshold:
            outliers.append(i)
    return outliers

InterQuantile Range

بازه بین 25 درصد تا 75 درصد را گویند. مراحل زیر را برای پیدا کردن آن انجام میدهیم:

  • Arrange the data in increasing order- سورت کردن داده از کم به زیاد
  • Calculate first(q1) and third quartile(q3)- محاسبه چارک اول و سوم
  • Find interquartile range (q3-q1)- محاسبه آختلاف q1 تا q3
  • Find lower bound q1*1.5- مرز پایین 1.5 برابر q1 است نه خود q1
  • Find upper bound q3*1.5-

Anything that lies outside of lower and upper bound is an outlier – هر مقدار که خارج از این بازه باشد را outlier گویند.

دیدگاهتان را بنویسید

نشانی ایمیل شما منتشر نخواهد شد.