# Classification of Retail Products: From Probabilistic Ranking to Neural Networks
## 6 Nearest-Neighbors Model  
The nearest neighbor (NN) [48] rule is a nonparametric method for classification based on instances. Taking into account the problem in Figure 2, a product in the MDD-DS \(p\) follows the definition \(\{p_{1},p_{2},\ldots,p_{n},v\}\), where \(n\) is the number of the aforementioned product attributes, and \(v\) is its assigned product variety. The KNN approach [31] classifies an unlabelled product on the majority of similar sample products among the k-nearest neighbors in MDD-DS that are the closest to the unlabelled product. The distances between the unlabelled product and each of the training product samples are determined by a specific distance measure. Therefore, the variety of new product \(\vec{p}\) is assigned to the most common variety among its closest \(k\) training samples according to the attributes considered in the product vectors. More formally, let \(unlabel-p\) an unlabelled product, the decision rule predicts a variety \(\hat{v}\) for the \(unlabel-p\) according to the variety \(v\) of the majority of its \(k\) nearest neighbors; in the case of a tie, \(\hat{v}\) is given by the closest nearest neighbor that belongs to one of the tied varieties. One of the problems for KNN is to give equivalent importance to each of the samples to determine the class membership, neglecting the typicality among them. Alternatively, some challenges arise for classification in a high dimensionality dataset where it is complex to discriminate between classes. This problem is due to the fact that the number of training samples and the increase in dimensionality grow overwhelmingly. The aforementioned \begin{table}
\begin{tabular}{l l l l l} \hline \hline  & \multicolumn{1}{c}{**’oil’**} & \multicolumn{1}{c}{**’olive’**} & \multicolumn{1}{c}{\(\cdots\)} & \multicolumn{1}{c}{**’aromatic’**} \\ \hline
**Almonds / hazelnuts** & 0 & 0 & \(\cdots\) & 0 \\ \hline \(\vdots\) & \(\vdots\) & \(\vdots\) & \(\cdots\) & \(\vdots\) \\ \hline
**Virgin and Extra virgin Olive Oil** & 233 & 224 & \(\cdots\) & 0 \\ \hline \(\vdots\) & \(\vdots\) & \(\vdots\) & \(\cdots\) & \(\vdots\) \\ \hline
**Juices (100\%)** & 0 & 0 & \(\cdots\) & 0 \\ \hline \hline \end{tabular}
\end{table} 
Table 6: Example of a _variety matrix_. drawbacks have been addressed in the literature by Fuzzy Sets Theory to allow imprecise knowledge to be represented and fuzzy measures to be introduced. Consequently, FKNN is a fuzzy version of the KNN classification algorithm [32]. Fuzzy classifiers delay the decision to assign a sample to a certain class by using _memberships_. In terms of our problem in Figure 2, FKNN assigns to an \(unlabel\_p\) a variety's fuzzy membership (not just true or false) by taking into account the _distance_ from \(unlabel\_p\) to its \(k\) nearest neighbors and those neighbors' memberships for this variety. More formally:  
* Variety membership is defined for each product \(\vec{p}\) in MDD-DS with a value in \([0,1]\) for each variety \(v\). Although the details can be found in [32], the main idea is assigning to each product \(\vec{p}\) a membership value for a variety \(v\) not just according to the assigned variety (true value) but also according to the assigned variety for its \(k\) nearest neighbors. * Besides given an unlabeled product \(unlabel\_p\), each neighboring product \(\vec{p}=\{p_{1},p_{2},\ldots,\)\(p_{m},v\}\) votes for every variety \(\{v_{1},v_{2},\ldots,v_{m}\}\) by using its variety memberships (not just for its assigned one \(v\)). Again, the details can be found in [32], but votes are weighted according to the inverse of the distance to \(unlabel\_p\) and added. The estimated variety \(\vartheta\) for \(unlabel\_p\) is the variety with the greatest combined vote. The main benefit of using the FKNN model may not be decreasing the error rate, but, more importantly, the model provides a degree of certainty that can be used with a \"refuse to decide\" option. Therefore, objects with overlapping classes can be detected and processed separately.