# Similarity-Based Decision Support for Improving Agricultural Practices and Plant Growth
## 2 Materials and Methods
### Algorithm Applied  
The K-Nearest Neighbour (KNN) algorithm is applied to the structured dataset composed of farmer profiles, each defined by a fixed set of attribute values [4; 14; 32; 33; 34; 35]. These attributes are categorized into categorical attributes (e.g., Soil Type, Climate, Pest Management) and numerical attributes (e.g., Water Temperature, Humidity Level), allowing the system to assess both qualitative and quantitative similarities between farmers.  
To fine-tune the performance of the KNN model, we evaluated the impact of varying the number of neighbours, \(k\). Several values were tested, including \(k=5\), 10, and 100, across datasets of different sizes. As shown in Table 1, while larger \(k\) values slightly increased stability, they also diluted the relevance of the neighbours by incorporating more dissimilar farmer profiles. Since our recommendation task values specificity and meaningful similarity, we selected \(k=3\) as the optimal choice. This value strikes a balance between accuracy and contextual relevance, ensuring recommendations are generated from the most similar farmers while maintaining computational efficiency.  
To better understand the recommendation process, we outline below the steps involved in computing farmer similarity:  
Step 1: Categorical Distance. The first step is to calculate the distance between our selected farmer and another from the list. If the value is the same as the query point, assign a distance of 0. If the value is different, assign a distance of 1. The compared farmer has the same soil type and pest management, but the climate is different. This yields a Categorical Distance, as computed in Equation (1) :  
\[C_{d}=0+0+1=1 \tag{1}\]  
Step 2: Numerical Distance. For the numerical attributes, the Euclidean distance between two points is used, \(A=(x_{1},y_{1},\dots)\) and \(B=(x_{2},y_{2},\dots)\), as given by Equation (2):  
\begin{table}
\begin{tabular}{c c c} \hline \hline \(k\) & **Accuracy (Cross-Validation)** & **Execution Time (s)** \\ \hline
3 & 91.2\% & 1.34 \\
5 & 89.7\% & 1.45 \\
10 & 87.1\% & 1.65 \\
100 & 79.5\% & 2.40 \\ \hline \hline \end{tabular}
\end{table}
Table 1: Effect of different \(k\) values on KNN performance.  
\[d(A,B)=\sqrt{(x_{2}-x_{1})^{2}+(y_{2}-y_{1})^{2}+\ldots} \tag{2}\]  
Now let us see this equation applied for two users having a watering temperature of 32 \({}^{\circ}\)C versus 34 \({}^{\circ}\)C. The difference would be \(32-34=-2\) and the squared difference would be \((-2)^{2}=4\). The same logic applied for the humidity level will conclude to the Euclidean distance from Equation (3):  
\[d(A,B)=\sqrt{4+144}\approx 12.17 \tag{3}\]  
Step 3: Total Distance. Step three consists of combining the Categorical and Numerical distances to obtain the Total Distance (Equation (4)). This should be applied to the selected user in combination with all the other users.  
\[T_{d}=C_{d}+d(A,B)=1+12.17=13.17 \tag{4}\]  
This is a practical way to implement the similarity-based algorithm in the agriculture section. By identifying these nearest neighbours, farmers can quickly find others facing similar challenges, allowing for knowledge exchange and more data-driven decisions [36].