Crop Prediction Model Using Machine Learning Algorithms

: Machine learning applications are having a great impact on the global economy by transforming the data processing method and decision making. Agriculture is one of the ﬁelds where the impact is signiﬁcant, considering the global crisis for food supply. This research investigates the potential beneﬁts of integrating machine learning algorithms in modern agriculture. The main focus of these algorithms is to help optimize crop production and reduce waste through informed decisions regarding planting, watering, and harvesting crops. This paper includes a discussion on the current state of machine learning in agriculture, highlighting key challenges and opportunities, and presents experimental results that demonstrate the impact of changing labels on the accuracy of data analysis algorithms. The ﬁndings recommend that by analyzing wide-ranging data collected from farms, incorporating online IoT sensor data that were obtained in a real-time manner, farmers can make more informed verdicts about factors that affect crop growth. Eventually, integrating these technologies can transform modern agriculture by increasing crop yields while minimizing waste. Fifteen different algorithms have been considered to evaluate the most appropriate algorithms to use in agriculture, and a new feature combination scheme-enhanced algorithm is presented. The results show that we can achieve a classiﬁcation accuracy of 99.59% using the Bayes Net algorithm and 99.46% using Naïve Bayes Classiﬁer and Hoeffding Tree algorithms. These results will indicate an increase in production rates and reduce the effective cost for the farms, leading to more resilient infrastructure and sustainable environments. Moreover, the ﬁndings we obtained in this study can also help future farmers detect diseases early, increase crop production efﬁciency, and reduce prices when the world is experiencing food shortages.


Introduction
Agriculture is a vital element that has a significant role in nourishing the world's growing population.To keep pace with the increasing demand for foodstuffs, farmers need to make the best use of them to reap output while minimizing losses.Forecasting and examining reap growth is a serious part of modern agriculture, and machine learning has become a powerful tool to achieve this goal line [1,2].Smart farming, or precision agriculture, is a modern farming conduct that utilizes recent technology to optimize reap production and minimize waste.Smart farming aims to increase reap output while minimizing using resources such as water, fertilizer, and energy [3].
Figure 1 illustrates IoT and machine learning-based crop analysis and prediction processes.Over the years, numerous elements and technologies have been integrated into the architecture of a smart farm, such as sensing and monitoring systems, Internet of Things (IoT) sensors, data analytics and Artificial Intelligence (AI), precision agriculture techniques, remote monitoring and control, automated systems, livestock management systems, cloud computing and big data storage, energy management, and farm management software, to enhance farming practices and boost productivity [4][5][6].In smart farming, the Internet of Things is considered one of the key contributing technologies used.IoT sensors can be utilized to monitor soil moisture, temperature, and other environmental aspects [7], and the gathered data from the IoT sensors can be used to define the best time to plant, water, and harvest reaps.By using IoT sensors, farmers can guarantee that the reaps receive the right amount of water and nutrients, which can improve their quality and yield [8,9].
data.Data from different platforms are incorporated into the data processing operations.Analysis using these collected data makes data cleaning and preprocessing more critical while using machine learning algorithms.
Machine learning algorithms can analyze vast amounts of data from IoT sensors and other sources.It is a rapidly growing field that has the potential to transform the way we predict and analyze crop growth and output.Machine learning algorithms use statistical/mathematical models and algorithms to analyze data and make predictions, enabling computer systems to learn and improve from experience without being explicitly programmed [14].In agriculture, especially in the cultivation area, machine learning algorithms can be trained on comprehensive data collected from farms, such as weather patterns, soil properties, crop growth stages, and pest and disease outbreaks.By evaluating the collected data, machine learning models can forecast reap growth, output, and quality with high accuracy [15].In recent years, machine learning applications have entered our lives in many areas, from health to defense industries and education to urbanization, and have taken an effective way in decision-making situations.At the same time, it started to produce information and technology solutions by forming the basis of the newly emerging search engine infrastructure, such as ChatGPT (Chat Generative Pretrained Transformer from the OpenAI [10], Google Bard [11], and similar AI-based chatbots and some other tools).Many research companies reveal that new trends will grow even more in various platforms.In this respect, the effect of machine learning-oriented systems and solutions in the technology field will increase its effectiveness as a huge multiplier, and many sectors, such as chip design [12] and traffic estimations [13], would be changed by enforcing machine learning models.
Generally, it is essential to collect and analyze accurate data using machine learning algorithms.The data collection is critical in both quality and size to obtain accurate results and make high predictions.In general, big data have size, speed, and various characteristics.Their large size helps eliminate randomness and allows the data to provide detailed results.In addition, large-scale analysis data could be more structured.Using more than one dataset from different sources in the analysis will provide a higher success rate.Many sources, such as sensors, social media, digital networks, physical devices, the stock market, and health centers, are sufficient data sources.This data can be accessed through APIs, web collection, and direct access paths.Data can be in two forms: static datasets or stream data.Data from different platforms are incorporated into the data processing operations.Analysis using these collected data makes data cleaning and preprocessing more critical while using machine learning algorithms.
Machine learning algorithms can analyze vast amounts of data from IoT sensors and other sources.It is a rapidly growing field that has the potential to transform the way we predict and analyze crop growth and output.Machine learning algorithms use statistical/mathematical models and algorithms to analyze data and make predictions, enabling computer systems to learn and improve from experience without being explicitly programmed [14].In agriculture, especially in the cultivation area, machine learning algorithms can be trained on comprehensive data collected from farms, such as weather patterns, soil properties, crop growth stages, and pest and disease outbreaks.By evaluating the collected data, machine learning models can forecast reap growth, output, and quality with high accuracy [15].
A noteworthy application of machine learning in agriculture is precision farming, which includes employing data and technology to optimize agricultural conducts such as fertilization, irrigation, and pest control to improve reap output and quality.Machine learning models can examine bulky amounts of data from several sources, such as satellite imagery, drone footage, and soil sensors, to craft comprehensive maps of reap growth, nutrient levels, and moisture content.Farmers can utilize these maps to regulate their farming conducts, such as applying fertilizer or watering specific field areas, to maximize reap output and minimize waste [16].Machine learning can also help farmers identify the most profitable crops to plant based on market demand and environmental factors.By analyzing historical market data and weather patterns, machine learning models can predict the demand for different crops and suggest optimal planting times and locations [17].This can help farmers maximize their profits while minimizing the risk of crop failure.In addition to predicting crop growth and output, machine learning can also analyze the quality of the harvested crops.Machine learning models can analyze the color, texture, and shape of fruits and vegetables to determine their ripeness and quality.This information can be used to optimize the harvesting process and ensure that only high-quality produce is sold to consumers [18,19].
There are several encounters for deploying machine learning in agriculture, such as the lack of data groundwork, high cost of sensors and other technology, and need for specialized proficiency to develop and maintain the different solutions.However, as more farms implement precision agriculture and gather data, the potential profits of deploying machine learning in agriculture will become more evident.It is worth mentioning that machine learning in agriculture is still in its early stages, and more research needs to be conducted in this area to realize this technology's potential fully.So far, the results are promising, and machine learning will likely become increasingly important [20].
In this study, the authors explore the effects of machine learning on multiple industries and present an overview of the methodologies utilized in various research studies.They emphasize the significance of gathering and analyzing precise data by applying machine learning algorithms to construct models that correctly predict labels based on the input data.This study discusses several classification algorithms, such as Decision Tree (DT), Naïve Bayes Classifier (NBC), Support Vector Machine (SVM), and Random Forest (RF), which can be employed to build such models.The authors predict that adopting machine learning-focused systems and solutions will significantly enhance efficiency and productivity, resulting in massive industry changes.
This paper is structured as follows: First, the introduction and background reading are presented in Section 1 to provide a comprehensive understanding of the topic.Then, in Section 2, a relevant literature review is presented.Section 3 introduces artificial intelligence in smart farming to delve deeper into the subject.Crop analysis and prediction-benefits and challenges are given in Section 4. Section 5 outlines the methodologies used in this study, followed by the presentation of the experimental results in Section 6. Lastly, Section 7 is dedicated to the conclusion and future recommendations.

