၁။ နောက်ခံသဘောတရားများ (Anomaly Detection & Isolation Forest)
GPS ခြေရာခံဒေတာများ (
bird_tracking.csv) ကို လေ့လာရာတွင် ပုံမှန်ပျံသန်းမှုဘောင်မှ သိသိသာသာ ခွဲထွက်နေသော အချက်အလက်များ (Anomalies / Outliers) ကို ရှာဖွေခြင်းသည် အလွန်အရေးကြီးပါသည်။ ငှက်ခြေရာခံဒေတာများတွင် Anomaly နှစ်မျိုး ရှိနိုင်ပါသည်-- GPS စက်ပိုင်းဆိုင်ရာ ချို့ယွင်းချက်များ (Sensor & GPS Glitches): ဂြိုဟ်တုအချက်ပြမှု လွဲချော်ခြင်းကြောင့် ပင်လယ်ရေမျက်နှာပြင်အောက် အနုတ်လက္ခဏာ အမြင့်ပေများ (
altitude < 0) ပြသခြင်း သို့မဟုတ် စက္ကန့်ပိုင်းအတွင်း မဖြစ်နိုင်သော အကွာအဝေးသို့ ကိုဩဒိနိတ် ခုန်ကူးသွားခြင်း (GPS Teleportation)။ - သဘာဝလွန် ပြင်းထန်သော ပျံသန်းမှုများ (Extreme Flight Events): လေပြင်းမုန်တိုင်းနှင့် ကြုံတွေ့၍ အမြန်နှုန်း ရုတ်တရက် ထိုးတက်သွားခြင်း သို့မဟုတ် လေစီးကြောင်း (Thermal) စီး၍ အလွန်မြင့်မားသော အမြင့်ပေသို့ တက်ရောက်ပျံသန်းခြင်း။
(က) Isolation Forest မည်သို့ အလုပ်လုပ်သနည်း။
သာမန် Clustering မော်ဒယ်များသည် "ပုံမှန်ဒေတာ (Normal Data) ပုံစံကို အရင်သင်ယူပြီး ထိုအုပ်စုနှင့် ဝေးကွာသူကို အမှားဟု သတ်မှတ်ခြင်း" ဖြစ်သော်လည်း Isolation Forest သည် ပြောင်းပြန်နည်းလမ်းကို အသုံးပြုပါသည်။
- အခြေခံ အယူအဆ Anomaly များသည် အရေအတွက် နည်းပါးပြီး အခြားဒေတာများနှင့် တန်ဖိုးကွာခြားလွန်းသောကြောင့် ၎င်းတို့ကို သီးခြားခွဲထုတ်ရန် (Isolate လုပ်ရန်) အလွန်လွယ်ကူသည် ဟူသော သဘောတရား ဖြစ်သည်။
- Path Length (အကိုင်းအခက် အရှည်) မော်ဒယ်သည် Feature တစ်ခုကို ကျပန်းရွေးချယ်ပြီး တန်ဖိုးတစ်ခုမှ ဖြတ်တောက်ပိုင်းခြားသော ဆုံးဖြတ်ချက်သစ်ပင်များ (Isolation Trees - iTrees) ရာနှင့်ချီ၍ တည်ဆောက်ပါသည်။
- ပုံမှန်အမှတ် (Normal Point) အခြားအမှတ်များနှင့် ရောနှောသိပ်သည်းနေသဖြင့် ၎င်းတစ်ခုတည်း သီးခြားဖြစ်သွားစေရန် အကြိမ်ပေါင်းများစွာ ခွဲထုတ်ရပါသည် (Path Length ရှည်သည်)။
- ပုံမှန်မဟုတ်သောအမှတ် (Anomaly) အစွန်အဖျားတွင် သီးခြားရှိနေသဖြင့် သစ်ပင်၏ အမြစ် (Root) အနီးတွင်ပင် ဖြတ်တောက်မှု အနည်းငယ်ဖြင့် သီးခြားခွဲထုတ်နိုင်ပါသည် (Path Length တိုသည်)။
(ခ) အဓိက Parameter များနှင့် ထူးခြားချက်
| Parameter / Concept | အဓိပ္ပာယ်နှင့် လုပ်ဆောင်ချက် |
contamination | ဒေတာတစ်ခုလုံးတွင် Anomaly မည်မျှရာခိုင်နှုန်း ပါဝင်နိုင်သည်ဟု ခန့်မှန်းသတ်မှတ်ပေးခြင်း (ဥပမာ- 0.015 ဆိုလျှင် အစွန်အဖျားဆုံး 1.5% ကို Anomaly အဖြစ် သတ်မှတ်မည်)။ |
decision_function() | ဒေတာတစ်ခုချင်းစီ၏ Anomaly Score ကို တွက်ပေးသည်။ တန်ဖိုးသည် အနုတ်လက္ခဏာ (< 0) ဘက်သို့ ပိုများလေ ပိုမိုပြင်းထန်သော Anomaly ဖြစ်လေ ဖြစ်သည်။ |
| Feature Scaling | Decision Tree အခြေခံ ဖြစ်သောကြောင့် StandardScaler ဖြင့် စကေးညှိရန် မလိုအပ်ဘဲ မူလ ရူပဗေဒယူနစ် (m/s, meters) များအတိုင်း တိုက်ရိုက် တွက်ချက်နိုင်သည်။ |
၂။ Python Code Implementation
အောက်ပါပရိုဂရမ်တွင် မူလကော်လံများအပြင် GPS ခုန်ကူးမှုအမှားနှင့် အမြင့်ရုတ်တရက် ထိုးတက်/ထိုးဆင်းမှုများကိုပါ ဖမ်းယူနိုင်ရန် Domain-Specific Feature Engineering (
vertical_speed နှင့် speed_discrepancy) ကို ထည့်သွင်းတည်ဆောက်ထားပါသည်။Python
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from sklearn.ensemble import IsolationForest
# ၁။ ဒေတာဖတ်ရှုခြင်းနှင့် Eric ၏ ဒေတာကို အချိန်အစဉ်လိုက် စီစဉ်ခြင်း
birddata = pd.read_csv("bird_tracking.csv")
eric_data = birddata[birddata['bird_name'] == 'Eric'].copy()
eric_data['date_time'] = pd.to_datetime(eric_data['date_time'], format='mixed')
eric_data = eric_data.sort_values('date_time').reset_index(drop=True)
# ၂။ မရှိမဖြစ် လိုအပ်သော ကော်လံများမှ NaN များကို ဖယ်ရှားခြင်း
req_cols = ['speed_2d', 'altitude', 'direction', 'latitude', 'longitude']
eric_data = eric_data.dropna(subset=req_cols).reset_index(drop=True)
# ၃။ Anomaly ရှာဖွေရန် အထောက်အကူပြု Feature Engineering ပြုလုပ်ခြင်း
# (က) မှတ်တမ်းတစ်ခုနှင့် တစ်ခုကြား ကွာခြားချိန် (စက္ကန့်)
eric_data['dt_seconds'] = eric_data['date_time'].diff().dt.total_seconds()
safe_dt = eric_data['dt_seconds'].replace(0, np.nan)
# (ခ) Haversine ဖော်မြူလာဖြင့် GPS ကိုဩဒိနိတ်နှစ်ခုကြား အမှန်တကယ် ရွေ့လျားအကွာအဝေး (မီတာ) တွက်ခြင်း
def haversine_meters(lat1, lon1, lat2, lon2):
R = 6371008.8 # ကမ္ဘာ့အချင်းဝက် (မီတာ)
phi1, phi2 = np.radians(lat1), np.radians(lat2)
dphi = np.radians(lat2 - lat1)
dlambda = np.radians(lon2 - lon1)
a = np.sin(dphi / 2.0)**2 + np.cos(phi1) * np.cos(phi2) * np.sin(dlambda / 2.0)**2
return 2 * R * np.arctan2(np.sqrt(a), np.sqrt(1 - a))
step_dist_m = haversine_meters(
eric_data['latitude'].shift(1), eric_data['longitude'].shift(1),
eric_data['latitude'], eric_data['longitude']
)
# ၁ နာရီ (3600s) အတွင်း ဆက်တိုက်မှတ်တမ်းများအတွက်သာ အမြန်နှုန်းကွာဟချက်နှင့် ဒေါင်လိုက်အမြန်နှုန်း တွက်ပါမည်
valid_gap = (eric_data['dt_seconds'] > 0) & (eric_data['dt_seconds'] <= 3600)
# GPS နေရာရွေ့မှုမှ တွက်ရသော အမြန်နှုန်းနှင့် စက်မှတိုင်းတာသော speed_2d ကွာဟချက် (GPS Glitch ဖမ်းရန်)
implied_speed = step_dist_m / safe_dt
eric_data['speed_discrepancy'] = np.where(valid_gap, np.abs(implied_speed - eric_data['speed_2d']), 0.0)
eric_data['speed_discrepancy'] = eric_data['speed_discrepancy'].fillna(0.0)
# ဒေါင်လိုက် အမြင့်အတက်အကျနှုန်း (Vertical Speed in m/s)
eric_data['vertical_speed'] = np.where(valid_gap, eric_data['altitude'].diff() / safe_dt, 0.0)
eric_data['vertical_speed'] = eric_data['vertical_speed'].fillna(0.0)
# ၄။ Isolation Forest မော်ဒယ် တည်ဆောက်ခြင်းနှင့် Anomaly ရှာဖွေခြင်း
feature_cols = ['speed_2d', 'altitude', 'speed_discrepancy', 'vertical_speed']
X = eric_data[feature_cols]
# contamination=0.015 (ဒေတာအားလုံး၏ အစွန်အဖျားဆုံး 1.5% ကို Anomaly အဖြစ် ရှာဖွေမည်)
iso_forest = IsolationForest(
n_estimators=200,
contamination=0.015,
random_state=42,
n_jobs=-1
)
# fit_predict သည် ပုံမှန်ဒေတာကို 1 နှင့် Anomaly ကို -1 ပြန်ပေးပါသည်
eric_data['anomaly_label'] = iso_forest.fit_predict(X)
# decision_function သည် Anomaly Score ထုတ်ပေးသည် (အနုတ်တန်ဖိုး ပိုများလေ ပိုထူးခြားလေ)
eric_data['anomaly_score'] = iso_forest.decision_function(X)
# ၅။ ရလဒ်များကို အကျဉ်းချုပ် စစ်ဆေးခြင်း
normal_data = eric_data[eric_data['anomaly_label'] == 1]
anomalies = eric_data[eric_data['anomaly_label'] == -1].sort_values('anomaly_score')
print("=== Isolation Forest Anomaly Detection ရလဒ်များ ===")
print(f"စုစုပေါင်း မှတ်တမ်းအရေအတွက် : {len(eric_data)} ခု")
print(f"ပုံမှန်ပျံသန်းမှု မှတ်တမ်း (Normal: 1) : {len(normal_data)} ခု")
print(f"ပုံမှန်မဟုတ်သော မှတ်တမ်း (Anomaly: -1) : {len(anomalies)} ခု\n")
# ပုံမှန်နှင့် Anomaly အုပ်စုနှစ်ခု၏ ပျမ်းမျှနှင့် အစွန်းရောက်တန်ဖိုး နှိုင်းယှဉ်ချက်
summary = eric_data.groupby('anomaly_label')[feature_cols].agg(['mean', 'min', 'max'])
print("--- ပုံမှန် (1) နှင့် Anomaly (-1) နှိုင်းယှဉ်ချက် ---")
print(summary.round(2))
print()
print("--- အပြင်းထန်ဆုံး Anomaly မှတ်တမ်း ၅ ခု (Lowest Anomaly Scores) ---")
display_cols = ['date_time', 'speed_2d', 'altitude', 'speed_discrepancy', 'vertical_speed', 'anomaly_score']
print(anomalies[display_cols].head(5).to_string(index=False))
# ၆။ ရလဒ်များကို ဂရပ် (၂) ခုဖြင့် ပုံဖော်ခြင်း
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(16, 7))
# --- ဘယ်ဘက်ဂရပ် (ax1): Speed vs Altitude တွင် Anomaly များကို ထင်ရှားစွာ ပြသခြင်း ---
ax1.scatter(
normal_data['speed_2d'], normal_data['altitude'],
c='#1f77b4', s=12, alpha=0.35, label='Normal Flight (1)'
)
ax1.scatter(
anomalies['speed_2d'], anomalies['altitude'],
c='#d62728', marker='X', s=45, alpha=0.85, label='Detected Anomalies (-1)'
)
# ပင်လယ်ရေမျက်နှာပြင် (0 meters) မျဉ်းကြောင်း ပြသခြင်း
ax1.axhline(0, color='black', linestyle='--', linewidth=1, label='Sea Level (0m)')
ax1.set_title("Isolation Forest: Speed vs Altitude Anomalies", fontsize=12, fontweight='bold')
ax1.set_xlabel("Flight Speed 2D (m/s)")
ax1.set_ylabel("Altitude (meters)")
ax1.legend(loc='upper right')
ax1.grid(True, linestyle='--', alpha=0.5)
# --- ညာဘက်ဂရပ် (ax2): အချိန်ကာလအလိုက် အမြင့်ပေ (Altitude) အတက်အကျနှင့် အမှားများ ---
ax2.plot(
eric_data['date_time'], eric_data['altitude'],
color='gray', linewidth=0.6, alpha=0.6, label='Altitude Trajectory'
)
ax2.scatter(
anomalies['date_time'], anomalies['altitude'],
c='#d62728', marker='o', s=30, zorder=3, label='Anomalies (-1)'
)
ax2.axhline(0, color='black', linestyle='--', linewidth=1)
ax2.set_title("Altitude Time-Series with Detected GPS Glitches & Spikes", fontsize=12, fontweight='bold')
ax2.set_xlabel("Date")
ax2.set_ylabel("Altitude (meters)")
ax2.legend(loc='upper right')
ax2.grid(True, linestyle='--', alpha=0.5)
fig.autofmt_xdate() # ရက်စွဲစာသားများ ထပ်မနေစေရန် စောင်းပေးခြင်း
plt.tight_layout()
plt.show()
၃။ ရလဒ်များကို အဓိပ္ပာယ်ဖွင့်ဆိုခြင်း (Interpreting the Results)
ပရိုဂရမ်ကို Run လိုက်သည့်အခါ Console နှင့် ဂရပ် (၂) ခုမှ အောက်ပါအချက်များကို တိကျစွာ ခွဲခြမ်းစိတ်ဖြာနိုင်ပါသည်-
- ပင်လယ်ရေမျက်နှာပြင်အောက် အနုတ်တန်ဖိုးများ (GPS Altitude Drift) ဘယ်ဘက်နှင့် ညာဘက်ဂရပ် နှစ်ခုလုံးတွင် အနက်ရောင်မျဉ်းပြတ် (
0m) အောက်သို့ ရောက်နေသော အနီရောင်အမှတ်များ (altitude < 0၊ ဥပမာ-100mဝန်းကျင်) ကို မော်ဒယ်က အလိုအလျောက် ဖမ်းမိထားပါသည်။ ငှက်သည် ပင်လယ်ရေအောက်သို့ ငုပ်လျှိုးပျံသန်းရန် မဖြစ်နိုင်သဖြင့် ၎င်းတို့မှာ GPS ဂြိုဟ်တု အမြင့်တိုင်းတာမှု ချို့ယွင်းချက် (Sensor Error) များ ဖြစ်ကြောင်း ချက်ချင်းသိနိုင်ပါသည်။ - အလွန်မြင့်မားသော ပျံသန်းမှုနှင့် အရှိန်နှုန်းများ (Extreme Weather / Migration Peaks) ဘယ်ဘက်ဂရပ်၏ အပေါ်ပိုင်းနှင့် ညာဘက်အစွန်တွင် အမြင့်ပေ
1,000mကျော်နှင့် အမြန်နှုန်း20 m/sကျော်အထိ ရောက်ရှိနေသော အနီရောင်Xအမှတ်များမှာ ခရီးဝေးရွှေ့ပြောင်းစဉ် အမြင့်ပေမြင့်မားစွာ လေစီးကြောင်းစီး၍ ပျံသန်းခဲ့သည့် ထူးခြားဖြစ်စဉ်များ ဖြစ်သည်။ speed_discrepancyဖြင့် GPS ခုန်ကူးမှု ဖမ်းယူခြင်းanomaliesဇယားတွင်speed_2dသည် ပုံမှန် (2 m/sခန့်) ပြနေသော်လည်းspeed_discrepancyတန်ဖိုး အလွန်မြင့်မားနေသော အတန်းများသည် အချိန်တိုအတွင်း GPS ကိုဩဒိနိတ် နေရာလွဲမှားခုန်ကူးသွားသည့် စက်ပိုင်းဆိုင်ရာ အမှားများကို ဖော်ပြနေခြင်း ဖြစ်သည်။

No comments:
Post a Comment
Note: Only a member of this blog may post a comment.