# Data-Driven and Machine-Learning-Based Real-Time Viscosity Measurement Using a Compliant Mechanism
## 1 Introduction
The resonant frequency of the diaphragm structure changes with variations in the fluid's viscosity, and the resonant frequency value is also measured to estimate the fluid's viscosity. Another approach uses tracking of the electromechanical impedance (EMI) of the sensors to measure viscosity [11]. [PERSON] and [PERSON] (2018) [6] introduced an online viscosity measurement system that determines the EMI of a piezoelectric torsional transducer to measure viscosity within the range of 20 cP to 700 cP. The system includes a stainless steel substrate with a specially designed configuration that creates shear mode vibrations, with piezoelectric ceramic material used as the actuator. [PERSON] and [PERSON] (2024) [12] demonstratedthe application of a viscosity measurement system using an EMI spectroscopy approach to investigate the interactions between the piezoelectric element and industrial fluid. In another study, [PERSON] and [PERSON] (2021) [13] investigated the EMI responses of a mechanical structure excited by piezoelectric material at 90 kHz, 200 kHz, 260 kHz, and 280 kHz frequencies, respectively. These authors demonstrated that variations in viscosity result in a change in the impedance amplitude, which can be correlated with the viscoelastic behavior of the material. Machine learning (ML) algorithms are widely applied to real-time estimation of fluid properties, achieving efficient and accurate results without involving complex models or costly equipment [14]. [PERSON] et al. (2020) [15] developed a methodology using a graph machine and a COSMO-RS \(\sigma\) neural network, achieving a 0.001 Pa-s accuracy in viscosity estimation. ML approaches have been used to monitor blood coagulation and have enabled SVMs and k-NN classifiers to achieve accuracy rates of 89.7% and 98.7%, respectively [16]. [PERSON] et al. (2022) [17] applied ML techniques, including a BRT, an SVM, and an ANN, to predict the density and viscosity of hybrid nanofluids, while [PERSON] (2023) [18] found that a Multi-Fidelity Neural Network (MFNN) outperformed an SVM and k-NN in viscosity prediction. A virtual sensor using an ANN model predicted coolant fluid viscosity with an error of 7.73 cP [19]. In drilling applications, [PERSON] (2019) [20] developed an ANN-based method for viscosity estimation with 98.8% accuracy. Similarly, [PERSON] et al. (2019) [21] achieved high accuracy in thermal conductivity and viscosity measurements for nanofluids using an ANN. Other studies have highlighted ANNs' efficiency: [PERSON] et al. (2021) [22] used an ANN and ATR-FTIR to predict nanofluid viscosity with an RMSE of 0.051, and [PERSON] et al. (2013) [23] demonstrated the accuracy of an ANN in measuring refrigerant viscosity at high densities. [PERSON] et al. (2018) [24] employed a genetic-algorithm-based ANN model and achieved an \(R^{2}\) value of 0.999. [PERSON] et al. (2021) [25] showed that an ELM outperformed ANFIS-PSO in predicting the viscosity of gas condensate with \(R^{2}\) of 0.941. Lastly, a piezoelectric-sensor-based ANN model made it possible to estimate the density and viscosity of liquid in real time, covering a broad density and viscosity range [26; 27]. Metaheuristic algorithms, such as genetic algorithms, Particle Swarm Optimization (PSO), and Simulated Annealing, have proven effective for enhancing machine learning models in complex prediction tasks. For example, Gaussian Process Regression (GPR), finetuned with metaheuristics, achieved high accuracy in viscosity prediction for suspensions containing microencapsulated phase change materials (PCMs) [28]. Similarly, Long Short-Term Memory (LSTM) models, optimized with the application of decomposition techniques and Shapley values, successfully forecasted Bitcoin prices [29]. Metaheuristics have also been applied to Artificial Neural Networks (ANNs) [30] and Multi-Fidelity Neural Networks (MFNNs) [31], resulting in notable improvements in their robustness and accuracy across diverse applications.