# Data-Driven and Machine-Learning-Based Real-Time Viscosity Measurement Using a Compliant Mechanism
## 3 Numerical Simulations and ML Models
### Machine Learning Models
This focus on support vectors enhances SVR's robustness and efficiency in handling large datasets by emphasizing the most informative points. 4. Random Forest Regression is an ensemble method that constructs multiple decision trees during training and gives the mean prediction of the individual trees as the outputs. It reduces overfitting and improves the prediction accuracy. The final prediction \(\hat{Y}\) is given as follows: \[\hat{Y}=\frac{1}{N}\sum_{i=1}^{N}{g_{i}(x)}\] (4) where \(N\) is the number of trees, and \(g_{i}(x)\) is the prediction of the \(i\)-th tree for input \(x\). Each tree's prediction \(g_{i}(x)\) is obtained by recursively splitting the training data at various nodes, ultimately leading \(x\) to a leaf node containing a value. This value represents the predicted outcome for \(x\) by the \(i\)-th tree. The ensemble method in Random Forest effectively averages these individual predictions \(g_{i}(x)\) to yield a robust and accurate final prediction \(\hat{Y}\). By combining multiple uncorrelated trees, Random Forest reduces the variance and enhances the generalization, making it highly effective for regression tasks. MLR was selected for its efficiency in modeling linear relationships, which is expected in this viscosity prediction task. Random Forest and decision tree models were included to assess any underlying non-linear dependencies, as they are adept at capturing complex patterns through ensemble methods and hierarchical splits. Support Vector Regression was chosen for its robustness and ability to handle outliers, providing a reliable benchmark for comparison across different data distributions. Each model was trained on the collected dataset using a train-test split approach, ensuring the models learned the relationship between the voltage data and viscosity. The performance of these models was evaluated using the following metrics: Mean Squared Error (_MSE_), Root Mean Squared Error (_RMSE_), and R-squared (\(R^{2}\)) values. Additionally, scatter plots and Regression Error Characteristic (_REC_) curves were used to visually assess the accuracy and reliability of the predictions. The performance of the proposed viscosity measurement method was evaluated using several key metrics, including Mean Square Error (_MSE_), Root Mean Square Error (_RMSE_), and the coefficient of determination (\(R^{2}\)). _MSE_ and _RMSE_ measured the average magnitude of the prediction errors. _R-squared_ was used to assess how well each model explained the variance in the data, with a value close to 1 indicating high explanatory power. When considered together, these metrics provided a comprehensive assessment, capturing both the prediction accuracy (_MSE_ and _RMSE_) and the quality of the model fit (_R-squared_), allowing us to confidently select the most suitable model for viscosity prediction. * Mean Square Error (_MSE_) is a measure of the average squared difference between the predicted viscosity values and the actual viscosity values in the dataset. It is calculated as follows: \[MSE=\frac{1}{n}\sum_{i=1}^{n}(y_{i}-\hat{y_{i}})^{2}\] (5) where \(n\) is the number of samples in the dataset, \(y_{i}\) is the actual viscosity value for sample \(i\), and \(\hat{y_{i}}\) is the predicted viscosity value for sample \(i\). * Root Mean Square Error (_RMSE_) is calculated as the square root of the _MSE_ and provides a measure of the average magnitude of the errors. It is calculated as follows: \[RMSE=\sqrt{MSE}\] (6)
* R-squared (\(R^{2}\)): The coefficient of determination (_R-squared_) indicates the proportion of the variance in the viscosity values that is predictable from the independent variables (voltage data). It is calculated as follows: \[R^{2}=1-\frac{\sum_{i=1}^{n}(y_{i}-\hat{y_{i}})^{2}}{\sum_{i=1}^{n}(y_{i}-\overline {y_{i}})^{2}}\] (7) where \(\overline{y}\) denotes the mean value for viscosity in the dataset. These evaluation metrics provide insights into the accuracy and performance of the ML model in predicting viscosity based on the voltage data collected from the experimental arrangement.