-1

I am a newbie in machine learning, can anyone explain to me why every time I run the model and tune hyperparameters, I use RandomSearch, when I get good parameters and apply them, it gets a good result. But when I run it all again, in tunning parameters, even though it's the same parameter before, the accuracy is lower than last time, can everyone explain to me?

XGboost - here is my best result in this model, then any time I run is lower than that.

this picture is my best result

Can anyone explain how to get a better result?

QHarr
  • 83,427
  • 12
  • 54
  • 101
Thanh
  • 1
  • 1
    Try to fix the random seed of python, numpy, XGboost and whatever else you are using. If your training depends on random samplings of the data you'll get a different result each time unless you make the randomness be deterministic (i.e. fixed.) – Luca Anzalone Apr 21 '23 at 13:41

2 Answers2

0

i think this problem is caused by XGBoost. XGBoost is a ensemble of decision trees, and it selects features to build trees randomly, each time you build a new XGBoost, the model is changed, so the best hyperparameters change.

yuhan
  • 1
0

You say you used Random Search. Random Search is a technique that selects random combinations of hyperparameters for your model during the tuning process. Since it's random, the chosen combinations might be different each time you run your code, which can lead to varying accuracy results.

To make sure you get consistent results each time you run your code, you can set a "random state" or "seed". This is a fixed number that ensures the random process starts from the same point, which helps in producing the same results every time.

To get the same results every time, you not only have to set the random state for the Random Search, but anywhere, where sampling is performed: E.g. when calling train_test_split, when calling StratifiedKFold or when training your XGBClassifier.

DataJanitor
  • 1,276
  • 1
  • 8
  • 19