Cross-validation၊ Overfitting နှင့် Clustering

scikit-learn 1.9.1

Split အမျိုးမျိုးမှာ model ရလဒ် တိုင်းပါ။ Label မပါတဲ့ row တွေကို K-means ဘယ်လို စုဖွဲ့လဲ လေ့လာပါ။

ဒီစာမျက်နှာမှာ

Fold အများကြီးနဲ့ အကဲဖြတ်ခြင်း

Cross-validation က training fold တွေပေါ် ထပ်ခါတလဲလဲ fit လုပ်ပြီး ဖယ်ထားတဲ့ validation fold တွေပေါ် score တိုင်းပါတယ်။ Training data မှာပဲ setting ရွေးဖို့ သုံးပြီး နောက်ဆုံး test set ပေါ် တစ်ခါ အကဲဖြတ်ပါ။ Training score မြင့်ပြီး validation score သိသိသာသာ နိမ့်ရင် overfit ဖြစ်နိုင်ပါတယ်။

from sklearn.linear_model import LinearRegression
from sklearn.model_selection import cross_val_score

X = [[1], [2], [3], [4], [5], [6]]
y = [3, 5, 7, 9, 11, 13]
scores = cross_val_score(LinearRegression(), X, y, cv=3, scoring="neg_mean_absolute_error")
print([round(-float(score) + 0.0, 6) for score in scores])
နမူနာ ရလဒ်
[0.0, 0.0, 0.0]

Label မပါဘဲ အုပ်စုခွဲခြင်း

K-means က Euclidean distance နဲ့ အနီးဆုံး center ကို point တွဲပြီး cluster အတွင်း squared distance နည်းအောင် ရှာပါတယ်။ Unit ကွာတာကြောင့် distance ကို feature တစ်ခုက လွှမ်းမိုးရင် scale လုပ်ပါ။ အုပ်စုတူပေမယ့် label number ပြောင်းနိုင်ပါတယ်။

from sklearn.cluster import KMeans

points = [[1], [2], [3], [9], [10], [11]]
model = KMeans(n_clusters=2, n_init=10, random_state=42).fit(points)
print(sorted(model.cluster_centers_.ravel().tolist()))
နမူနာ ရလဒ်
[2.0, 10.0]

တရားဝင် ကိုးကားချက်များ