K-nearest neighbors algorithm: Difference between revisions

Content deleted Content added
rm COI / selfcite
No edit summary
Tags: nowiki added Visual edit
Line 1:
'''''<big>خوارزمية أقرب k  من الجيران</big>'''''{{Distinguish|k-means clustering}} '''''<big>k لا تكن متحير من</big>'''''
{{DISPLAYTITLE:''k''-nearest neighbors algorithm}}
{{Machine learning bar}}
'''''<big>- المتوسط الحسابي للمجموعه</big>'''''
In [[pattern recognition]], the '''''k''-nearest neighbors algorithm''' ('''''k''-NN''') is a [[Non-parametric statistics|non-parametric]] method used for [[statistical classification|classification]] and [[regression analysis|regression]].<ref>{{cite journal |last=Altman |first=N. S. |authorlink=Naomi Altman|title=An introduction to kernel and nearest-neighbor nonparametric regression |journal=The American Statistician |volume=46 |issue=3 |year=1992 |pages=175–185 |doi=10.1080/00031305.1992.10475879|hdl=1813/31637 |url=https://ecommons.cornell.edu/bitstream/1813/31637/1/BU-1065-MA.pdf }}</ref> In both cases, the input consists of the ''k'' closest training examples in the [[feature space]]. The output depends on whether ''k''-NN is used for classification or regression:
 
In [[pattern recognition]], the '''''k''-nearest neighbors algorithm''' ('''''k''-NN''') is a [[Non-parametric statistics|non-parametric]] method used for [[statistical classification|classification]] and [[regression analysis|regression]].<ref>{{cite journal |last=Altman |first=N. S. |authorlink=Naomi Altman|title=An introduction to kernel and nearest-neighbor nonparametric regression |journal=The American Statistician |volume=46 |issue=3 |year=1992 |pages=175–185 |doi=10.1080/00031305.1992.10475879|hdl=1813/31637 |url=https://ecommons.cornell.edu/bitstream/1813/31637/1/BU-1065-MA.pdf }}</ref> In both cases, the input consists of the ''k'' closest training examples in the [[feature space]]. The output depends on whether ''k''-NN is used for classification or regression '''<big>من K في تمييز الانماط , تعد خوارزمية أقرب</big>'''
:* In ''k-NN classification'', the output is a class membership. An object is classified by a plurality vote of its neighbors, with the object being assigned to the class most common among its ''k'' nearest neighbors (''k'' is a positive [[integer]], typically small). If ''k''&nbsp;=&nbsp;1, then the object is simply assigned to the class of that single nearest neighbor.
 
:<big>'''طريقة غير ثابتة تستخدم للتصنيف والانحدار . (K_NN) الجيران'''</big> . '''<big>للتصنيف أو الإنحدار (K_NN) . في كلتا الحالتين ، يتكون الإدخال من أقرب عينات التدريب في مساحة الميزة .يعتمد الناتج على اذا ما كانت</big>'''
:*In ''k-NN classification'', the output is a class membership. An object is classified by a plurality vote of its neighbors, with the object being assigned to the class most common among its ''k'' nearest neighbors (''k'' is a positive [[integer]], typically small). If ''k''&nbsp;=&nbsp;1, then the object is simply assigned to the class of that single nearest neighbor.
 
'''<big>الناتج عبارة عن عضوية صفية . يتم تصنيف العينة المستهدفة بتصويت متعدد من جيرانه ، حيث يتم تعيين هذه العينة إلى الفئة الأكثر شيوعًا K_NN في تصنيف</big>'''
 
:'''<big>( عدد صحيح موجب صغير عادة K) . من الجيران K بين أقرب</big>''' '''<big>k=1 إذا كانت</big>''' '''<big>فسيتم تعيين العينة المقصودة ببساطة إلى فئة أقرب جار منفرد.</big>'''
:*In ''k-NN regression'', the output is the property value for the object. This value is the average of the values of ''k'' nearest neighbors. '''<big>، الناتج هو قيمة مملوكة للعينة المستهدفة . K_NNفي الإنحدار</big>'''
 
'''<big>أقرب للجيران k هذه القيمة هي المتوسط الحسابي للقيم .</big>'''
 
:* In ''k-NN regression'', the output is the property value for the object. This value is the average of the values of ''k'' nearest neighbors.
 
''k''-NN is a type of [[instance-based learning]], or [[lazy learning]], where the function is only approximated locally and all computation is deferred until classification.
 
'''<big>هو نوع من التعلم القائم على العينة ، أو التعلم الكسول ، حيث يتم فقط تقريب الدالة محليًا ويتم تأجيل جميع العمليات الحسابية حتى التصنيف. K_NN</big>'''
 
Both for classification and regression, a useful technique can be to assign weights to the contributions of the neighbors, so that the nearer neighbors contribute more to the average than the more distant ones. For example, a common weighting scheme consists in giving each neighbor a weight of 1/''d'', where ''d'' is the distance to the neighbor.<ref>This scheme is a generalization of linear interpolation.</ref>
 
'''<big>سواء بالنسبة للتصنيف أو الانحدار ، يمكن أن تكون التقنية مفيدة في تعيين قيم (وزن ) لمساهمات الجيران ، بحيث يساهم الجيران الأقرب للمتوسط  الحسابي أكثر من الجيران البعيدين. على سبيل المثال ، يتكون مخطط القيم المشتركة من إعطاء كل جار قيمه قدرها</big>'''
 
'''<big>1/d حيث ال d هي المسافة الى الجار</big>'''
 
The neighbors are taken from a set of objects for which the class (for ''k''-NN classification) or the object property value (for ''k''-NN regression) is known. This can be thought of as the training set for the algorithm, though no explicit training step is required.
 
'''<big>يتم أخذ الجيران من مجموعة من العينات المستهدفة التي تعرف فئتها</big>'''
 
'''<big>(لتصنيف K_NN)</big>'''
 
'''<big>القيمة المملوكة للعينة المستهدفة</big>'''
 
'''<big>من أجل الإنحدار K_NN</big>'''
 
'''<big>.يمكن اعتبار ذلك بمثابة مجموعة تدريب للخوارزمية ، على الرغم من عدم الحاجة إلى خطوة تدريب واضحة.</big>'''
 
A peculiarity of the ''k''-NN algorithm is that it is sensitive to the local structure of the data.
 
'''<big>من خصائص خوارزمية</big>'''
 
'''<big>K_NN</big>'''
 
'''<big>أنها حساسة للبنية المحلية للبيانات</big>'''
 
==Statistical setting==
Suppose we have pairs <math>(X_1,Y_1), (X_2,Y_2), \dots, (X_n, Y_n) </math> taking values in <math>\mathbb{R}^d \times \{1,2\}</math>, where {{mvar|Y}} is the class label of {{mvar|X}}, so that <math>X|Y=r \sim P_r</math> for <math>r=1,2</math> (and probability distributions <math>P_r</math>). Given some norm <math>\|\cdot\|</math> on <math>\mathbb{R}^d</math> and a point <math>x \in \mathbb{R}^d</math>, let <math>(X_{(1)},Y_{(1)}), \dots, (X_{(n)}, Y_{(n)}) </math> be a reordering of the training data such that <math> \|X_{(1)}-x\| \leq \dots \leq \|X_{(n)}-x\| </math>
 
 
'''<big>افترض أن لدينا أزواج</big>'''
 
'''<big>(X_1,Y_1), (X_2,Y_2), \dots, (X_n, Y_n)</big>'''
 
'''<big>تأخذ قيم</big>'''
 
'''<big>mathbb{R}^d \times \{1,2\}</big>'''
 
'''<big>حيث Y هو تصنيف X بحيث X|Y=r \sim P_r لr=1,2(توزيعات الاحتمال P<sub>r</sub></big>'''
 
'''<big>بالنظر الى بعض القواعد</big>'''
 
'''<big>\|\cdot\| على \mathbb{R}^d والنقطة x \in \mathbb{R}^d</big>'''
 
'''<big>اجعل (X_{(1)},Y_{(1)}), \dots, (X_{(n)}, Y_{(n)})</big>'''
 
'''<big>عبارة عن إعادة ترتيب لبيانات التدريب بحيث  </big>'''
 
'''<big>\|X_{(1)}-x\| \leq \dots \leq \|X_{(n)}-x\|</big>'''
 
<br />
==Algorithm==
'''<big>الألغوريتم</big>''' [[File:KnnClassification.svg|thumb|right|Example of ''k''-NN classification. The test sample (green dot) should be classified either to blue squares or to red triangles.
 
If ''k = 3'' (solid line circle) it is assigned to the red triangles because there are 2 triangles and only 1 square inside the inner circle.
 
If ''k = 5'' (dashed line circle) it is assigned to the blue squares (3 squares vs. 2 triangles inside the outer circle).]]
 
'''<big>مثال على تصنيف K_NN</big>'''
 
'''<big>. يجب تصنيف عينة الاختبار (النقطة الخضراء) إما على شكل مربعات زرقاء أو مثلثات حمراء. إذا كانت k = 3 (خط مستمر(غير متقطع) دائري) يتم تعيينها إلى المثلثات الحمراء نظرًا لوجود مثلثين ومربع واحد فقط داخل الدائرة الداخلية.</big>'''
 
'''<big>إذا كانت K=5</big>'''
 
'''<big>دائرة الخط المتقطع) ، يتم تعيينها إلى المربعات الزرقاء (3 مربعات مقابل  مثلثين داخل الدائرة الخارجية.</big>'''
 
<br />]]
 
The training examples are vectors in a multidimensional feature space, each with a class label. The training phase of the algorithm consists only of storing the [[feature vector]]s and class labels of the training samples.
 
أمثلة التدريب عبارة عن متجهات في مساحة الميزة متعددة الأبعاد ، ولكل منها تسمية لتصنيف . تتكون مرحلة تدريب الخوارزمية  فقط من تخزين متجهات الميزات و التصنيفات لعينات التدريب.
 
In the classification phase, ''k'' is a user-defined constant, and an unlabeled vector (a query or test point) is classified by assigning the label which is most frequent among the ''k'' training samples nearest to that query point.
 
'''<big>في مرحلة التصنيف ، يُعتبر</big>'''
 
'''<big>K</big>'''
 
'''<big>ثابتًا يحدده المستخدم ، و المتجه الغير مصنف (استعلام أو نقطة اختبار) يتم تصنيفها عن طريق تعيين سمة التصنيف الأكثر</big>'''
 
'''<big>شيوعا بين K</big>'''
 
'''<big>من عينات التدريب الأقرب إلى نقطة الاستعلام هذه.</big>'''
 
A commonly used distance metric for [[continuous variable]]s is [[Euclidean distance]]. For discrete variables, such as for text classification, another metric can be used, such as the '''overlap metric''' (or [[Hamming distance]]). In the context of gene expression microarray data, for example, ''k''-NN has been employed with correlation coefficients, such as Pearson and Spearman, as a metric.<ref>{{cite journal|last1=Jaskowiak|first1=P. A.|last2=Campello|first2=R. J. G. B.|title=Comparing Correlation Coefficients as Dissimilarity Measures for Cancer Classification in Gene Expression Data|publisher=Brazilian Symposium on Bioinformatics (BSB 2011)|pages=1–8|citeseerx=10.1.1.208.993}}</ref> Often, the classification accuracy of ''k''-NN can be improved significantly if the distance metric is learned with specialized algorithms such as [[Large Margin Nearest Neighbor]] or [[Neighbourhood components analysis]].
 
'''<big>مقياس المسافة الذي يشيع استخدامه للمتغيرات المستمرة هو المسافة</big>'''
 
'''<big>Euclidean .</big>'''
 
'''<big>بالنسبة للمتغيرات المنفصلة ، مثل تصنيف النص ، يمكن استخدام مقياس آخر ، مثل قياس التداخل أو (مسافة .</big>'''
 
'''<big>Hamming).</big>'''
 
'''<big>في سياق بيانات  المايكرواري لتعبير الجيني ، على سبيل المثال ، تم استخدام</big>'''
 
<span dir="RTL"></span>'''<big>k_NN مع معاملات الارتباط</big>'''
 
<span dir="RTL"></span>'''<big>مثل Pearson و Spearman</big>'''
 
<span dir="RTL"></span>'''<big>كمقياس. [3] في كثير من الأحيان يمكن تحسين دقة تصنيف</big>'''
 
<span dir="RTL"></span> '''<big>K_NN</big>'''
 
<span dir="RTL"></span>'''<big>بشكل ملحوظ إذا تم تعليم مقياس المسافة باستخدام خوارزميات متخصصة مثل أقرب أكبر حافة جيران او تحليل مكونات الجوار.</big>'''
 
A drawback of the basic "majority voting" classification occurs when the class distribution is skewed. That is, examples of a more frequent class tend to dominate the prediction of the new example, because they tend to be common among the ''k'' nearest neighbors due to their large number.<ref name="Coomans_Massart1982">{{Cite journal
Line 44 ⟶ 139:
}}
</ref> One way to overcome this problem is to weight the classification, taking into account the distance from the test point to each of its ''k'' nearest neighbors. The class (or value, in regression problems) of each of the ''k'' nearest points is multiplied by a weight proportional to the inverse of the distance from that point to the test point. Another way to overcome skew is by abstraction in data representation. For example, in a [[self-organizing map]] (SOM), each node is a representative (a center) of a cluster of similar points, regardless of their density in the original training data. ''K''-NN can then be applied to the SOM.
 
'''<big>يحدث العيب في التصنيف "تصويت الأغلبية" الأساسي عندما يكون توزيع الفئة منحرف بيانياً . وهذا يعني أن فئات العينات الأكثر شيوعًا تميل إلى السيطرة على التنبؤ بالعينة الجديدة ، لأنها تميل إلى أن تكون شائعة بين أقرب الجيران بسبب عددهم الكبير. [4] طريقة واحدة للتغلب على هذه المشكلة هي وضع قيم (وزن) للفئات , مع مراعاة المسافة من نقطة الاختبار إلى كل من</big>'''
 
'''<big>K اقرب للجيران ,</big>'''
 
'''<big>, يتم ضرب الفئة (أو القيمة ، في مشاكل الانحدار) لكل من أقرب النقاط</big>'''  
 
'''<big>K بوزن يتناسب مع معكوس المسافة من تلك النقطة إلى نقطة الاختبار. طريقة أخرى للتغلب على الانحراف هي عن طريق تجريد تمثيل البيانات</big>'''
 
'''<big>على سبيل المثال ، في الخريطة ذاتية التنظيم (SOM)</big>'''
 
'''<big>، كل عقدة تمثل (مركز) لمجموعة من النقاط المتشابهة ، بغض النظر عن كثافتها في بيانات التدريب الأصلية. يمكن بعد ذلك تطبيق</big>'''
 
'''<big>K-NN على (SOM)</big>'''
 
==Parameter selection==
The best choice of ''k'' depends upon the data; generally, larger values of ''k'' reduces effect of the noise on the classification,<ref>Everitt, B. S., Landau, S., Leese, M. and Stahl, D. (2011) Miscellaneous Clustering Methods, in Cluster Analysis, 5th Edition, John Wiley & Sons, Ltd, Chichester, UK.</ref> but make boundaries between classes less distinct. A good ''k'' can be selected by various [[heuristic (computer science)|heuristic]] techniques (see [[hyperparameter optimization]]). The special case where the class is predicted to be the class of the closest training sample (i.e. when ''k'' = 1) is called the nearest neighbor algorithm.
 
'''<big>أفضل خيار لإختيار K</big>'''
 
'''<big>يعتمد على البيانات ؛ عمومًا ، تقلل القيم الكبيرة ل K</big>'''
 
'''<big>من تأثير الضوضاء على التصنيف ،</big>'''
 
'''<big>لكنها تجعل الحدود بين الفئات أقل تمييزًا. يمكن اختيار K</big>'''
 
'''<big>بحيث تكون جيدة من خلال تقنيات ارشادية مختلفة (مثل تحسين hyperparameter)</big>'''
 
'''<big>الحالة الخاصة التي يُتوقع فيها أن تكون الفئه هي فئة عينة التدريب الأقرب  (أي عندما يكون</big>'''
 
'''<big> k = 1) تسمى خوارزمية أقرب جار    .</big>'''
 
 
The accuracy of the ''k''-NN algorithm can be severely degraded by the presence of noisy or irrelevant features, or if the feature scales are not consistent with their importance. Much research effort has been put into [[feature selection|selecting]] or [[feature scaling|scaling]] features to improve classification. A particularly popular{{citation needed|date=March 2013}} approach is the use of [[evolutionary algorithm]]s to optimize feature scaling.<ref>{{cite journal |vauthors=Nigsch F, Bender A, van Buuren B, Tissen J, Nigsch E, Mitchell JB |title=Melting point prediction employing k-nearest neighbor algorithms and genetic parameter optimization |journal=Journal of Chemical Information and Modeling |volume=46 |year=2006 |issue=6 |pages=2412–2422 |doi=10.1021/ci060149f |pmid=17125183}}</ref> Another popular approach is to scale features by the [[mutual information]] of the training data with the training classes.{{Citation needed|date=December 2008}}
Line 61 ⟶ 185:
}}
</ref>
 
