# Data-Driven and Machine-Learning-Based Real-Time Viscosity Measurement Using a Compliant Mechanism
## 5 Results and Discussion
### MSE, RMSE, and R-Squared Metrics  
The results of the different ML models trained and evaluated using the Mean Squared Error (_MSE_), Root Mean Squared Error (_RMSE_), and R-squared (\(R^{2}\)) are summarized in Table 3.  
It is evident from Table 3 that the Multiple Linear Regression model exhibits the best performance with the lowest _MSE_ (0.69) and _RMSE_ (0.83) values and the highest R-squared value (0.99), indicating its superior predictive accuracy. Furthermore, its highest R-squared coefficient signifies a strong correlation between the predicted and actual viscosity values.  
The Random Forest model exhibited a competitive performance, producing a relatively low _MSE_ (3.77) and _RMSE_ (1.94) and a high R-squared coefficient (0.98). Although it was not as accurate as Multiple Linear Regression, it demonstrated robust predictive capabilities, making it a reliable alternative due to its effective ensemble approach.  
The Support Vector Regression model performed reasonably well, with moderate _MSE_ (6.45) and _RMSE_ (2.54) values and a high R-squared coefficient (0.97), indicating a good fit to the data. However, this model could not fully capture all of the data complexities, and it was not as accurate as the other models.  
Conversely, the Decision Tree model yielded the highest _MSE_ (12) and RMSE (3.46) among the evaluated models, indicating less accurate viscosity prediction. Additionally, it showed a lower R-squared coefficient (0.94), suggesting a weaker correlation between the predicted and actual viscosity values as compared to the other models.  
Figure 12: Two sample records for 30 cP liquid viscosity.  
\begin{table}
\begin{tabular}{c c c c} \hline \hline
**ML Model** & _MSE_ & _RMSE_ & _R\({}^{2}\)_ \\ \hline Multiple Linear Regression & 0.69 & 0.83 & 0.99 \\ Random Forest & 3.77 & 1.94 & 0.98 \\ Support Vector & 6.45 & 2.54 & 0.97 \\ Decision Tree & 12.00 & 3.46 & 0.94 \\ \hline \hline \end{tabular}
\end{table}
Table 3: Parameters of the vibration excitor and the piezoelectric sensor.  
Figure 13a shows that Linear Regression had the lowest _MSE_, ensuring that it made the lowest average squared error in its predictions. As we move from Linear Regression to Random Forest, Support Vector, and finally the decision tree, the _MSE_ progressively increases, with the decision tree having the highest _MSE_. The _RMSE_ chart shown in Figure 13b follows a similar trend to that in the MSE chart. Linear Regression again has the lowest _RMSE_, suggesting the lowest average magnitude of error. The errors increase from Random Forest to Support Vector and the decision tree, with the decision tree showing the highest _RMSE_. The \(R^{2}\) chart (Figure 13c) evaluates the accuracy of the ML models by evaluating the variance in the data. Linear Regression achieves the highest \(R^{2}\), close to 0.99, indicating a near-perfect fit. The \(R^{2}\) values decrease for Random Forest, Support Vector, and the decision tree, with the decision tree having the lowest \(R^{2}\) of 0.94.  
Figure 13: Performance comparison of the ML models for viscosity prediction: (**a**) _MSE_, (**b**) _RMSE_, and (**c**) \(R^{2}\).