Literature Review
Machine learning approaches and algorithms are utilized in crop yield prediction methods to improve the quality of the crop so that the farmer's profit is maximized.The quality of the agricultural sector is improved; hence, the overall economy is enhanced.This issue has been discussed in detail in the literature [21][22][23][24][25][26][27][28][29][30][31][32][33][34][35].In [21], a review of machine learning algorithms to predict palm oil yield is discussed.The authors conducted a comparative analysis of the related work, focusing on the suggested approaches' advantages, disadvantages, and limitations.Furthermore, based on the discussion and evaluation of the existing studies, the authors provided a new architecture based on machine learning methods to predict palm oil yield.
The authors in [22] focused on crop prediction and yield by studying soil quality, considering that soil properties have a major effect on crop production.The authors studied different soil properties, such as NPK (Nitrogen, Phosphorous, Potassium) levels, temperature, rainfall, moisture, PH value, and humidity.Comparative analyses concern three machine learning algorithms: Naïve Bayes, Logistic Regression, and Random Forest.
Moreover, the authors conducted a comparison between these algorithms concerning accuracy.A crop production model proposed in [23] aims to manage the produced crop using machine learning algorithms to help farmers in developing countries who are still using traditional methods and cannot recognize the correct market value of their products.The proposed system is based on three scenarios; firstly, choosing the best crops based on the farmer's location; secondly, providing guidance on soil preparation; and thirdly, providing the best way of crop marketing from farmer to consumer.The authors applied Support Vector Regression; Voting Regression techniques; Random Forest Regression algorithms; and proper real climate, weather, and soil data.
Due to the scarcity of natural resources around the world, the authors in [24] proposed to utilize supervised machine learning algorithms, such as K-Nearest Neighbor Support Vector Machine, Random Forest, and Artificial Neural Network, to help farmers make the proper decision regarding crop selection and production; therefore, the country's overall economic status will be improved.Observing the growth process of chili and cotton crops using mobile phone images and machine learning techniques is the subject of the study [24].The authors suggested a prediction method using the following supervised machine learning algorithms: Random Forest, Support Vector Machine, Decision Tree, K-Nearest Neighbor (K-NN), Gaussian Naïve Bayes (GNB), and logistic regression (LR).The authors claimed that the study might help in the smart-farming process by recognizing the best machine learning algorithm for better crop prediction and analysis, especially for chili and cotton crops.In [25], a dataset for soil prediction was collected from Tamil Nadu Agricultural University (TNAU), India, which involved 32 districts.Based on the comparative analysis of different machine learning algorithms, such as Naïve Bayes, Bayes Net, and Instance-Based Learner (IBK) algorithms, the authors claimed that the provided comparative results help farmers to make the proper decision regarding crop selection and production.The authors in [26] recommended 22 types of crops in this study and proposed a three-step framework: firstly, data preprocessing and feature extraction; secondly, classification; and, finally, performance evaluation.As a result of the comparison, the authors claimed that the best classifier for this problem is Naïve Bayes, with an accuracy of 99.45%.This research work would provide a better outcome if the authors performed the classification and performance evaluation for a real problem.
Since crop monitoring is considered the main domain in the smart-farming process and crop diseases are the main reason for yield losses, especially in developing countries, the authors in [27] provided a comprehensive survey on crop monitoring techniques concerning crop yield estimation and disease detection using deep learning models.Based on the results and comparison, the authors claimed that crop monitoring techniques using deep learning methods are more accurate and powerful than some developing countries' traditional methods.In [28], the authors proposed a novel technique based on Support Vector Machines for auxiliary information on real applications of the agriculture sector.The authors claimed that they obtained an accuracy of 91% compared to the existing applications.The farmers can use this proposed methodology to gain a better yield of the crops, and different governmental sectors can use it to improve crop productivity.However, the authors did not suggest any recommendations for fertilizer systems to improve crop management.
In [29], a machine learning and Multilayer Perception method, along with the quantity of rainfall, have been suggested by the authors to help farmers in making a proper decision regarding a harvest even before they start planting.Furthermore, the suggested method focuses on the optimal process for the marketing and storage of the crop.Based on the provided results, the authors claimed that the proposed method would be beneficial for farmers to improve agricultural yield outcomes.In [30], the main objective of this research was to predict crop productivity loss by utilizing linear regression methods based on data taken from the previous year's statistics.The models were created using real-world data, and the evaluation process was based on samples.The authors applied both Naïve Bayes and Decision Tree algorithms in this evaluation.They claimed that the proposed method Appl.Sci.2023, 13, 9288 5 of 20 improves production and maximizes the farmer's profit.In [31], the authors developed a web-based application for crop yield prediction to be used by farmers.This tool provides farmers with a list of various crops planted previously to predict and learn about the best crop to cultivate in the future.Furthermore, the tool can provide farmers with climate data and information to help them make the best decision regarding market demand and prices.
In [32], the author's survey's main objective was to evaluate the performance of different publications from 2016 to 2020 that aimed to predict fungal illnesses on the crops.The authors evaluated different machine learning algorithms utilized in the literature.As per the provided comparative results, the authors concluded that the best performance among all machine learning models, SVM, variations of choice trees, and Naïve Bayes has been widely utilized and gained the best results regarding the yearly prediction of crop diseases.In [33], using machine learning, the authors proposed a system for the early prediction of crop diseases in plants by utilizing the Convolutional Neural Network (CNN) method.The dataset that is taken from a village is trained and tested.Different diseases are collected in a database, and the classifier is trained to compare the accuracy and choose the one with high accuracy.The provided model helps farmers predict plant diseases and make the best decision regarding the type of crop to be planted.The authors in [34] recognized problems facing farmers in India regarding crop yield prediction; therefore, they collected datasets published online.To facilitate analyzing and studying data, the dataset was clustered using the K-Means Clustering algorithm, and the Naïve Bayes algorithm was used to recognize the best crop to plant.The provided analysis and results show that the proposed system is beneficial for farmers, not only for the early prediction of crop yields but also for selecting the best crop to plan.
Based on the above literature review, it can be noticed that this issue has been discussed in the literature from different perspectives.Most of the work in this field utilized machine learning algorithms to help farmers with crop prediction gain better yield and improve overall production.However, many research analyses did not consider a real problem for which to perform classification and performance evaluation.Further, the authors did not give clear notifications about the obtained accuracy.Exceptionally, in [26], the authors provided analysis and performance evaluation with an accuracy of 99.45%, but still on 22 selected crops only and not based on real data.With this paper, we aim to improve the performance of machine learning usage in smart farming by:

