الجيران الأقرب k
التصنيف حسب الأمثلة الأقرب
الجيران الأقرب k درس مجاني في Data Science Academy على CoddyKit. هذا هو الدرس 2 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في Data Science Academy، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة Data Science Academy 4 دروس في المجموع.
بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.
Judged by Your Neighbors
k-Nearest Neighbors classifies a point by looking at the examples closest to it. Birds of a feather end up in the same class. 🐦
No Real Training
kNN is a lazy learner: it just memorizes the data. The real work happens later, when a new point asks for a label.
Measure the Distance
To find who is near, the model computes a distance to every training point, most often plain straight-line distance.
Take a Vote
The closest k neighbors each cast a vote. Whichever class wins the majority becomes the prediction for the new point.
k Is the Key Choice
The letter k is how many neighbors you consult. It is the one knob that most shapes how kNN behaves.
Small k, Jumpy Borders
A tiny k, like 1, follows every wiggle in the data and reacts to noise, giving jagged, overfit boundaries.
Large k, Smoother Calls
A big k averages over many points for smoother decisions, but too large and it blurs the real differences between classes.
Scaling Is Not Optional
Distance is unfair if one feature spans thousands and another spans tenths. Always scale features so each counts equally.
Build the Classifier
Create it like any estimator and pick your n_neighbors right away. Here we consult the five closest points.
from sklearn.neighbors import KNeighborsClassifier
model = KNeighborsClassifier(n_neighbors=5)Fit, Then Predict
The familiar contract still applies: fit stores the data, predict finds neighbors and votes on the answer.
model.fit(X_train, y_train)
model.predict(X_test)Watch the Cost
kNN is simple but can be slow at prediction time, since every guess compares the new point to all stored examples.
Quick Check
Let's pin down the parameter that defines kNN.
Recap
kNN predicts by letting the closest k neighbors vote. Choose k with care and scale your features, and it works well. 🎯
الأسئلة الشائعة
هل درس «الجيران الأقرب k» مجاني؟
نعم — نص درس «الجيران الأقرب k» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة Data Science Academy، انتقل إلى CoddyKit PRO. تتضمن دورة Data Science Academy 4 دروس في المجموع.
ماذا ستتعلم في «الجيران الأقرب k»؟
التصنيف حسب الأمثلة الأقرب تتمرن على Data Science Academy مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.
هل أحتاج إلى خبرة سابقة لأبدأ Data Science Academy؟
لا تُشترط خبرة سابقة. Data Science Academy على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 2 من أصل 4.
كم من الوقت يستغرق درس «الجيران الأقرب k»؟
معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.
هل يمكنني كتابة وتشغيل أكواد في درس Data Science Academy هذا؟
نعم. كل درس في Data Science Academy يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.
جميع الدروس في هذه الدورة
- الانحدار اللوجستي لنعم أو لا
- الجيران الأقرب k
- أشجار القرار والغابات العشوائية
- أساسيات Gradient Boosting