Box plots और IQR

Python में Anomaly Detection

Bekhruz (Bex) Tuychiev

Kaggle Master, Data Science Content Creator

Boxplots पुनरावलोकन

  • Boxplots:
    • 5-number summary के उन्नत विज़ुअल रूप
    • डेटा की स्थिति, फैलाव और skewness दिखाते हैं
    • outliers की उपस्थिति दर्शाते हैं

एनोटेशन वाला एक नमूना बॉक्सप्लॉट.

Python में Anomaly Detection

Boxplot के घटक

25th, 75th पर्सेंटाइल और बॉक्स को तीर व टेक्स्ट से दिखाता एक बॉक्सप्लॉट.

Python में Anomaly Detection

Whiskers

और घटकों के साथ एक और बॉक्सप्लॉट: median, एक नमूना outlier, lower और upper outlier सीमाएँ.

Python में Anomaly Detection

Inter Quartile Range (IQR)

  • IQR - Inter Quartile Range
  • IQR = Q3 - Q1
  • Whisker लंबाई: IQR और एक factor का संयोजन

पिछली स्लाइड जैसा ही छोटा बॉक्सप्लॉट.

Python में Anomaly Detection

Whisker लंबाई की गणना

  • Factor = 1.5
  • Lower limit: $Q1 - 1.5 * IQR$
  • Upper limit: $Q3 + 1.5 * IQR$

पिछली स्लाइड जैसा ही बॉक्सप्लॉट.

Python में Anomaly Detection

Boxplots बनाना

import matplotlib.pyplot as plt

plt.boxplot(sales)
plt.xlabel("Product sales")

product sales का बॉक्सप्लॉट जिसमें upper outlier सीमा के ऊपर कई outliers एक काली रेखा बनाते हैं.

Python में Anomaly Detection

Whisker लंबाई नियंत्रित करना

plt.boxplot(sales, whis=2.5)
plt.xlabel("Product sales")

product sales का बॉक्सप्लॉट जिसमें upper whisker के ऊपर कम outliers हैं.

Python में Anomaly Detection

कोड में IQR

# Calculate the percentiles
q1 = sales.quantile(0.25)
q3 = sales.quantile(0.75)


# Calculate IQR IQR = q3 - q1 # Set Multiplying factor factor = 2.5
Python में Anomaly Detection

IQR से outliers ढूँढना

# Calculate the limits
lower_limit = q1 - (IQR * factor)


upper_limit = q3 + (IQR * factor)
# Create masks
is_lower = sales < lower_limit
is_upper = sales > upper_limit


# Filter outliers = sales[is_lower | is_upper] # Print the # of outliers print(len(outliers))
29
Python में Anomaly Detection

मेथड की लचीलापन

  • Boxplots और IQR फ़िल्टरिंग बहुत लचीलापन देती है
  • outliers मार्क करने के लिए कस्टम नियम बना सकते हैं
Python में Anomaly Detection

अभ्यास करते हैं!

Python में Anomaly Detection

Preparing Video For Download...