•
Presenting experimental results that demonstrate the impact of changing labels on the accuracy of data analysis algorithms.

•
The research outcome recommends that farmers could make more informed verdicts about factors that affect crop growth by analyzing wide-ranging data collected from farms, including real-time data from IoT sensors.

•
As per the provided analysis in this research work, the machine learning algorithms demonstrate a high level of classification accuracy.Notably, the Bayes Net algorithm achieved an impressive accuracy of 99.59%, while both the Naïve Bayes Classifier and Hoeffding Tree algorithms yielded a remarkable accuracy of 99.46%.These results highlight the efficacy and reliability of these algorithms in accurately classifying the given data.

•
Therefore, by integrating different technologies, the achieved results can be used as an indicator for the farmers to have early and informed decisions regarding crop prediction to improve productivity, and hence the overall economy will be improved, accordingly.

Machine Learning in Smart Farming
Innovative farming methods have profoundly transformed agriculture using advanced technologies to increase productivity, enhance sustainability, and lessen environmental harm.Machine learning (ML), a vital component of this change, has enabled various applications that simplify farming operations and better inform decision-making processes.
ML applications are widely used in livestock, water, soil, and crop management.ML improves animal welfare for livestock and boosts production, increasing sustainability via predictive modeling and real-time health monitoring [35].ML is exploited to optimize irrigation and water usage for water management by analyzing various parameters.The application of newly emerging ML technologies and large amounts of available weather and water data makes it easier to manage water resources.This is especially helpful because natural events can be unpredictable, and the relationships between them can be complicated [36].
In soil management, ML helps analyze soil health, predict nutrient needs, and conclude the factors affecting soil distribution controls [37].As in crop management, ML detects diseases and weeds, evaluates crop quality, recognizes species, and predicts crop yield.
Crop yield prediction is immensely important for farmers and policymakers, governments concerned with food security, and food marketing organizations [38].These stakeholders can use yield prediction models to make data-driven decisions and develop strategies for efficient resource allocation, food distribution, and price stabilization.This leads to a more resilient food system that can be assured by anticipating crop production changes.However, predicting crop production is a complex task, as it is affected by many factors, such as weather conditions, the kind of fertilizer used, soil type, and the variety of seeds.Consequently, tackling this task necessitates the incorporation of diverse datasets and a range of attribute types.
Supervised learning techniques benefit crop yield prediction among the numerous ML categories.This is due to their robust predictive capabilities and ability to handle different attribute types.These methods employ labeled data to forecast outcomes based on specific inputs.For example, they project crop yields based on weather conditions and soil quality data.
Forecasting crop yield can be achieved using a broad spectrum of ML techniques, including Artificial Neural Networks (ANNs), Support Vector Machines, and Random Forests [39][40][41][42].These algorithms' ability to process historical and up-to-date information regarding weather, soil conditions, and crop health facilitates precise crop yield predictions.The resulting insights enable farmers to make educated decisions about planting, irrigation, and fertilization, ultimately leading to optimized yields and less resource wastage.
Machine learning is already playing an important role in providing farmers with information to make agriculture more efficient and productive, hence maximizing their profits.Therefore, farmers are highly encouraged to apply ML algorithms and techniques efficiently, especially while collecting, processing, and analyzing data.ML technology can provide a solution to most challenges farmers face [43].It can help them predict the weather more accurately, decrease waste, boost output, and increase profit margins.In this regard, farmers are motivated to use the advanced technology to collect data, such as autonomous vehicles, variable rate technology, GPS-based soil sampling, automated hardware, telematics, software, sensors, cameras, robots, drones, GPS guidance, and control systems [44].
According to [45], two-thirds of the farmers worldwide struggle to use technology, and more than 50% are unaware of the existing solutions.Teaching farmers to work with machine learning can be a transformative step in modernizing agriculture and improving productivity.While AI technology may seem daunting to some, there are ways to educate farmers about the benefits of smart farming and the usage of machine learning algorithms.Farmers need to be aware of the great benefits they may achieve if they use automation and AI on their farms.Training and informative workshops are the fastest ways to do so.This training needs to include foundation knowledge of ML, identifying use cases in agriculture, the importance of data collection and preparation for better prediction, ML algorithms and their best applications, and addressing concerns or misconceptions related to ethical and privacy considerations.They should be introduced to success stories of smart farms and encouraged to increase collaboration and share knowledge with their peers.A very important point is to introduce them to user-friendly tools and platforms that do not Appl.Sci.2023, 13, 9288 7 of 20 require programming skills for easy adaption.Since ML is a rapidly evolving field and new techniques and tools emerge frequently, we should encourage farmers to continue learning and stay updated with the latest developments in the field.
Despite the optimistic outlook of ML in agriculture, similar to any ML issue, the quality of the results is predominantly influenced by the quality of the input data.The efficacy of crop yield prediction depends heavily on the quality and availability of data.Crop prediction requires wide-ranging data, including weather, soil, historical yield, and satellite imagery.Guaranteeing data quality through efficient collection, preprocessing, and feature selection is critical in model development.However, agricultural big data introduces several challenges, which will be examined in the following section.

