Python ရှိ interquartile range ကို တွက်နည်း
interquartile range ကို မကြာခဏ “ IQR” ဟုခေါ်ပြီး ဒေတာအစုတစ်ခု၏ 50% အလယ်တန်းခွဲဝေမှုကို တိုင်းတာသည့်နည်းလမ်းတစ်ခုဖြစ်သည်။ ဒေတာအစုတစ်ခု၏ ပထမ quartile* (25th percentile) နှင့် တတိယ quartile (the 75th percentile) အကြား ကွာခြားချက်အဖြစ် တွက်ချက်ပါသည်။
ကံကောင်းထောက်မစွာ၊ numpy.percentile() လုပ်ဆောင်ချက်ကို အသုံးပြု၍ Python ရှိ ဒေတာအတွဲတစ်ခု၏ ကွာတားအကွာအဝေးကို တွက်ချက်ရန် လွယ်ကူသည်။
ဤသင်ခန်းစာတွင် ဤလုပ်ဆောင်ချက်ကို လက်တွေ့အသုံးပြုပုံ နမူနာများစွာကို ပြသထားသည်။
ဥပမာ 1- ဇယားတစ်ခု၏ကြားပိုင်းအကွာအဝေး
အောက်ဖော်ပြပါ ကုဒ်သည် ဇယားတစ်ခုတွင် တန်ဘိုး၏ interquartile အကွာအဝေးကို တွက်ချက်နည်းကို ပြသည်-
import numpy as np #define array of data data = np.array([14, 19, 20, 22, 24, 26, 27, 30, 30, 31, 36, 38, 44, 47]) #calculate interquartile range q3, q1 = np. percentile (data, [75,25]) iqr = q3 - q1 #display interquartile range iqr 12.25
ဤဒေတာအတွဲ၏ကြားပိုင်းအကွာအဝေးသည် 12.25 ဖြစ်သည် ။ ဤသည်မှာ ဤဒေတာအတွဲရှိ တန်ဖိုးများ၏ 50% အလယ်တန်းကို ဖြန့်ချီခြင်းဖြစ်သည်။
ဥပမာ 2- Data Frame Column တစ်ခု၏ Interquartile Range
အောက်ပါကုဒ်သည် ဒေတာဘောင်တစ်ခုရှိ ကော်လံတစ်ခုအတွက် interquartile အကွာအဝေးကို တွက်ချက်နည်းကို ပြသသည်-
import numpy as np import pandas as pd #create data frame df = pd.DataFrame({'rating': [90, 85, 82, 88, 94, 90, 76, 75, 87, 86], 'points': [25, 20, 14, 16, 27, 20, 12, 15, 14, 19], 'assists': [5, 7, 7, 8, 5, 7, 6, 9, 9, 5], 'rebounds': [11, 8, 10, 6, 6, 9, 6, 10, 10, 7]}) #calculate interquartile range of values in the 'points' column q75, q25 = np. percentile (df['points'], [75,25]) iqr = q75 - q25 #display interquartile range iqr 5.75
အမှတ်များ ကော်လံရှိ တန်ဖိုးများ ၏ interquartile အကွာအဝေးသည် 5.75 ဖြစ်သည် ။
ဥပမာ 3- ဒေတာဘောင်ကော်လံများစွာ၏ ကွာတားအကွာအဝေး
အောက်ပါ ကုဒ်သည် ဒေတာဘောင်တစ်ခုရှိ ကော်လံအများအပြား၏ interquartile အကွာအဝေးကို တွက်ချက်နည်းကို ပြသသည်-
import numpy as np import pandas as pd #create data frame df = pd.DataFrame({'rating': [90, 85, 82, 88, 94, 90, 76, 75, 87, 86], 'points': [25, 20, 14, 16, 27, 20, 12, 15, 14, 19], 'assists': [5, 7, 7, 8, 5, 7, 6, 9, 9, 5], 'rebounds': [11, 8, 10, 6, 6, 9, 6, 10, 10, 7]}) #define function to calculate interquartile range def find_iqr(x): return np. subtract (*np. percentile (x, [75, 25])) #calculate IQR for 'rating' and 'points' columns df[[' rating ', ' points ']]. apply (find_iqr) rating 6.75 points 5.75 dtype:float64 #calculate IQR for all columns df. apply (find_iqr) rating 6.75 points 5.75 assists 2.50 rebounds 3.75 dtype:float64
မှတ်ချက်- အထက်ဖော်ပြပါဒေတာဘောင်ရှိ ကော်လံများစွာအတွက် IQR ကို တွက်ချက်ရန် pandas.DataFrame.apply() လုပ်ဆောင်ချက်ကို ကျွန်ုပ်တို့ အသုံးပြုပါသည်။
ထပ်လောင်းအရင်းအမြစ်များ
interquartile range (IQR) သည် outliers ကြောင့် ထိခိုက်ပါသလား။
Excel တွင် Interquartile Range (IQR) တွက်ချက်နည်း
Interquartile Range ဂဏန်းတွက်စက်