# Data-Driven and Machine-Learning-Based Real-Time Viscosity Measurement Using a Compliant Mechanism
## 3 Numerical Simulations and ML Models
### Machine Learning Models  
The following machine learning (ML) models were used to predict the fluid's viscosity based on the sensor's voltage output:  
1. Multiple Linear Regression (MLR) was employed to model the relationship between the dependent variable (viscosity) and the independent variable (voltage data). The model is represented by the following equation: \[Y=\beta_{0}+\beta_{1}X_{1}+\beta_{2}X_{2}+\dots+\beta_{n}X_{n}+\epsilon\] (1) where \(Y\) is the predicted viscosity; \(\beta_{0}\) is the intercept; and \(\beta_{1}\), \(\beta_{2}\), \(\dots\), \(\beta_{n}\) are the coefficients corresponding to the features of the voltage data \(X_{1}\), \(X_{2}\), \(\dots\), \(X_{n}\). The error term \(\epsilon\) accounts for the deviations of the observed values from the predicted values. The constants \(\beta_{i}\) quantify the relationships between the independent variables \(X_{i}\) and the dependent variable \(Y\). They are calculated using Ordinary Least Squares (OLS) estimation, which minimizes the sum of the squared differences between the observed and the predicted viscosity values, expressed mathematically as follows: \[RSS=\sum_{j=1}^{m}\big{(}y_{i}-\hat{y}_{j}\big{)}^{2}\] (2) where \(y_{i}\) is the actual viscosity value, \(\hat{y}_{j}\) is the predicted value, and \(m\) is the number of observations. In the simulation, the coefficients scale and combine the \(X_{i}\) variables to generate the best estimate of viscosity, indicating how much \(Y\) changes with one-unit change in each \(X_{i}\). The independent variables \(X_{i}\) represent the sensor's voltage outputs, which are the crucial inputs to the model for accurate viscosity predictions. 2. A decision tree (DT) involves splitting the data into subsets based on the specific features that result in the most significant information gain. Subdivisions are performed in a deterministic manner, meaning that the process follows a set of predefined rules rather than being random. Specifically, the algorithm evaluates all possible splits for each feature and selects the one that results in the highest information gain, which quantifies how well a particular feature separates the data into distinct classes or values. Information gain is defined as a reduction in the uncertainty about the target variable (viscosity, in this case), achieved by partitioning the data according to a specific feature. It measures how effectively a feature can split the data into subsets that are more  
Figure 5: Resonant frequency of the mechanical structure. homogeneous with respect to the target variable. The feature that maximizes this reduction in uncertainty is chosen for the split, leading to the creation of sub-blocks that represent more uniform groups of data points. The predicted viscosity for a given subset is calculated as the average value of the target variable in that subset, providing a straightforward and interpretable model output. 3. Support Vector Regression (SVR) attempts to find a function that deviates from the actual observed data points by a value that is no greater than \(\epsilon\) (epsilon, the margin of tolerance) and, at the same time, as flat as possible. The SVR model is formulated as follows: \[f(x)=\sum_{i=0}^{n}{(\alpha_{i}-\alpha_{i}^{*})K(x_{i}-x)+b}\] (3) In this equation, the kernel function \(K(x_{i},x)\) computes the similarity between two data points \(x_{i}\) and \(x\), enabling the model to capture non-linear relationships without explicitly transforming the input features. The bias term \(b\) allows the regression function to be shifted up or down, helping the model fit the data more effectively. The values \(\alpha_{i}\) and \(\alpha_{i}^{*}\) are the Lagrange multipliers associated with the support vectors. These multipliers are calculated during the training process to maximize the margin while minimizing the error, determining the contribution of each support vector to the final regression function. Non-zero multipliers indicate critical support vectors that define the model.