Crop Analysis and Prediction Benefits and Challenges
As stated earlier, while machine learning is being exploited in multiple fields, it remains an active area of research and a challenging one in the agricultural domain.This section summarizes the main benefits and challenges ML faces when used in crop analysis and predictions based on recent research [46][47][48][49][50]. Figure 2 shows AI-based crop analysis and prediction phases.
and AI on their farms.Training and informative workshops are the fastest ways to do so.This training needs to include foundation knowledge of ML, identifying use cases in agriculture, the importance of data collection and preparation for better prediction, ML algorithms and their best applications, and addressing concerns or misconceptions related to ethical and privacy considerations.They should be introduced to success stories of smart farms and encouraged to increase collaboration and share knowledge with their peers.A very important point is to introduce them to user-friendly tools and platforms that do not require programming skills for easy adaption.Since ML is a rapidly evolving field and new techniques and tools emerge frequently, we should encourage farmers to continue learning and stay updated with the latest developments in the field.
Despite the optimistic outlook of ML in agriculture, similar to any ML issue, the quality of the results is predominantly influenced by the quality of the input data.The efficacy of crop yield prediction depends heavily on the quality and availability of data.Crop prediction requires wide-ranging data, including weather, soil, historical yield, and satellite imagery.Guaranteeing data quality through efficient collection, preprocessing, and feature selection is critical in model development.However, agricultural big data introduces several challenges, which will be examined in the following section.

