Decoding Common Machine Learning Methods Agricultural Application Case Studies Using Open Source Software

Srinivasagan N. Subhashree, S. Sunoj,

Oveis Hassanijalilian, and C. Igathinathane

Introduction

Machine learning (ML) applications are ubiquitous in the present digital age. The ML methods are gaining attention due to their ability to solve complex problems and provide a decision support system from large volumes of data. Software packages are available for different ML methods in the form of modules in various programming languages (e.g.. Python, R, MATLAB). Sufficient online resources and publications are available discussing the theoretical framework of ML methods and practical usage of the software modules in various platforms. However, to our knowledge, resources dealing with the concepts and mechanisms of the ML methods and the sequence of intermediate operations performed inside the ML algorithms with a working code are not available. The ML methods are usually presented as “blackbox” products providing no insight into the mechanism or allowing for modification to suit user needs. It will always be desirable to develop ML algorithms from fundamental principles, especially using open source free software, to fit the processing and analyzing requirements of the user. Therefore, it is proposed to focus on decoding the two common ML methods and develop working codes using open source R software and demonstrate the applications.

Among the various fields that successfully employ ML methods, modern agriculture is one of the sectors that produces an enormous amount of data from different equipment components, such as yield monitors, seed and fertilizer equipment, soil moisture sensors, cameras, and global positioning systems (GPS). Another data domain is a variety of images from satellites, unmanned aerial vehicles, spectral camera (e.g., hyper, IR, NIR, NDVI) imagery, LiDAR point clouds, field mounted PhenoCams, as well as simple handheld color digital cameras. However, as the source of these data varies greatly, their type and quality will also vary accordingly. Furthermore, since agriculture deals with biological systems, there exists considerable variability, which presents a challenging scenario to be tackled through common/simple data analysis procedures. The ML methods are generally applied in analyzing such diverse data to make informed decisions in agriculture. Therefore, in this chapter we used two agricultural field application datasets, such as soybean aphid identification and weed species classification, for the demonstration of decoded ML methods.

Of several agricultural applications, the motivation for choosing these two datasets is due to the complexity of the problems. In the soybean aphid dataset, the other objects (exoskeletons and leafspots) exhibit features similar to aphids; hence classifying aphids is complicated and requires the selection of suitable features (individual or a combination). In the weed dataset, the classification of weeds into grassy and clover-shaped species at the “just emerged” stage is a difficult and tedious task, as both species display almost similar shape (two to four emerged leaves). The two datasets used in this chapter were primarily in the form of images, which were processed using ImageJ (Rasband, 2019; Schindelin et al., 2012), an open source and free image processing software, to extract features suitable for ML application.

Even though employing ML classification using available packages is a simple and plug-and-play methodology, it is vital to realize that it is a blindfold approach. The user supplies the input data to the model and receives output while being oblivious of the process behind the packaged ML methods. The methods in such packages, commonly referred to as "black-boxes,” are built with the highest efficiency specific to their ecosystem, and when required it is not always possible to customize them to a different ecosystem. It is always desirable to decode and reconstruct the ML methods to overcome these limitations.

The primary advantage of such user-coded models is that the user is fully aware of the mechanism, the mathematical principles behind the algorithm, and the models’ limitations. The models when reconstructed in open source software will be cost- effective and have less constraint and complexity. Furthermore, user-coded models can be customized based on the data, could potentially improve the model performance more than the black-box approaches, and provide knowledge and training to the users (e.g., students and researchers) as it is developed from scratch.

Given this background and requirement to develop decoded ML algorithms, the objectives of this chapter were to: (i) decode two of the common ML classification methods using open source software ImageJ (image processing and data extraction) and R (data handling and model development); (ii) employ the decoded algorithm for demonstrating classification using field data of agricultural applications, such as soybean aphids identification and weed species classification; and (iii) compare the performances of the decoded algorithm with the existing black-box approaches.

Literature Review

