## 2 Materials and Methods
### Machine Learning Methods  
Studied samples were split into two classes: tumor and control. To verify separability of the classes at each time point, we used the ML pipeline (MLP) presented in Figure 4.  
In the first stage, THz spectra were smoothed by the Savitsky-Golay filter to remove sharp spikes, using the following parameters: filtering window width (windows_size) 15, degree of smoothing polynomial (polyorder) 2, and smoothing of the spectrum derivative (deriv) was not used. The parameter names were given according to the scipy.signal.savgol_filter library in the Python language. At the second stage, we implemented outlier removal by the isolation forest (IF) method [37]. IF is a machine learning technique, which uses an ensemble of binary decision trees called isolation trees (see Figure 5) to discover anomalies in data based on the distance of the current point in feature space from the others. Unlike other outlier removal methods, IF does not model normal points distribution to find deviations. A set of THz spectra belonging to the same class were used in the IF input. In the upper node of the isolation tree, a single component of the spectrum was analyzed to find the outlier. If it was not found, the process continued on the lower nodes. The decision to considered a feature vector as anomalous depended on the number of randomly chosen vector components required to isolate it from the other data. This algorithm was implemented in the Python language with the sklearn.ensemble.IsolationForest library. The isolation number parameter was chosen automatically [38]. In the third stage, the data were standardized by subtracting the mean and normalizing to the standard deviation (Z-score normalization). PCA was chosen to construct a sequential algorithm for the informative feature selection. The number of principal components remaining were 10, to cover more than 95% of variance in data. The informative features were selected from the rows of the loadings matrix with the highest absolute values. PCA and Z-score were implemented using sklearn.decomposition.PCA and sklearn.preprocessing.StandardScaler Python modules. The separability of data was analyzed by the predictive model, based on SVM with linear kernel at the fourth stage. Figure 4: Proposed MLP for THz spectral data analysis. Figure 5: The concept of the isolation forest algorithm. Green dots are a common data; blue dots are rare data, but not an anomalous; the red dot is an anomaly. The closer an endpoint dot is to a tree root, the higher the anomality score. Each node is a randomly chosen component of the studied spectrum. The sklearn.svm.SVC Python module with default parameters was applied to construct the classifier. The k-fold CV was used. The algorithm was implemented in Python using the model_selection.StratifiedShuffleSplit module of the sklearn library. The quality of classifiers was estimated using the receiver operation curve (ROC) and area under curve (AUC) analysis. ROC plots a graph of sensitivity versus 1-specificity, and AUC displays the area under the ROC. For the final stage, we developed a sequential feature selection algorithm by combining PCA and SVM (see Figure 6). Note that PCA and SVM are deterministic methods, so the difference in results can only be obtained by randomly splitting the initial dataset for the training and testing samples. The LASSO (least absolute shrinkage and selection operator) method of multivariate regression with L\({}_{1}\) regularization was chosen to investigate the relation between the THz spectra and the tumor size [39]. The linear LASSO model is described by the formula:  
\[\min_{w}\frac{1}{2N}\|Xw-y\|_{2}^{2}+\alpha\|w\|_{1},\]  
where \(N\) is the number of samples, \(X\) is the initial spectra, \(y\) is tumor size, \(w\) is regression coefficient, \(\alpha\) is the regularization parameter, \(\|w\|\) denotes vector norm, lower index 1 and 2 are the L\({}_{1}\) and L\({}_{2}\) norm, respectively.