Crop Analysis and Prediction Benefits and Challenges
As stated earlier, while machine learning is being exploited in multiple fields, it remains an active area of research and a challenging one in the agricultural domain.This section summarizes the main benefits and challenges ML faces when used in crop analysis and predictions based on recent research [46][47][48][49][50]. Figure 2 shows AI-based crop analysis and prediction phases.

Benefits
The following are the key advantages farmers can receive from utilizing machine learning on their farms:

•
More effectiveness: This approach is more effective and accurate in identifying patterns and saving farmers time and resources because a larger volume of data can be evaluated by machine learning in a shorter amount of time than with previous methods.

•
Increased crop yield: Using many data sources for analysis, including weather patterns, soil quality, and historical machine learning algorithms, can help farmers make more informed decisions that increase crop yields.

•
Lower costs: Machine learning may assist farmers in maximizing the use of resources, such as water, fertilizer, and pesticides, by offering insights into crop development and health.This can save expenses while lowering how much of an impact agriculture has on the environment.

•
Early disease detection: Farmers can take preventative measures to stop the spread of illness and reduce crop loss by identifying early indicators of crop diseases with machine learning.Once the model is sufficiently trained, it can detect anomalies such as discoloration on growth size in the early stages of disease much faster than humans would notice.

•
Improved crop management: By offering insights into variables such as soil moisture, temperature, and nutrient levels, ML algorithms can assist farmers in improving their crop management tactics.This can assist farmers in making data-driven decisions regarding the best time to water, fertilize, and sow their crops.
Overall, using ML in crop analysis and prediction can help farmers optimize their crop yields, reduce waste, and increase profitability while promoting sustainable farming practices.

Challenges
Although crop analysis and prediction can significantly benefit from machine learning, there are also various challenges we need to consider.The main difficulties consist of the following:

•
Data quality: The accuracy and dependability of machine learning models depend on the caliber of the training data.Obtaining high-quality data in agriculture can be challenging because of changes in the soil, climate, geography, and other environmental factors.As a result, gathering and cleansing data might be difficult.Ref. [51] discusses the main challenges related to fruit detection and recognition based on deep learning.They have concluded that most of the factors leading to low accuracy, slow speed, and poor robustness of fruit detection and recognition are related to the scarcity of high-quality fruit datasets, detection of small target fruits, fruit detection in occluded and dense scenarios, detection of multi-scale and multi-species fruits, and lightweight fruit detection models.

•
Data volume: ML models frequently need a large amount of data for efficient training.Large data management and collection in agriculture can be complex, especially for small farms.Ref. [52] considers volume, velocity, variety, and veracity as the main challenges of big data.

•
Model complexity: Because agricultural systems are intricate, it can be challenging to develop machine learning models that account entirely for all the important variables affecting crop development and output.Selecting the best model architecture for a specific crop analysis or forecast activity can be difficult and requires extensive knowledge [53].Additionally, the most common use of ML techniques provides analysis for prediction, recommendations, situation determination, and automation.NN, RF, SVM, DT, and Naïve Bayes algorithms are the most popular techniques used in agronomy.The main challenges for these algorithms are the large volume of data, which increases the complexity of the training time and computation for SVM [53], and the need to tailor the algorithm for each specific problem in the case of RF [54].
The design of big data architecture is one of the most complex challenges, considering that it must be flexible and highly scalable [55].Ref. [56] analyzed the factors affecting soil temperature and concluded that the relationship between variables affecting the soil temperature is quite complex and challenging, leading to the estimation of it using physically and statistically based models with a tradeoff between resolution, accuracy, and computational efficiency.According to them, the best ML technique for soil temperature retrieval generally depends on training datasets, model structure, and target level of accuracy.
Other challenges related to the usage of ML in agriculture are: • Interpretability: Analyzing the outcomes of ML models, particularly those that use deep learning techniques, which are quite complex, can be challenging.Because of this, it may be difficult for farmers to comprehend the elements that go into making a particular crop prediction or suggestion.