The superior power of ML algorithms is the ability to solve problems that were not possible to address by simpler mathematical approaches with explicit programming. The overall process of ML has the following three steps: (i) finding patterns from input data, (ii) building an ML model, and (iii) predicting the response using the ML model (Das et al., 2020). Recent applications of ML algorithms can be found in cutting-edge technologies from Netflix and Amazon recommendations (Gomez- Uribe and Hunt, 2016), fraud detection for financial institutions (Kiiltiir and C^aglayan, 2017), driverless cars, and autonomous vehicles (Choi and Cha, 2019; Ali Alheeti and McDonald-Maier, 2018) to biomedical and healthcare fields (Das et al., 2020b;

Dey et al., 2019), including agriculture (Liakos et al., 2018; Zhou et al., 2019). The common theme among these examples is the availability of rich datasets.

Some of the successful agricultural applications of ML include crop yield prediction (Low et al., 2018), inputs quantification (Tantalaki et ah, 2019), phenology and crop health monitoring (Behmann et ah, 2015), weeds classification and geo-location (dos Santos Ferreira et ah, 2017), animal behavior and health monitoring (Borchers et ah, 2017), and plant disease detection and classification (Ferentinos, 2018).

Most of these applications used software packages that are available for different ML methods in the form of black-box modules in various programming languages, such as Scikit-learn and TensorFlow in Python (Pedregosa et ah, 2011; Abadi et ah, 2015; Sarkar et ah, 2018); nnet, and caret in R (Ramasubramanian and Singh, 2017; Kuhn. 2019); and Statistic and ML toolbox in MATLAB (Martinez and Martinez, 2015). All of these packages are great for training, developing, and testing ML models, but they come with their pros and cons. Python and R (R Core Team, 2019) are preferred among industry, since they are free, open source, and work cross-platform; while MATLAB, a commercial software that, as well as requiring an annual subscription, is commonly used in academia.

Among the agricultural applications of ML, pest identification and weed species classification are a few common issues being addressed. For these agricultural applications, the available ML packages developed for addressing generic applications are being adapted and tested, but a reliable solution is still lacking. This is possibly due to the lack of resources that facilitate agricultural researchers in understanding the mechanism of ML methods. Better clarity on this aspect will help in customizing the methods to suit a specific agricultural application. Therefore, this chapter focuses on handling agricultural field data examples and provides an overview of the application of user-developed, decoded, commonly used ML methods. Particularly in the agricultural domain, this chapter could possibly change the perception of the straightforward “application” mindset among several researchers to a “development” mindset. Such an impact will help in developing solutions for other specific agricultural problems, not limited to the aforementioned common applications.

Materials and Methods

Overall ML Model Development Process

The overall processing stages for the decoded ML model development in this chapter are outlined (Figure 2.1) and subsequently described. The data required for this process were generated from the digital images acquired from the two different agricultural applications of identification and classification (soybean aphids and weed species). The actual input data for the ML models need to be in a structured format (with the same data type across features). We used ImageJ (Version 1.52r) for processing and extracting data (Rasband, 2019; Schindelin et al., 2012). ImageJ is an open source, java-based, and free image processing software that allows for the development of task-specific and user-coded applications in the form of plugins (Igathinathane et al., 2009). ImageJ also supports plugin development in several other languages (e.g., JavaScript. Python. Ruby, Clojure, Scala). The raw color images were preprocessed using ImageJ’s thresholding methods to obtain binary

Overall process flow diagram of decoding common linear discriminant analysis (LDA) and к-nearest neighbor (kNN) machine learning methods

FIGURE 2.1 Overall process flow diagram of decoding common linear discriminant analysis (LDA) and к-nearest neighbor (kNN) machine learning methods.

images (suitable for further processing) for feature extraction. ImageJ offers a several measurements (features) option from the binary image, such as the object area, major and minor axes length, width and height of bounding box, and Feret dimensions, to name a few. These basic measurements can be used to derive additional shape features to address the requirement of different applications (Igathinathane et al„ 2008; Sunoj et al., 2017, 2018; Du and Sun, 2004).

The evaluated shape features were processed using R, an open source and free statistical software (R Core Team, 2019). A user-coded R program was developed to process the data and build the ML models based on linear discriminant analysis (LDA) and к-nearest neighbor (kNN) algorithms (Figure 2.1). The initial data processing included data cleaning, feature selection, and data splitting into training and testing datasets. The ML models were decoded showing various intermediate processes that run inside the ML algorithms. The results of the user-coded models were compared with the black-box models, from readily available R packages, based on the model performance and the time taken for processing.

 
Source