'''<big>يمكن أن تتدهور دقة خوارزمية K_NN</big>'''
 
'''<big>بشدة بسبب وجود ميزات خاطئة أو غير ملائمة ، أو إذا كانت قياسات الميزة غير متوافقة مع أهميتها. لقد تم بذل الكثير من الابحاث في اختيار الميزات أو توسيع نطاقها لتحسين التصنيف. هناك نهج شائع بشكل خاص وهو استخدام الخوارزميات التطورية لتحسين قياس الميزة. [6] هناك أسلوب شائع آخر يتمثل في توسيع نطاق الميزات من خلال المعلومات المتبادلة لتدريب البيانات مع تدريب الفئات.</big>'''
 
'''<big>في مشكلات التصنيف الثنائي (فئتين) ، من المفيد لإختيار K</big>'''
 
'''<big>ليكون عددا فرديا لأن هذا يتجنب التصويت المقيد. إحدى الطرق الشائعة لاختيار أفضل</big>'''
 
'''<big>K تجريبياً في هذا الإطار هي من خلال طريق</big>'''
 
'''<big>[7]bootstrap</big>'''  
 
==The {{math|1}}-nearest neighbor classifier==
'''<big>1-المصنف المجاور الاقرب</big>'''
 
The most intuitive nearest neighbour type classifier is the one nearest neighbour classifier that assigns a point {{mvar|x}} to the class of its closest neighbour in the feature space, that is <math>C_n^{1nn}(x) = Y_{(1)}</math>.
 
 
As the size of training data set approaches infinity, the one nearest neighbour classifier guarantees an error rate of no worse than twice the [[Bayes error rate]] (the minimum achievable error rate given the distribution of the data).
 