•
Accessibility: In situations with limited resources, obtaining access to the hardware and software infrastructure required for developing and deploying ML models may be challenging.

•
Privacy and security: These concerns exist around collecting, storing, and using sensitive agricultural data.It can be challenging to ensure privacy and security while still allowing access to the data for ML research.

•
Human factors: It is possible that farmers and other interested parties need more time to be ready to adopt new methods and technology, such as ML-based systems.For technology to be used more widely, it must be made accessible, user-friendly, and capable of providing real benefits.
Addressing these challenges requires collaboration between data scientists, farmers, and other stakeholders to ensure that ML algorithms are effective, usable, and ethical.

Methodology
In our research endeavor, we deployed a comprehensive array of 15 diverse machine learning algorithms to construct models based on agricultural data, including 2200 records encompassing 22 distinct crop labels.These models provide farmers with recommendations on the most suitable crops to cultivate.Our methodology for crop analysis in Figure 3 adheres to the standard stages of data analysis [53][54][55][56].A significant improvement is the inclusion of multiple classifiers, which are fine-tuned and evaluated to identify the most suitable ones for the input data.Moreover, our methodology incorporates feature reduction and augmentation techniques [57], essential for highlighting pertinent features that enhance crop detection and assist farmers in selecting the most appropriate features for accurate predictions.We have the following steps in our models for crop prediction.
− Data Collection: The collection of data from IoT devices on farms is vital for conducting machine learning analysis.By gathering crucial information on crop usage, crop type, water requirements, and harvest methods for agriculture, we can significantly increase productivity on smart farms.− Data Modeling: The accuracy of data analysis was tested through experiments that involved altering labels.To group crops, we categorized them into four broad groups based on various factors, rather than predicting individual crop types.We analyzed a dataset of crop types using machine learning, utilizing seven different features to classify them.Additionally, we determined the minimum number of features necessary for precise learning and prediction.In our study, we proposed applying various machine learning algorithms with different features for crop analysis.These algorithms were carefully chosen based on their unique capabilities and characteristics and included the Naïve Bayes Classifier, Random Forest, and Multilayer Neural Network.We thoroughly analyzed the results, emphasizing the essential features contributing to high accuracy.To ensure high-quality data, we emphasize the importance of data collection and preprocessing, including tasks such as cleaning and transformation.Figure 3 provides an overview of our crop analysis and prediction of our methodology, incorporating IoT and machine learning algorithms.
We have the following steps in our models for crop prediction.
-Data Collection: The collection of data from IoT devices on farms is vital for conducting machine learning analysis.By gathering crucial information on crop usage, crop type, water requirements, and harvest methods for agriculture, we can significantly increase productivity on smart farms.-Data Modeling: The accuracy of data analysis was tested through experiments that involved altering labels.To group crops, we categorized them into four broad groups based on various factors, rather than predicting individual crop types.We analyzed a dataset of crop types using machine learning, utilizing seven different features to classify them.Additionally, we determined the minimum number of features necessary for precise learning and prediction.-Model Evaluation and Interpretation: We want to achieve precise crop detection by selecting appropriate features for our machine learning algorithms.To ensure optimal results, we considered parameter properties on the relevant properties.This allowed us to obtain accurate and reliable data for our agricultural operations.During our experiments, we analyzed the effects of modifying the labels on the accuracy of our data analysis algorithm.This enabled us to understand the impact of minor label changes better and helped us optimize our approach toward achieving greater accuracy in our results.To achieve success in crop classification, it is vital to utilize broader labels.It is crucial to thoroughly investigate and ascertain the most efficient classification techniques within this domain.
Several classification algorithms, such as Naïve Bayes Classifiers, Random Forest, and Multilayer Neural Network, are used to build a model to predict the correct labels based on provided data.The constructed model was initially achieved by training using training data; then, the results were evaluated using test data to ensure that predictions were accurate and desired values.
The following algorithms were used in our experiment: -Naïve Bayes Classifier is a supervised learning algorithm that uses Bayes' theorem to classify objects.It is used in machine learning and data mining applications for text analysis, medical diagnosis, spam filtering, and other similar tasks.Naïve Bayes assumes that features in a class are considered independent of each other.In practice, the Naïve Bayes algorithm performs well, especially when the data are sparse, and the number of features is extensive.Below is the pseudocode for Naïve Bayes Classifier: Output: {New data point x to be classified; predicted class for x}.

