Random state value changes the results of rmse and R2 I want to know why everytime I run my algorithm (XGBoost regressor) with a different random state (applied to train/test split part) I get different values for R2 and RMSE. For example :

*

*Random state = 0 -> RMSE = 4.67, R2 = 0.78

*Random state = 42 -> RMSE = 8.58, R2 = 0.54


Your code is doing what it should. There is a random component to your machine learning modeling, and that random component is different for the different random states, the same as how the following two code blocks will give different random numbers.
np.random.seed(2021)
np.random.normal(0, 1, 10)

vs
np.random.seed(2022)
np.random.normal(0, 1, 10)

