Hyperparameter tuning XGBoost
Instead of looping through the predictions why don't you import mean_squared_error from scikit learn's metrics module?
I'm guessing you are optimising using the mean squared log error objective.
Firstly, Log transform the Actual and predicted values and find the mean squared error
Example:
from sklearn.metrics import mean_squared_error
mean_sq_error = mean_squared_error(np.log1p(yval), np.log1p(pred))
np.log1p(x) does the same as np.log(x+1)