Calculating Root Mean Square Error (RMSE) in Percentage using scikit-learn library
Root Mean Square Error (RMSE) is a popular metric for evaluating the accuracy of a model’s predictions. It measures the average distance between the predicted values and the actual values in a dataset. However, sometimes it is helpful to express RMSE as a percentage to better understand the magnitude of the errors.
In order to calculate RMSE in percentage using scikit-learn library, you can follow the steps below:
- First, import necessary libraries:
- Next, calculate the RMSE using the mean_squared_error function:
- Then, calculate the RMSE in percentage:
- Finally, print out the RMSE in percentage:
<code>
import numpy as np
from sklearn.metrics import mean_squared_error
</code>
<code>
y_true = np.array([3, -0.5, 2, 7])
y_pred = np.array([2.5, 0.0, 2, 8])
rmse = np.sqrt(mean_squared_error(y_true, y_pred))
</code>
<code>
rmse_percentage = (rmse/np.mean(y_true))*100
</code>
<code>
print('RMSE in percentage:', rmse_percentage)
</code>
By following these steps, you can now calculate the RMSE in percentage using the scikit-learn library. This can be helpful in understanding the accuracy of your model’s predictions in a more intuitive way.