'''<big>الأكثر بديهية في أقرب جارمن حيث التصنيف هو المصنف المجاوئ الأقرب الذي يعين نقطه X</big>'''
 
'''<big>إلى فئة أقرب جار لها في مساحة الميزه ، هذا هو </big>'''
 
'''<big>C_n^{1nn}(x) = Y_{(1)}</big>'''
 
'''<big>مع اقتراب حجم مجموعه تدريب البيانات من لانهاية ، فان المصنف المجاور الأقرب يضمن معدل خطا لا يزيد عن ضعف معدل الخطا في</big>'''
 
'''<big>Bayes</big>'''
 
'''<big>(معدل الخطا الأدنى الممكن تحقيقه بالنظر إلى توزيع البيانات).</big>'''
 
==The weighted nearest neighbour classifier==
'''<big>المصنف المجاور المرجح الاقرب</big>'''
The {{mvar|k}}-nearest neighbour classifier can be viewed as assigning the {{mvar|k}} nearest neighbours a weight <math>1/k</math> and all others {{mvar|0}} weight. This can be generalised to weighted nearest neighbour classifiers. That is, where the {{mvar|i}}th nearest neighbour is assigned a weight <math>w_{ni}</math>, with <math>\sum_{i=1}^n w_{ni} = 1</math>. An analogous result on the strong consistency of weighted nearest neighbour classifiers also holds.<ref name = "Stone">{{Cite journal | author = Stone C. J.
 
The {{mvar|k}}-nearest neighbour classifier can be viewed as assigning the {{mvar|k}} nearest neighbours a weight <math>1/k</math> and all others {{mvar|0}} weight. This can be generalised to weighted nearest neighbour classifiers. That is, where the {{mvar|i}}th nearest neighbour is assigned a weight <math>w_{ni}</math>, with <math>\sum_{i=1}^n w_{ni} = 1</math>. An analogous result on the strong consistency of weighted nearest neighbour classifiers also holds.<ref name="Stone">{{Cite journal | author = Stone C. J.
| title = Consistent nonparametric regression
| journal = [[Annals of Statistics]]
Line 77 ⟶ 230:
</ref>
 
'''<big>يمكن رؤية المصنف المجاور</big>'''
Let <math>C^{wnn}_n</math> denote the weighted nearest classifier with weights <math>\{w_{ni}\}_{i=1}^n</math>. Subject to regularity conditions {{explain|date=January 2019}} on the class distributions the excess risk has the following asymptotic expansion<ref name="Samworth12"/>
 
'''<big>k  </big>'''
 
'''<big>الأقرب على أساس تعيين الجيران الأقرب</big>'''
 
'''<big>k بوزن</big>'''
 
'''<big>1/k</big>'''
 
'''<big>والياقي وزن 0</big>'''
 
'''<big>يمكن تعميم ذلك لتوزين(وضع قيم ل) أقرب الجيران المصنفيين . هذا هو ، حيث يتم تعيين وزن</big>'''
 
'''<big>w<sub>ni لأقرب ''i''th</sub></big>'''
 
'''<big>من الجيران باستخدام \sum_{i=1}^n w_{ni} = 1</big>'''
 
'''<big>نتيجة مماثلة على التطابق القوي للمصنفات الموزونه لأقرب الجيران لها أيضًا</big>'''
 
 
Let <math>C^{wnn}_n</math> denote the weighted nearest classifier with weights <math>\{w_{ni}\}_{i=1}^n</math>. Subject to regularity conditions {{explain|date=January 2019}} on the class distributions the excess risk has the following asymptotic expansion<ref name="Samworth12" />
 
'''<big>اجعل C^{wnn}_n</big>'''
 
'''<big>تدل على أقرب مصنف مرجح بالأوزان مع قيم  </big>'''
 
'''<big>\{w_{ni}\}_{i=1}^n</big>'''
 
'''<big>مع مراعاة لشروط الانتظام [بحاجة إلى مزيد من التوضيح] على توزيعات الفئات ، فإن المخاطرة الزائدة لها هي  توسع المقارب وهي كالتالي</big>'''
 
<br />
 
:<math>\mathcal{R}_\mathcal{R}(C^{wnn}_{n}) - \mathcal{R}_{\mathcal{R}}(C^{Bayes}) = \left(B_1 s_n^2 + B_2 t_n^2\right) \{1+o(1)\},</math>
 
for constants <math>B_1</math> and <math>B_2</math> where <math>s_n^2 = \sum_{i=1}^n w_{ni}^2</math> and <math>t_n = n^{-2/d}\sum_{i=1}^n w_{ni}\{i^{1+2/d} - (i-1)^{1+2/d}\}</math>.
 
'''<big>لثوابت B1 , B2</big>'''
 
The optimal weighting scheme <math>\{w_{ni}^*\}_{i=1}^n</math>, that balances the two terms in the display above, is given as follows: set <math>k^* = \lfloor B n^{\frac 4 {d+4}} \rfloor</math>,
 
:<math>w_{ni}^* = \frac 1 {k^*} \left[1 + \frac d 2 - \frac d {2{k^*}^{2/d}} \{ i ^{1+2/d} - (i-1)^{1+2/d}\}\right] </math> for <math>i=1,2,\dots,k^*</math> and
مخطط الترجيح الأمثل \{w_{ni}^*\}_{i=1}^n
 
'''<big>الذي يوازن بين المصطلحين في العرض أعلاه ، ويرد على النحو التالي:</big>'''
 
:<math>w_{ni}^* = \frac 1 {k^*} \left[1 + \frac d 2 - \frac d {2{k^*}^{2/d}} \{ i ^{1+2/d} - (i-1)^{1+2/d}\}\right] </math> for <math>i=1,2,\dots,k^*</math> and
:<math> w^*_{ni} = 0 </math> for <math> i = k^*+1,\dots,n</math>.
 
With optimal weights the dominant term in the asymptotic expansion of the excess risk is <math>\mathcal{O}(n^{-\frac 4 {d+4}})</math>. Similar results are true when using a [[bootstrap aggregating|bagged nearest neighbour classifier]].
 
'''<big>مع الأوزان المثالية ، فإن المصطلح السائد في التوسع المقارب للمخاطر الزائدة هو</big>'''
 
'''<big><nowiki>\mathcal{O}(n^{-\frac 4 {d+4}})</nowiki></big>'''
 
'''<big>تكون النتائج المماثلة صحيحة عند استخدام مصنف مجاور أقرب.</big>'''
 
==Properties==
Line 107 ⟶ 306:
}}
</ref>
 
'''<big>KNN هي حالة خاصة لمقدار كثافة النطاق الترددي المتغير "بالون" ، مع نواة موحدة</big>'''
 
The naive version of the algorithm is easy to implement by computing the distances from the test example to all stored examples, but it is computationally intensive for large training sets. Using an approximate [[nearest neighbor search]] algorithm makes ''k-''NN computationally tractable even for large data sets. Many nearest neighbor search algorithms have been proposed over the years; these generally seek to reduce the number of distance evaluations actually performed.
 
'''<big>من السهل تنفيذ الإصدار البسيط من الخوارزمية عن طريق حساب المسافات من عينة الاختبار إلى جميع العينات المخزنة ، لكنه مكثف حسابيًا لمجموعات التدريب الكبيرة. باستخدام خوارزمية أقرب بحث تقريبي للجيران يجعل</big>'''
 
'''<big>k-NN</big>'''
 
'''<big>قابلاً للتتبع حسابيًا حتى بالنسبة لمجموعات البيانات الكبيرة. تم اقتراح العديد من خوارزميات البحث عن الجوار على مدار السنين ؛ تسعى هذه عمومًا إلى تقليل عدد التقييمات عن بُعد التي تم تنفيذها فعليًا.</big>'''
 
 
''k-''NN has some strong [[consistency (statistics)|consistency]] results. As the amount of data approaches infinity, the two-class ''k-''NN algorithm is guaranteed to yield an error rate no worse than twice the [[Bayes error rate]] (the minimum achievable error rate given the distribution of the data).<ref>{{cite journal |url=http://ssg.mit.edu/cal/abs/2000_spring/np_dens/classification/cover67.pdf|doi=10.1109/TIT.1967.1053964 |author=[[Thomas M. Cover|Cover TM]], [[Peter E. Hart|Hart PE]] |title=Nearest neighbor pattern classification |journal=IEEE Transactions on Information Theory |year=1967 |volume=13 |issue=1 |pages=21–27|citeseerx=10.1.1.68.2616 }}</ref> Various improvements to the ''k''-NN speed are possible by using proximity graphs.<ref>{{cite journal |doi=10.1142/S0218195905001622 |author=Toussaint GT |title=Geometric proximity graphs for improving nearest neighbor methods in instance-based learning and data mining |journal=International Journal of Computational Geometry and Applications |volume=15 |issue=2 |date=April 2005 |pages=101–150}}</ref>
 
'''<big>KNN لديه بعض نتائج التطابق القوية. مع اقتراب كمية البيانات من اللانهاية</big>'''
 
'''<big>فإن خوارزمية K_NN</big>'''
 
'''<big>المكونة من فئتين مضمونة لتنتج معدل خطأ لا يزيد عن ضعف معدل خطأ بايز (الحد الأدنى لمعدل الخطأ القابل للتحقيق بالنظر إلى توزيع البيانات). [12] يمكن إجراء تحسينات مختلفة على سرعة</big>'''
 
'''<big>k-NNباستخدام الرسوم البيانية القريبة</big>'''
 
For multi-class ''k-''NN classification, [[Thomas M. Cover|Cover]] and [[Peter E. Hart|Hart]] (1967) prove an upper bound error rate of
 
بالنسبة لتصنيف KNN متعددة الطبقات
 
'''<big>يثبت Cover and Hart (1967) معدل الخطأ أعلى من الحد الأقصى</big>'''
 
:<math>R^* \ \leq \ R_{k\mathrm{NN}} \ \leq \ R^* \left(2 - \frac{MR^*}{M-1}\right)</math>
Line 118 ⟶ 338:
where <math>R^*</math>is the Bayes error rate (which is the minimal error rate possible), <math>R_{kNN}</math> is the ''k-''NN error rate, and {{mvar|M}} is the number of classes in the problem. For <math>M=2</math> and as the Bayesian error rate <math>R^*</math> approaches zero, this limit reduces to "not more than twice the Bayesian error rate".
 
'''<big>حيث  R* هو معدل الخطأ Bayes (وهو الحد الأدنى لمعدل الخطأ الممكن) R_{kNN}</big>'''
==Error rates==
There are many results on the error rate of the {{mvar|k}} nearest neighbour classifiers.<ref name = "PTPR">{{cite book |author = Devroye, L., Gyorfi, L. & Lugosi, G. |year = 1996 |title = A probabilistic theory of pattern recognition| publisher=Springer | isbn=978-0-3879-4618-4}}</ref> The {{mvar|k}}-nearest neighbour classifier is strongly (that is for any joint distribution on <math> (X, Y)</math>) [[Bayes classifier|consistent]] provided <math>k:=k_n</math> diverges and <math>k_n/n</math> converges to zero as <math>n \to \infty</math>.
 
'''<big>ومعدل الخطأ k-NN</big>'''
Let <math> C_n^{knn} </math> denote the {{mvar|k}} nearest neighbour classifier based on a training set of size {{mvar|n}}. Under certain regularity conditions, the [[Bayes classifier|excess risk]] yields the following asymptotic expansion<ref name = "Samworth12">{{Cite journal | author = Samworth R. J.
 
<span dir="RTL"></span>'''<big>{{mvar|M}} :عدد الفئات في المكشلة</big>'''
 
<span dir="RTL"></span>'''<big>بالنسبة الى M =2</big>'''
 
<span dir="RTL"></span>'''<big>,ومع اقتراب معدل الخطأ</big>'''
 
<span dir="RTL"></span>'''<big>Bayesian من الصفر</big>'''
 
<span dir="RTL"></span> '''<big>، يقلل هذا الحد إلى "ليس أكثر من ضعف معدل الخطأ</big>'''
 
<span dir="RTL"></span>'''<big>Bayesian" .</big>'''
 
<br />
 
== Error rates ==
'''<big>معدلات الخطأ</big>'''
 
There are many results on the error rate of the {{mvar|k}} nearest neighbour classifiers.<ref name="PTPR">{{cite book |author = Devroye, L., Gyorfi, L. & Lugosi, G. |year = 1996 |title = A probabilistic theory of pattern recognition| publisher=Springer | isbn=978-0-3879-4618-4}}</ref> The {{mvar|k}}-nearest neighbour classifier is strongly (that is for any joint distribution on <math> (X, Y)</math>) [[Bayes classifier|consistent]] provided <math>k:=k_n</math> diverges and <math>k_n/n</math> converges to zero as <math>n \to \infty</math>.
 
'''<big>هناك العديد من النتائج على معدل الخطأ لأقرب مصنفات الجيران</big>'''
 
'''<big>k.</big>'''
 
'''<big>يكون مصنف الجوار الأقرب</big>'''
 
'''<big>k</big>'''
 
'''<big>قويًا (أي بالنسبة لأي توزيع مشترك على  </big>'''
 
'''<big>(X, Y)</big>'''
 
'''<big>k:=k_n متناسقًا بشرط أن تتحول</big>'''
 
'''<big>ويتحول   k_n/n</big>'''
 
'''<big>الى صفر لما n \to \infty</big>'''
 
Let <math> C_n^{knn} </math> denote the {{mvar|k}} nearest neighbour classifier based on a training set of size {{mvar|n}}. Under certain regularity conditions, the [[Bayes classifier|excess risk]] yields the following asymptotic expansion<ref name="Samworth12">{{Cite journal | author = Samworth R. J.
| title = Optimal weighted nearest neighbour classifiers
| journal = [[Annals of Statistics]]
Line 132 ⟶ 390:
}}
</ref>
 
<br />
 
:'''<big>دع C_n^{knn}</big>'''
:'''<big>تدل على أقرب تصنيف لجار K</big>'''
:'''<big>بناءً على مجموعة تدريب بالحجم N</big>'''
:'''<big>في ظل ظروف انتظام معينة ، ينتج عن  المخاطرة الزائدة لها هي كالتالي توسع المقارب</big>'''
::<math>\mathcal{R}_\mathcal{R}(C^{knn}_{n}) - \mathcal{R}_{\mathcal{R}}(C^{Bayes}) = \left\{B_1\frac 1 k + B_2 \left(\frac k n\right)^{4/d}\right\} \{1+o(1)\},</math>
 
for some constants <math> B_1 </math> and <math> B_2 </math>.
 
'''<big>لبعض الثوابت B1 و   B2</big>'''
 
The choice <math>k^* = \lfloor B n^{\frac 4 {d+4}} \rfloor</math> offers a trade off between the two terms in the above display, for which the <math>k^*</math>-nearest neighbour error converges to the Bayes error at the optimal ([[minimax]]) rate <math>\mathcal{O}(n^{-\frac 4 {d+4}})</math>.
 
'''<big><nowiki>يوفر الاختيار  k^* = \lfloor B n^{\frac 4 {d+4}} \rfloor</nowiki></big>'''
 
'''<big>مفاضلة بين المصطلحين في الشاشة أعلاه ، حيث يتقارب الخطأ ل k^*</big>'''
 
'''<big>  أقرب الجيران  مع خطأ</big>'''
 
'''<big>Bayes</big>'''
 
'''<big>على النحو الأمثل (الحد الأدنى) لمعدل</big>'''
 
'''<big><nowiki>\mathcal{O}(n^{-\frac 4 {d+4}})</nowiki></big>'''
 
==Metric learning==
'''<big>التعلم القياسي</big>'''
 
The K-nearest neighbor classification performance can often be significantly improved through (supervised) metric learning. Popular algorithms are [[neighbourhood components analysis]] and [[large margin nearest neighbor]]. Supervised metric learning algorithms use the label information to learn a new [[Metric (mathematics)|metric]] or [[Pseudometric space|pseudo-metric]].
 
'''<big>غالبًا ما يمكن تحسين أداء تصنيف</big>'''
 
'''<big>K  - الجار الأقرب بشكل كبير من خلال التعلم القياسي (الخاضع للإشراف). الخوارزميات الشعبية هي تحليل مكونات الجوار و أقرب أكبر حافة جيران . تستخدم خوارزميات التعليم القياسي الخاضعة للإشراف معلومات التصنيف لتعلم القياس الجديد أو القياس الزائف.</big>'''
 
<br />
==Feature extraction==
'''<big>ميزة الاستخراج</big>'''
 
When the input data to an algorithm is too large to be processed and it is suspected to be redundant (e.g. the same measurement in both feet and meters) then the input data will be transformed into a reduced representation set of features (also named features vector). Transforming the input data into the set of features is called [[feature extraction]]. If the features extracted are carefully chosen it is expected that the features set will extract the relevant information from the input data in order to perform the desired task using this reduced representation instead of the full size input. Feature extraction is performed on raw data prior to applying ''k''-NN algorithm on the transformed data in [[feature space]].
 
'''<big>عندما تكون بيانات الإدخال إلى خوارزمية كبيرة جدًا بحيث لا يمكن معالجتها ويشتبه في أنها زائدة عن الحاجة (على سبيل المثال القياس في كل من القدمين والأمتار هو نفسه) ، فسوف يتم تحويل بيانات الإدخال إلى تقليل التمثيل من مجموعة الميزات (تسمى أيضًا ميزات المتجهات ). يسمى تحويل بيانات الإدخال إلى مجموعة من الميزات استخراج الميزة. إذا تم اختيار الميزات المستخرجة بعناية ، فمن المتوقع أن تقوم مجموعة الميزات باستخراج المعلومات ذات الصلة من بيانات الإدخال من أجل أداء المهمة المطلوبة باستخدام هذا التمثيل المخفض بدلاً من الإدخال بالحجم الكامل</big>'''
 
'''<big>يتم إجراء استخراج المعالم على البيانات الأولية قبل تطبيق خوارزمية k-NN</big>'''
 
'''<big>على البيانات المحولة في مساحة الميزة.</big>'''
 
An example of a typical [[computer vision]] computation pipeline for [[Facial recognition system|face recognition]] using ''k''-NN including feature extraction and dimension reduction pre-processing steps (usually implemented with [[OpenCV]]):
 
'''<big>مثال على خط أساسي في حساب رؤية الكمبيوتر النموذجيه للتعرف على الوجوه باستخدام k-NN بما في ذلك خطوات استخراج ما قبل المعالجة وتقليل الأبعاد (عادة ما يتم تنفيذها باستخدام OpenCV)</big>'''
 
# [[Haar wavelet|Haar]] face detection
Line 150 ⟶ 446:
# [[Principal Component Analysis|PCA]] or [[Linear discriminant analysis|Fisher LDA]] projection into feature space, followed by ''k''-NN classification
 
 
'''<big>1.      كشف الوجه Haar</big>'''
 
'''<big>2.      تحليل مسار التحول المتوسط</big>'''
 
'''<big>3.      PCA  او Fisher LDR  الاسقاط في مساحة الميزة , تليها تصنيف k-NN</big>'''
 
<br />
==Dimension reduction==
'''<big>تخفيض البعد</big>'''
 
For high-dimensional data (e.g., with number of dimensions more than 10) [[dimension reduction]] is usually performed prior to applying the ''k''-NN algorithm in order to avoid the effects of the [[Curse of Dimensionality|curse of dimensionality]].
<ref>Beyer, Kevin, et al.. [https://minds.wisconsin.edu/bitstream/handle/1793/60174/TR1377.pdf?sequence=1 'When is “nearest neighbor” meaningful?]. Database Theory—ICDT’99, 217-235|year 1999</ref>
 
 
'''<big>بالنسبة للبيانات  كثيرة الأبعاد (على سبيل المثال ، عدد الأبعاد أكثر من 10)</big>'''
 
'''<big>يتم إجراء تقليص للبعد عادة قبل تطبيق خوارزمية k-NN  </big>'''
 
'''<big>لتفادي تأثيرات لعنة الأبعاد</big>'''
 
The curse of dimensionality in the ''k''-NN context basically means that [[Euclidean distance]] is unhelpful in high dimensions because all vectors are almost equidistant to the search query vector (imagine multiple points lying more or less on a circle with the query point at the center; the distance from the query to all data points in the search space is almost the same).
 
'''<big>تعني لعنة الأبعاد في سياق</big>'''
 
'''<big>k-NN</big>'''
 
'''<big>أساسًا أن المسافة Euclidean</big>'''
 
'''<big>غير مفيدة في الأبعاد الكثيرة لأن جميع المتجهات متساوية تقريباً مع متجه الاستعلام (المتجهه المستهدفة)  (تخيل نقاط متعددة ملقاة أكثر أو أقل على دائرة مع نقطة الاستعلام في المركز ؛ المسافة من الاستعلام إلى جميع نقاط البيانات في مساحة البحث هي نفسها تقريبًا).</big>'''
 
[[Feature extraction]] and dimension reduction can be combined in one step using [[Principal Component Analysis|principal component analysis]] (PCA), [[linear discriminant analysis]] (LDA), or [[Canonical correlation|canonical correlation analysis]] (CCA) techniques as a pre-processing step, followed by clustering by ''k''-NN on [[Feature (machine learning)|feature vectors]] in reduced-dimension space. In [[machine learning]] this process is also called low-dimensional [[embedding]].<ref>Shaw, Blake, and Tony Jebara. 'Structure preserving embedding. Proceedings of the 26th Annual International Conference on Machine Learning. ACM,2009</ref>
 
'''<big>يمكن دمج استخراج المعالم وتقليل الأبعاد في خطوة واحدة باستخدام تحليل المكون الرئيسي</big>'''
 
'''<big>(PCA)</big>'''
 
'''<big>أو تحليل التمييز الخطي (LDA) ،</big>'''
 
'''<big>تقنيات تحليل الارتباط الكنسي (CCA)</big>'''
 
'''<big>كخطوة ما قبل المعالجة ، متبوعة بالتجميع بواسطة k-NN</big>'''
 
'''<big>على الميزة المتجهات في مساحة منخفضة البعد. في التعلم الآلي ، تسمى هذه العملية أيضًا التضمين المنخفض الأبعاد</big>'''
 
For very-high-dimensional datasets (e.g. when performing a similarity search on live video streams, DNA data or high-dimensional [[time series]]) running a fast '''approximate''' ''k''-NN search using [[Locality Sensitive Hashing|locality sensitive hashing]], "random projections",<ref>Bingham, Ella, and Heikki Mannila. [https://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.24.5135&rep=rep1&type=pdf Random projection in dimensionality reduction: applications to image and text data]. Proceedings of the seventh ACM SIGKDD international conference on Knowledge discovery and data mining. ACM | year 2001</ref> "sketches" <ref>Shasha, D High Performance Discovery in Time Series.Berlin: Springer, 2004, {{ISBN|0-387-00857-8}}</ref> or other high-dimensional similarity search techniques from the [[VLDB conference|VLDB]] toolbox might be the only feasible option.
 
'''<big>بالنسبة إلى مجموعات البيانات كثيرة الأبعاد للغاية (على سبيل المثال ، عند إجراء بحث تشابه على تدفق فيديو مباشر أو بيانات الحمض النووي أو السلاسل الزمنية كثيرة الأبعاد) التي تدير بحثًا تقريبيًا سريعًا بواسطة</big>'''
 
'''<big>k-NN</big>'''
 
'''<big>باستخدام التجزئة المحسّن للمواقع المحلية ، "الإسقاطات العشوائية" ، [17] " الرسومات "[18] أو غيرها من تقنيات البحث عن التشابه في الأبعاد الكثيرة من مربع الأدوات</big>'''
 
'''<big>VLDB قد يكون الخيار الوحيد الممكن</big>'''
 
== Decision boundary ==
'''<big>حدود القرار</big>'''
 
Nearest neighbor rules in effect implicitly compute the [[decision boundary]]. It is also possible to compute the decision boundary explicitly, and to do so efficiently, so that the computational complexity is a function of the boundary complexity.<ref>{{cite journal |doi=10.1007/s00454-004-1152-0 |vauthors=Bremner D, [[Erik Demaine|Demaine E]], Erickson J, [[John Iacono|Iacono J]], [[Stefan Langerman|Langerman S]], [[Pat Morin|Morin P]], [[Godfried Toussaint|Toussaint G]] |title=Output-sensitive algorithms for computing nearest-neighbor decision boundaries |journal=Discrete and Computational Geometry |volume=33 |issue=4 |year=2005 |pages=593–604}}</ref>
 
'''<big>أقرب قواعد الجيران سارية المفعول هو حساب الحدود القرار. من الممكن أيضًا حساب حدود القرار بشكل صريح ، والقيام بذلك بكفاءة ، بحيث يكون التعقيد الحسابي دالة على تعقيد الحدود.</big>'''
 
'''<big>[19]</big>'''
 
== Data reduction ==
'''<big>تقليل المعلومات</big>'''
 
Data reduction is one of the most important problems for work with huge data sets. Usually, only some of the data points are needed for accurate classification. Those data are called the ''prototypes'' and can be found as follows:
'''<big>يعد تقليل البيانات أحد أهم المشكلات للعمل مع مجموعات البيانات الضخمة. عادة ، هناك حاجة فقط لبعض نقاط البيانات للتصنيف الدقيق. تسمى هذه البيانات النماذج الأولية ويمكن العثور عليها على النحو التالي:</big>'''
 
# Select the ''class-outliers'', that is, training data that are classified incorrectly by ''k''-NN (for a given ''k'')
 
'''<big>حدد القيم المتطرفة ، أي بيانات التدريب التي تم تصنيفها بطريقة غير صحيحة بواسطة</big>'''
 
'''<big> k-NN</big>'''
 
'''<big>بالنسبة إلى</big>'''
 
'''<big>(k  )</big>'''
 
# Separate the rest of the data into two sets: (i) the prototypes that are used for the classification decisions and (ii) the ''absorbed points'' that can be correctly classified by ''k''-NN using prototypes. The absorbed points can then be removed from the training set.
 
'''<big>افصل بقية البيانات إلى مجموعتين: (1) النماذج الأولية المستخدمة لاتخاذ قرارات التصنيف و (2) النقاط الممتصة التي يمكن تصنيفها بشكل صحيح بواسطة</big>'''
 
'''<big>k-NN</big>'''
 
'''<big>باستخدام النماذج الأولية. يمكن بعد ذلك إزالة النقاط الممتصة من مجموعة التدريب.</big>'''
 
=== Selection of class-outliers ===
'''<big>اختيار الطبقة المتطرفة</big>'''
 
A training example surrounded by examples of other classes is called a class outlier. Causes of class outliers include:
'''<big>يُطلق على عينات التدريب المحاطه بعينات من الفئات الأخرى اسم الفئه المتطرفة.  تتضمن أسباب القيم الخارجية للفئة</big>'''
 
* random error
* insufficient training examples of this class (an isolated example appears instead of a cluster)
* missing important features (the classes are separated in other dimensions which we do not know)
* too many training examples of other classes (unbalanced classes) that create a "hostile" background for the given small class
 
* ·        '''<big>الخطأ العشوائي</big>'''
* '''<big>·        عينات تدريب غير كافيه لهذه الفئه (تظهر عينات معزوله(ليس لها علاقة ببعض) بدلاً من مجموعة)</big>'''
* '''<big>·           يفتقد الميزات الهامة (يتم فصل الطبقات في أبعاد أخرى لا نعرفها)</big>'''
* '''<big>الكثير من عينات التدريب لفئات أخرى (فئات غير متوازنة) تنشئ خلفية "معادية" للفئة الصغيرة المعينة</big>'''
 
Class outliers with ''k''-NN produce noise. They can be detected and separated for future analysis. Given two natural numbers, ''k>r>0'', a training example is called a ''(k,r)''NN class-outlier if its ''k'' nearest neighbors include more than ''r'' examples of other classes.
 
'''<big>القيم المتطرفة مع k-NN</big>'''
 
'''<big>تنتج ضوضاء.</big>'''
 
'''<big>يمكن اكتشافها وفصلها لتحليلها في المستقبل بالنظر إلى رقمين طبيعيين ،</big>'''
 
'''<big>k> r> 0</big>'''
 
'''<big>يُطلق على عينات التدريب اسم</big>'''
 
'''<big>''(k, r)'' NN  </big>'''
 
'''<big>الطبقة المتطرفه إذا كان أقرب جيرانه</big>'''
 
'''<big>K</big>'''
 
'''<big>يشتمل على أكثر من</big>'''
 
'''<big>rعينه للفئات الأخرى.</big>'''
 
<br />
 
=== CNN for data reduction ===
'''<big>CNN للحد من البيانات</big>'''
Condensed nearest neighbor (CNN, the ''[[Peter E. Hart|Hart]] algorithm'') is an algorithm designed to reduce the data set for ''k''-NN classification.<ref>[[Peter E. Hart|P. E. Hart]], The Condensed Nearest Neighbor Rule. IEEE Transactions on Information Theory 18 (1968) 515–516. {{doi|10.1109/TIT.1968.1054155}}</ref> It selects the set of prototypes ''U'' from the training data, such that 1NN with ''U'' can classify the examples almost as accurately as 1NN does with the whole data set.
 
Condensed nearest neighbor (CNN, the ''[[Peter E. Hart|Hart]] algorithm'') is an algorithm designed to reduce the data set for ''k''-NN classification.<ref>[[Peter E. Hart|P. E. Hart]], The Condensed Nearest Neighbor Rule. IEEE Transactions on Information Theory 18 (1968) 515–516. {{doi|10.1109/TIT.1968.1054155}}</ref> It selects the set of prototypes ''U'' from the training data, such that 1NN with ''U'' can classify the examples almost as accurately as 1NN does with the whole data set.
[[File:BorderRAtio.PNG|thumb|130px|right|Calculation of the border ratio.]]
 
[[File:PointsTypes.png|thumb|130px|right|Three types of points: prototypes, class-outliers, and absorbed points.]]
'''<big>أقرب جوار مكثف</big>'''
 
'''<big>(CNN</big>'''
 
'''<big>، خوارزمية هارت( هي خوارزمية مصممة لتقليل مجموعة البيانات لتصنيف .</big>'''
 
'''<big>k</big>'''
 
'''<big>NN وهي تحدد مجموعة النماذج الأولية</big>'''
 
'''<big>U من بيانات التدريب ،</big>'''
 
'''<big>بحيث يمكن ل1NN  مع U</big>'''
 
'''<big>تصنيف العينات بدقة تقريبًا</big>'''
 
'''<big>كما يفعل1NN</big>'''
 
'''<big>مع مجموعة البيانات بأكملها</big>'''.[[File:BorderRAtio.PNG|thumb|130px|right|Calculation of the border ratio.حساب نسبة الحدود.]]
[[File:PointsTypes.png|thumb|130px|right|Three types of points: prototypes, class-outliers, and absorbed points.ثلاثة أنواع من النقاط: النماذج الأولية ، القيم المتطرفة ، والنقاط الممتصة.]]
Given a training set ''X'', CNN works iteratively:
 
'''<big>بالنظر إلى مجموعة التدريب X ، تعمل CNN بشكل متكرر:</big>'''
 
# Scan all elements of ''X'', looking for an element ''x'' whose nearest prototype from ''U'' has a different label than ''x''.
# Remove ''x'' from ''X'' and add it to ''U''
# Repeat the scan until no more prototypes are added to ''U''.
 
'''<big>1.     اكشف عن جميع عناصر X ، ابحث عن العنصر x حيث له أقرب نموذج أولي من U له تصنيف مختلف عن x</big>'''
 
'''<big>2.     أزل x من X وأضفها إلى U</big>'''
 
'''<big>3.     كرر الفحص حتى لا يتم إضافة المزيد من النماذج الأولية إلى .U</big>'''
 
Use ''U'' instead of ''X'' for classification. The examples that are not prototypes are called "absorbed" points.
 
'''<big>استخدم U بدلاً من X للتصنيف</big>'''
It is efficient to scan the training examples in order of decreasing border ratio.<ref name = "MirkesKnn">E. M. Mirkes, [http://www.math.le.ac.uk/people/ag153/homepage/KNN/KNN3.html KNN and Potential Energy: applet.] University of Leicester, 2011.</ref> The border ratio of a training example ''x'' is defined as
 
'''<big>. العينات التي ليست لها نماذج أولية تسمى نقاط "المماص " .</big>'''
 
It is efficient to scan the training examples in order of decreasing border ratio.<ref name="MirkesKnn">E. M. Mirkes, [http://www.math.le.ac.uk/people/ag153/homepage/KNN/KNN3.html KNN and Potential Energy: applet.] University of Leicester, 2011.</ref> The border ratio of a training example ''x'' is defined as
 
'''<big>إنه فعال للكشف عن عينات التدريب من أجل خفض نسبة الحدود. [21] يتم تعريف نسبة الحدود لعينة التدريب</big>'''  
 
'''<big>x</big>'''
 
: {{math|1= ''a''(''x'') = {{sfrac|{{mabs|{{mabs|''x'-y''}}}}|{{mabs|{{mabs|''x-y''}}}}}} }}
 
where {{math|{{mabs|{{mabs|''x-y''}}}}}} is the distance to the closest example ''y'' having a different color than ''x'', and {{math|{{mabs|{{mabs|''x'-y''}}}}}} is the distance from ''y'' to its closest example ''x' '' with the same label as ''x''.
 
'''<big>حيث ||''x-y''|| هي المسافة إلى أقرب عينة</big>'''
 
'''<big>y ذات لون مختلف عن x ، و || x'-y || هي المسافة من</big>'''
 
'''<big>y إلى أقرب عينة</big>'''
 
'''<big>x 'لها نفس التصنيف مثل x</big>'''  .
 
The border ratio is in the interval [0,1] because {{math|{{mabs|{{mabs|''x'-y''}}}}}}never exceeds {{math|{{mabs|{{mabs|''x-y''}}}}}}. This ordering gives preference to the borders of the classes for inclusion in the set of prototypes ''U''. A point of a different label than ''x'' is called external to ''x''. The calculation of the border ratio is illustrated by the figure on the right. The data points are labeled by colors: the initial point is ''x'' and its label is red. External points are blue and green. The closest to ''x'' external point is ''y''. The closest to ''y'' red point is ''x' ''. The border ratio {{math|1= ''a''(''x'') = {{mabs|{{mabs|''x'-y''}}}} / {{mabs|{{mabs|''x-y''}}}} }}is the attribute of the initial point ''x''.
 
'''<big>تقع نسبة الحد في الفاصل الزمني [0،1] لأن</big>'''
Below is an illustration of CNN in a series of figures. There are three classes (red, green and blue). Fig. 1: initially there are 60 points in each class. Fig. 2 shows the 1NN classification map: each pixel is classified by 1NN using all the data. Fig. 3 shows the 5NN classification map. White areas correspond to the unclassified regions, where 5NN voting is tied (for example, if there are two green, two red and one blue points among 5 nearest neighbors). Fig. 4 shows the reduced data set. The crosses are the class-outliers selected by the (3,2)NN rule (all the three nearest neighbors of these instances belong to other classes); the squares are the prototypes, and the empty circles are the absorbed points. The left bottom corner shows the numbers of the class-outliers, prototypes and absorbed points for all three classes. The number of prototypes varies from 15% to 20% for different classes in this example. Fig. 5 shows that the 1NN classification map with the prototypes is very similar to that with the initial data set. The figures were produced using the Mirkes applet.<ref name = "MirkesKnn"/>
 
'''<big>|| x'-y || لا تتجاوز أبدًا || x-y ||.</big>'''
<gallery caption="CNN model reduction for k-NN classifiers" widths="200px">
 
File:Data3classes.png|Fig. 1. The dataset.
'''<big>يعطي هذا الترتيب الأفضلية لحدود الفئات لإدراجها في مجموعة النماذج الأولية</big>'''
File:Map1NN.png|Fig. 2. The 1NN classification map.
 
File:Map5NN.png|Fig. 3. The 5NN classification map.
'''<big>U. تسمى نقطة التصنيف المختلفة عن</big>'''
File:ReducedDataSet.png|Fig. 4. The CNN reduced dataset.
 
File:Map1NNReducedDataSet.png|Fig. 5. The 1NN classification map based on the CNN extracted prototypes.
'''<big>x خارجية إلى x . يتضح حساب نسبة الحدود من خلال الشكل الموجود على اليمين.</big>'''
 
'''<big>يتم تمييز نقاط البيانات حسب الألوان: النقطة الأولية هي</big>'''
 
'''<big>x والتصنيف باللون الأحمر. النقاط الخارجية زرقاء وخضراء.</big>'''
 
'''<big>الأقرب إلى النقطة الخارجية</big>'''
 
'''<big>x هي y .الأقرب إلى النقطة الحمراء y هي x.</big>'''
 
'''<big>نسبة الحدود a (x) = || x'-y || / || x-y || هي سمة النقطة الأولية x  .</big>'''
 
Below is an illustration of CNN in a series of figures. There are three classes (red, green and blue). Fig. 1: initially there are 60 points in each class. Fig. 2 shows the 1NN classification map: each pixel is classified by 1NN using all the data. Fig. 3 shows the 5NN classification map. White areas correspond to the unclassified regions, where 5NN voting is tied (for example, if there are two green, two red and one blue points among 5 nearest neighbors). Fig. 4 shows the reduced data set. The crosses are the class-outliers selected by the (3,2)NN rule (all the three nearest neighbors of these instances belong to other classes); the squares are the prototypes, and the empty circles are the absorbed points. The left bottom corner shows the numbers of the class-outliers, prototypes and absorbed points for all three classes. The number of prototypes varies from 15% to 20% for different classes in this example. Fig. 5 shows that the 1NN classification map with the prototypes is very similar to that with the initial data set. The figures were produced using the Mirkes applet.<ref name="MirkesKnn" />
 
'''<big>فيما يلي توضيح لشبكة CNN</big>'''
 
'''<big>في سلسلة من الأشكال.</big>'''
 
'''<big>هناك ثلاث فئات (الأحمر والأخضر والأزرق). الشكل 1: في البداية يوجد 60 نقطة في كل فئه.</big>'''
 
'''<big>يوضح الشكل 2 خريطة تصنيف</big>'''
 
'''<big>1NN</big>'''
 
'''<big>يتم تصنيف كل بكسل بواسطة</big>'''
 
'''<big>1NN</big>'''
 
'''<big>باستخدام جميع البيانات. يوضح الشكل 3 خريطة تصنيف</big>'''
 
'''<big>5NN</big>'''
 
'''<big>تتوافق المساحات البيضاء مع المناطق غير المصنفة ، حيث يتم تضييق التصويت</big>'''
 
'''<big>5NN</big>'''
 
'''<big>(على سبيل المثال ، إذا كانت هناك نقطتان خضراء واثنتان حمراء وواحدة زرقاء بين 5 من أقرب الجيران). يوضح الشكل 4 مجموعة البيانات المنخفضة. التقاطع هي القيم المتطرفة التي حددتها</big>'''
 
'''<big>2NN</big>'''
 
'''<big>جميع الثلاث جيران الاقرب لهذه الحالات ينتمون إلى فئات أخرى) ؛ المربعات هي النماذج الأولية ، والدوائر الفارغة هي النقاط الممتصة. يُظهر الركن السفلي الأيسر أرقام القيم الخارجية للنماذج الأولية والنقاط الممتصة للفئات الثلاثة. يتراوح عدد النماذج الأولية من 15 ٪ إلى 20 ٪ لفئات مختلفة في هذا العينة. يوضح الشكل 5  خريطة التصنيف</big>'''
 
'''<big>1NN</big>'''
 
'''<big>مع النماذج الأولية مشابهة جدًا لتلك الموجودة في مجموعة البيانات الأولية. تم إنتاج الأرقام باستخدام برنامج ميركس الصغير.</big>''' ]
 
<gallery widths="200" caption="CNN model reduction for k-NN classifiers">
File:Data3classes.png|Fig. 1. The dataset. الشكل الأول قاعدة بيانات
File:Map1NN.png|Fig. 2. The 1NN classification map.لشكل 2. خريطة التصنيفات 1NN
File:Map5NN.png|Fig. 3. The 5NN classification map.خريطة التصنيفات
File:ReducedDataSet.png|Fig. 4. The CNN reduced dataset.                     الشكل 4. مجموعة البيانات المنخفضة                                 
File:Map1NNReducedDataSet.png|Fig. 5. The 1NN classification map based on the CNN extracted prototypes.                  الشكل الخامس : خريطة التصنيفات تستند على نماذج المستخرجة
</gallery>
 
== ''k''-NN regression ==
الانحدار k-NN
 
In ''k''-NN regression, the ''k''-NN algorithm{{citation needed|date=September 2019}} is used for estimating continuous variables. One such algorithm uses a weighted average of the ''k'' nearest neighbors, weighted by the inverse of their distance. This algorithm works as follows:
 
'''<big>في انحدار k-NN ، تُستخدم خوارزمية k-NN [بحاجة لمصدر]</big>'''
 
'''<big>لتقدير المتغيرات المستمرة. تستخدم إحدى هذه الخوارزميات متوسطًا مرجحًا لأقرب الجيران k ،</big>'''
 
'''<big>موزونًا بعكس المسافة. تعمل هذه الخوارزمية كما يلي:</big>'''
 
# Compute the Euclidean or [[Mahalanobis distance]] from the query example to the labeled examples.
Line 213 ⟶ 716:
# Find a heuristically optimal number ''k'' of nearest neighbors, based on [[RMSE]]. This is done using cross validation.
# Calculate an inverse distance weighted average with the ''k''-nearest multivariate neighbors.
 
'''<big>1.    حساب المسافة Euclidean  أو Mahalanobis من عينة الاستعلام إلى عينات التصنيف.</big>'''
 
'''<big>2.       ترتيب عينات التصنيف عن طريق زيادة المسافة.</big>'''
 
'''<big>3.     ابحث عن رقم k الأمثل لأقرب الجيران ، بناءً على RMSE. يتم ذلك باستخدام التحقق من الصحة.</big>'''
 
'''<big>حساب متوسط معكوس المسافة المرجح مع أقرب k من الجيران متعددة المتغيرات</big>'''
 
==''k''-NN outlier==
k-NN للقيم المتطرفة
 
The distance to the ''k''th nearest neighbor can also be seen as a local density estimate and thus is also a popular outlier score in [[anomaly detection]]. The larger the distance to the ''k''-NN, the lower the local density, the more likely the query point is an outlier.<ref>{{cite conference | doi = 10.1145/342009.335437| title = Efficient algorithms for mining outliers from large data sets| conference = Proceedings of the 2000 ACM SIGMOD international conference on Management of data – SIGMOD '00| pages = 427| year = 2000| last1 = Ramaswamy | first1 = S. | last2 = Rastogi | first2 = R. | last3 = Shim | first3 = K. | isbn = 1-58113-217-4}}</ref> Although quite simple, this outlier model, along with another classic data mining method, [[local outlier factor]], works quite well also in comparison to more recent and more complex approaches, according to a large scale experimental analysis.<ref name="CamposZimek2016">{{cite journal|last1=Campos|first1=Guilherme O.|last2=Zimek|first2=Arthur|last3=Sander|first3=Jörg|last4=Campello|first4=Ricardo J. G. B.|last5=Micenková|first5=Barbora|last6=Schubert|first6=Erich|last7=Assent|first7=Ira|last8=Houle|first8=Michael E.|title=On the evaluation of unsupervised outlier detection: measures, datasets, and an empirical study|journal=Data Mining and Knowledge Discovery|volume=30|issue=4|pages=891–927|year=2016|issn=1384-5810|doi=10.1007/s10618-015-0444-8}}</ref>
 
'''<big>يمكن أيضًا اعتبار المسافة إلى</big>'''
 
'''<big>''k''th</big>'''
 
'''<big> أقرب جار قريب كتقدير للكثافة المحلية وبالتالي فهي أيضًا درجة شائعة متطرفة في اكتشاف الحالات الشاذة. كلما زادت المسافة إلى</big>'''
 
'''<big>k-NN</big>'''
 
'''<big>، انخفضت الكثافة المحلية ، وكانت نقطة الاستعلام أكثر احتمالًا لتكون متطرفة. [22] على الرغم من بساطته ، إلا أن هذا النموذج الخارجي ، إلى جانب طريقة أخرى لاستخراج البيانات ، وهو عامل خارجي محلي ، يعمل جيدًا أيضًا مقارنة بالأساليب الأكثر حداثة وتعقيدًا ، وفقًا لتحليل تجريبي واسع النطاق</big>'''
 
==Validation of results==
التحقق من النتائج
 
A [[confusion matrix]] or "matching matrix" is often used as a tool to validate the accuracy of ''k''-NN classification. More robust statistical methods such as [[likelihood-ratio test]] can also be applied.
 
'''<big>غالبا</big>'''
 
'''<big>ما يتم استخدام مصفوفة الارتباك أو "مصفوفة المطابقة" كأداة للتحقق من دقة تصنيف</big>'''
 
'''<big>k-NN.</big>'''
 
'''<big>يمكن أيضًا تطبيق طرق إحصائية أكثر قوة مثل اختبار نسبة الاحتمال.</big>'''
 
==See also==