I am building a random forest classifier for DoS/DDoS attack detection, it is a binary classification problem. While tuning the parameters I got confused about what parameters to focus on exactly and what values I should choose. I chose some parameters as shown in the code, but I kept thinking what if I didn't include that one value that would give me the best result.

So my question is, from all the random forest's parameters, what parameters to focus on and which values I should give them?

#hyperparametres tuning
#finding best params
   forest = RandomForestClassifier()
   params = { 
                'n_estimators': [100,150,200],
                 'max_features': ['auto','log2'],
                 'max_depth' : [4,5,6,7],
                 'min_samples_split' :[2,3,4,5,6],
                 'max_samples': [100,150,200,250]
   CV_rfc = GridSearchCV(estimator=forest, param_grid=params, cv= 5)
   CV_rfc.fit(x_train, y_train)
  • $\begingroup$ What do you wish to gain by optimizing the parameters? Ie, what are you optimising for ? $\endgroup$
    – Jon Nordby
    Aug 30, 2022 at 18:06
  • $\begingroup$ How many samples do you have? Recommend setting max_samples as a float, which means the proportion of samples - less easy to mess up than hardcoding an exact number $\endgroup$
    – Jon Nordby
    Aug 30, 2022 at 18:09

1 Answer 1


Random Forest is one of the few algorithms which will work well for default parameters. If you'd like to get precise I'd recommend using this paper https://arxiv.org/pdf/1804.03515.pdf. It gives you good pointers on what attributes to use when working with classification or regression algorithms. If its classification you might want to keep max depth as None (i.e grow the tree to its full depth). Random forest aren't prone to overfitting unlike Decisions trees.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.