# Crop Prediction Model Using Machine Learning Algorithms
## 6 Experimental Results  
In this work, we used 15 different machine learning algorithms to model agriculture data, which recommend to farmers the most suitable crops to produce on the farm. Tabular data are used in this work for classification of the crop data. Data are collected from the Kaggle database, which is an online platform for scientists to share their research data [58]. The dataset includes several features, such as ratio of Nitrogen content (N), temperature, pH value of the soil, rainfall, humidity, ratio of Phosphorous content (K), and ratio of Potassium content (P) in the soil. The crop prediction dataset has 2200 records, which have 22 crop labels, such as apple, banana, rice, coffee, cotton, black gram, watermelon, chickpea, coconut, grapes, jute, kidney beans, grape, lentil, and orange. The dataset includes several features, such as the ratio of Nitrogen content (N), temperature, pH value of the soil, rainfall, humidity, ratio of Phosphorous content (K), and the ratio of Potassium content (P) in the soil. Sixty-seven percent of the data is used in training, and the rest of the data are used for testing. Table 1 shows accuracy values and error rates for the algorithms considered. Bayes Net, Naive Bayes Classifier, Hoeffding Tree, and Random Forest algorithms yield the best accuracy. The DT algorithm yields 88.50%, and the rest of the classification algorithms have more than 90% accuracy. Error metrics can be formalized as follows:  
\[\text{K}\;(\text{Kappa})=(\text{P}_{\text{o}}-\text{P}_{\text{e}})/(1-\text{P}_{ \text{e}}) \tag{1}\]  
where \(\text{P}_{\text{o}}\) is relative observed agreement and \(\text{P}_{\text{e}}\) is hypothetical probability of chance agreement. \[\text{MAE}\;(\text{Mean Absolute Error})valueI=\frac{\sum\limits_{\text{i=1} }^{\text{N}}\left|\text{y}_{\text{i}}-\text{x}_{\text{i}}\right|}{\text{n}} \tag{2}\]  
where n is the total number of data, \(\text{x}_{\text{i}}\) is the true value, and \(\text{y}_{\text{i}}\) is the prediction. \[\text{RMSE}\;(\text{Root Mean Square Error})=\sqrt{\frac{\left[\sum\limits_{ \text{i=1}}^{\text{n}}\left(\text{x}_{\text{i}}-\text{x}^{\prime}_{\text{i}} \right)\right]}{\text{n}}} \tag{3}\]  
where \(\text{x}_{\text{i}}\) is observed and \(\text{x}_{\text{i}}\)\({}^{\prime}\) is the predictive value. \[\text{RAE}\;(\text{Relative Absolute Error})=\frac{\sum\limits_{\text{i=1}}^{ \text{n}}\left|\text{y}_{\text{i}}-\text{y}^{\prime}_{\text{i}}\right|}{\sum \limits_{\text{i=1}}^{\text{n}}\left|\text{y}_{\text{i}}-\text{y}\right|} \tag{4}\]  
where y is the average value of the data. \[\text{Root Relative Squared Error}\;(\text{RMSE})=\text{A}=\sqrt{\frac{\sum \limits_{\text{i=1}}^{\text{n}}\left(\text{P}_{\text{i}}-\text{T}_{\text{j}} \right)^{2}}{\sum\limits_{\text{i=1}}^{\text{n}}\left(\text{T}_{\text{i}}- \text{T}\right)^{2}}} \tag{5}\]  
where P is the predicted value and T is the target value. \begin{table}
\begin{tabular}{l c c c c c c} \hline \hline
**Method** & **Accuracy (\%)** & **Kappa (0–1)** & **MAE** & **RMSE** & **RAE** & **RRSE** \\  & & **(0–1)** & **(0–1)** & **(0–1)** & **(\%)** & **(\%)** \\ \hline Bayes Net & 99.59 & 0.995 & 0.0010 & 0.018 & 1.14 & 8.64 \\ \hline Naive Bayes Classifier & 99.46 & 0.994 & 0.0009 & 0.020 & 1.05 & 9.73 \\ \hline Logistic & 97.99 & 0.979 & 0.0020 & 0.038 & 2.30 & 18.24 \\ \hline Multilayer Perception & 98.79 & 0.987 & 0.0046 & 0.033 & 5.33 & 16.18 \\ \hline Simple Logistic & 98.66 & 0.986 & 0.0025 & 0.029 & 2.88 & 14.03 \\ \hline IBK & 97.86 & 0.977 & 0.0032 & 0.043 & 3.69 & 21.05 \\ \hline KSTAR & 97.86 & 0.977 & 0.0036 & 0.038 & 4.11 & 18.47 \\ \hline LWL & 76.74 & 0.756 & 0.0752 & 0.188 & 86.59 & 90.26 \\ \hline Ada BoostM1 & 6.82 & 0.036 & 0.0829 & 0.203 & 95.51 & 97.79 \\ \hline Regression & 98.38 & 0.983 & 0.0099 & 0.042 & 11.41 & 20.44 \\ \hline Decision Table & 88.50 & 0.879 & 0.0565 & 0.145 & 65.10 & 69.61 \\ \hline Hoeffding Tree & 99.46 & 0.994 & 0.0009 & 0.020 & 1.05 & 9.74 \\ \hline J48 & 98.79 & 0.987 & 0.0012 & 0.032 & 1.35 & 15.36 \\ \hline \hline \end{tabular}
\end{table}