•
For each unique class value c in y, calculate the prior probability for class c where count (c) is the count of observations with class c.

•
For each feature i in X and each unique class value c in y, calculate the conditional probability of feature i given class c as follows: where count (i, c) is the count observations with the feature i and class c.

•
Calculate the posterior probability for each class given the new data point x: • Initialize the posterior probability P(c|x) to P(c)

•
For each feature i in x: =, multiply P(c|x) by P(i|c) if x[i] is observed in the training data, otherwise ignore the term.

•
Choose the class with the highest posterior probability as the predicted class for x.
-Random Forest is a type of supervised machine learning algorithm that is used in regression and classification problems.It is an ensemble learning algorithm that uses Decision Trees to make a prediction.Random Forest creates many Decision Trees and combines their predictions to make a final prediction.More trees created yield high accuracy and robust results.Below is the pseudocode for the Random Forest algorithm:

•
For each tree in the Random Forest: • Select a bootstrap sample from the training data set.

•
Create a Decision Tree T_t with a maximum depth of d.

•
Randomly select f features to consider at each split of T_t.

•
Use the selected features to find the best split at each node of T_t.

•
For each input data: • For each decision, find the prediction.

•
Obtain predictions of all the trees.

•
Calculate the final predicted class.
-Multilayer Neural Network is a machine learning algorithm consisting of multiple layers of interconnected nodes between the input and output layers.
To minimize the error between the predicted output and the actual output, the neural network involves adjusting each neuron's weight and biases by using an optimization algorithm such as backpropagation.Below is the pseudocode for the Multilayer Neural Network algorithm:

•
Define the number of layers and the number of neurons per layer.

•
Initialize the weights and biases for each neuron in the network randomly.
For each input data: • Forward propagate the input through the neural network to obtain the predicted output.

•
Calculate the error rate between the predicted output and the actual output.

•
Backward propagate the error through the neural network to adjust the weights and biases using the optimization algorithm.

•
Repeat until the error converges to a satisfactory level.
By integrating these methodologies, we aimed to provide farmers with efficient and effective crop recommendations, ensuring they receive tailored advice based on the most pertinent features while minimizing the required effort and time investment.

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, Naïve 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: K (Kappa) = (P o − P e )/(1 − P e ) (1) where P o is relative observed agreement and P e is hypothetical probability of chance agreement.

