## 3 Materials and Methods
### Data Preprocessing
#### 3.2.2 Handling Outliers  
The purpose of outlier detection (OD) is to identify and separate outliers in a sample (anomalies from usual data) from normal data (also called inliers). This is usually an unsupervised problem, as there is not enough knowledge about the data patterns. The general scope of OD algorithms is to allow for the identification of outliers, as their removal from the dataset can be crucial to improving model performance [26]. The crop data involved in the study contained self-reported information filled in by the farmers in a national statistics information platform. A first analysis of the data showed a small percentage (5-10%) of inconsistent or incomplete data (for example, the percentage of planting per week was not filled in for all weeks). This is normal for data collected in an uncontrolled manner. Furthermore, the missing data on planting day were completed using various methods, generating values for 80% of the instances. This is likely to have either introduced or exacerbated anomalies in the dataset. Given these reasons, we analysed the impact of removing outliers from our data to create the prediction models. In this sense, we applied and compared the unsupervised algorithms for anomaly detection described below, chosen based on the robustness and computation requirements for the regression tasks, as found in the literature. Isolation forest (IF) uses isolation trees to separate each instance from the rest, and compute the anomaly score from the expected path length \(E(h(x))\) of each instance, with \(h(x)\) as the average estimation path length and \(c(n)\) defined based on \(H(i)\), the harmonic number. \[c(n)=2H(n-1)-2(n-1)/n \tag{2}\]  
\[s(x,n)=2^{-E(h(x))/c(n)} \tag{3}\]  
This method is very flexible, as it has been proven to work well even in high-dimensional problems (even for a large number of irrelevant attributes), or in the case where the training set does not contain anomalies [29]. It can be configured by the number of trees and contamination rate (expected rate of outliers in the dataset). Minimum covariance determinant (MCD) uses a statistical covariance distance to compute a tolerance ellipse, defined as the set of \(p\)-dimensional points \(x\) whose Mahalanobis distance  
\[MD(x)=d(x,\bar{x},Cov(X))=\sqrt{(x-\bar{x})^{\prime}Cov(X)^{-1}(x-\bar{x})} \tag{4}\]  
describes the distance from the centre of the data cloud to \(x\)[30]. The elliptic envelope (EE) implementation in Sklearn was used in our case, as described by [31], and requires setting the contamination rate parameter. The Local outlier factor (LOF) approach defines LOF of an instance \(p\) as  
\[LOF_{MinPts}(p)=\frac{\sum_{o\in N_{MinPts}(p)}\frac{Ind_{MinPts}(o)}{Ind_{MinPts }(p)}}{N_{MinPts}(p)} \tag{5}\]  
the degree to which we call \(p\) an outlier, calculated as the average of the ratio of the local reachability density of \(p\) (that is, the average reachability distance based on the MinPts-nearest neighbours of \(p\)) and those of \(p\)'s MinPts-nearest neighbours. The reachability distance of object \(p\) with respect to object \(o\) is calculated as the distance between an object and the k-neighbourhood of \(p\):  
\[reachdist_{k}(p,o)=max\{kdistance(o),d(p,o)\} \tag{6}\]  
OneClass-SVM (OC-SVM) is a kernel-based algorithm focused on estimating the density function of the input data (K) in order to define a binary function that decides if a point is an outlier or inlier based on an anomaly detection sensitivity [32]. In short, this involves solving a dual optimisation problem, defined formally as:  
\[\min_{\alpha\in R^{n}}\{\frac{1}{2}\alpha^{\gamma}K\alpha\}s.t.\{\alpha^{ \gamma}1=1,0\leq\alpha\leq\frac{1}{\
u N}\} \tag{7}\]  
where \(K\) is a Gaussian kernel function, \(\gamma\) is the kernel scale, and \(\
u\in(0,1]\) measures the anomaly detection sensitivity [26]. The \(\
u\) hyperparameter needs to be optimised, considering a low value involves a small chance for a point to be an anomaly.