MAE (Mean
where n is the total number of data, x i is the true value, and y i is the prediction.
where x i is observed and x i is the predictive value.

RAE (Relative
where y is the average value of the data.

Root Relative Squared Error (RRSE) =
where P is the predicted value and T is the target value.Table 2 shows each algorithm's build and test time.It can be noticed that the Multilayer Perception algorithm build time is greater than other algorithms because this algorithm is an Artificial Neural Network algorithm, including several hidden layers in addition to the input and output layer.The MLP algorithm runs with several iterations to find the best model for the given input and output set, which increases the build time.KSTAR and LWL algorithms have higher testing times than others.The NBC algorithm is the most efficient algorithm in classifying crop data based on accuracy and process time.[59,60].The results indicate that the lowest build time is observed when the training set is at 40%, while the highest build time occurs when the training set is at 10%.On the other hand, test times are consistently low across all scenarios, with the highest being at 0.05 when the training set is at 10%.Experiments show that the MLP algorithm has higher build times than the other ML algorithms, but testing time is very efficient.After performing machine learning classification on a dataset with seven features and one label representing the crop type and recording the accuracies of different algorithms in Table 1, further simulations were conducted to determine the minimum number of features required to achieve high accuracy in algorithm learning and prediction.In this work, our primary focus is to determine the meaningfulness and correlation of the numerous features used for predicting crop outcomes.To achieve this, we utilized the Variance Inflation Factor (VIF), a statistical measure in machine learning, to assess multicollinearity [61].By calculating the VIF for each variable, we gained valuable insights into potential correlations among predictor variables in the model.This crucial step allowed us to identify the best VIF values, indicating collinearity, and values below 10, signifying non-collinearity.As a result of this preparation, we were able to select the most suitable combination of features for our dataset.Table 5 shows the results of four scenarios where we selected three to four features and evaluated the accuracy of crop detection for each set.The second set of features (Temperature, Humidity, pH, Rainfall) achieved the highest accuracy, reaching 97.05% with Bayes Net and 97.32% with Random Forest.In contrast, the worst prediction outcome occurred when using the features N, P, and K, where the best accuracy obtained was 68.04% with Random Forest.The results in Table 5 highlight the importance of selecting the appropriate features for achieving high accuracy in crop detection using machine learning algorithms.The set of features (composed of Temperature, Humidity, pH, and Rainfall) we identified can be used as a guide for selecting relevant features for crop determination in future agricultural data analysis.
More experiments were conducted to investigate the impact of changing the label on the accuracy of the data analysis algorithm.The results are displayed in Table 5 Instead of predicting the specific crop type, we manually grouped the crops into four more general categories based on their growth characteristics, usage, type, water requirements, and harvest method, as described in Table 6.Then, we tested the accuracy of the algorithm to predict these new general labels one at a time.Table 6 presents a classification of crops based on several class labels.The table includes information on the growth characteristics, usage (food, feed, fiber), type, water requirements, and harvest method for various crops.The crops are classified based on their growth characteristics, such as grass, bush, and tree; their water requirements, such as drought tolerance, drought, and water loving; as well as their harvest method, which can be performed by hand or machine.For example, rice and maize are classified as grasses, with the type being cereal, whereas chickpeas and pigeon peas are classified as bushes, with the type being legumes.
This experiment aims to explore whether the algorithm could accurately predict more general categories of crops, which could be helpful in situations where general characteristics of crops are investigated, and specific crop types are not known or easily identifiable.The experiment results are summarized in Table 7, where we compared the accuracies of various classification methods for each general category.Table 7 shows that some classification methods perform better in predicting general categories.For example, the IBK, KSTAR, and KSTAR methods achieved high accuracies for predicting all general categories compared to the type of the crop (first column in the table), while Bayes Net, Naïve Bayes Classifier, Logistic, and Multilayer Perception had low accuracies for all categories.The experiment demonstrates the potential usefulness of using more general

Conclusions
Our research highlighted the significance of incorporating machine learning algorithms and IoT sensors in modern agriculture to optimize reap production and reduce waste through informed decision-making.This study identifies the challenges and opportunities associated with integrating these technologies in agriculture.It presents experimental results that demonstrate the impact of changing labels on the accuracy of data analysis algorithms along with accuracy, error values, build, and test time for each classification algorithm.The findings suggest that analyzing wide-ranging data collected from farms, including real-time data from IoT sensors, can enable farmers to make more informed decisions about factors that affect harvest growth.Despite the challenges associated with deploying machine learning in agriculture, our results achieved so far are very promising in that machine learning approaches will become increasingly crucial for production predictions in agriculture in the future.In this experiment, crops were investigated according to general characteristics using different machine learning algorithms, and valuable results were obtained by making predictions in cases where certain crop types are unknown or cannot be easily identified.Our work indicated that appropriate feature selection is critical to achieve better accuracy in machine learning algorithms while analyzing agricultural data.Using the Temperature, Humidity, pH, and Precipitation features in the dataset, it achieved the highest accuracy, reaching 97.05% with Bayes Net and 97.32% with Random Forest.This research provided valuable insights into the potential benefits of these technologies in modern agriculture, and further research and development in this field could help optimize crop production, reduce waste, and improve food security globally.
In future work, more crop data will be evaluated using GPS-based IoT and sensor data from different geographic regions.All these results will be analyzed using a machine learning algorithm.Thus, our data evaluation pool will be established.In addition, different species of the same plant variety will be analyzed separately, and it will be possible to reveal which product is the best type of product among the same species using different machine learning algorithms.

Figure 1 .
Figure 1.IoT and machine learning-based crop analysis and prediction process.Figure 1. IoT and machine learning-based crop analysis and prediction process.

Figure 1 .
Figure 1.IoT and machine learning-based crop analysis and prediction process.Figure 1. IoT and machine learning-based crop analysis and prediction process.

Figure 2 .
Figure 2. AI-based crop analysis and prediction.Figure 2. AI-based crop analysis and prediction.

Figure 2 .
Figure 2. AI-based crop analysis and prediction.Figure 2. AI-based crop analysis and prediction.

Figure 3 .
Figure 3. Methodology for crop prediction using IoT and ML.

Figure 3 .
Figure 3. Methodology for crop prediction using IoT and ML.
: {X: Training set; m: Number of observations; n: Number of features; Labels y for the training set}.
y): Training data set; T: Number of trees; d: Maximum depth of each tree; f: Number of features to consider at each split} Outputs: {Learned trees for classification}

Table 1 .
Accuracy and error values for each classification algorithm.

Table 2 .
Build and test times for classification algorithms.

Table 3
demonstrates accuracy and error measurement in the Multilayer Perception algorithm with different sample sizes of training data.When 10% of the data is used in training, accuracy with MLP is 93.53%; however, when 90% of data is used, accuracy is 97.72%.In the MLP algorithm, reaching high accuracy and efficient time complexity is important.The MLP algorithm can be very efficient in numeric-based data; however, it will be slow if collected data are images or videos.Table4presents the build and test times for the Multilayer Perception (MLP) algorithm under different scenarios involving modifications to the training and testing data percentage.It is worth noting that the MLP algorithm has longer build times than other algorithms

Table 3 .
Accuracy and error values for Multilayer Perception algorithm (training set from 10% to 90%).

Table 4 .
Build and test times for Multilayer Perception algorithm (training set from 10% to 90%).

Table 7 .
Comparison of the accuracies (%) of various classification methods.