1
$\begingroup$

So, I have a few questions concerning random Forests (mainly in R):

  1. How ntree affects Random Forests in general? Will we get more precise "OOB error" (more trees -> bigger possibility that OOB sample will be part of a test set for more trees -> hence, precise OOB error?)?
  2. How set.seed() helps randomness for RFs? When we do sampling with replacement I'm thinking that by using the same seed (ex. set.seed(1234)) we will draw same rows for each forest? That is, if we used first 10 rows on tree_1, in random forest_1 then we will use the same rows in tree_1 of random_forest_2, or random_forest_3 etc.
  3. Why changing the order of features “improves” a bit OOB error rate, and overall class.error? (using the same seed)
  4. Speaking of R, how is confusion matrix made for Random Forest? Do we first train the model, and then we put all the data points in pre-trained RF so we can obtain TruePositives etc. by counting them.

PS. I'm currently using RFs mainly for EDA!

$\endgroup$
1
$\begingroup$
  1. How ntree affects Random Forests in general? Will we get more precise "OOB error" (more trees -> bigger possibility that OOB sample will be part of a test set for more trees -> hence, precise OOB error?)?

This is simple: the more trees, the better, where you should use something like 100, 250, or more trees if you can afford it.

  1. How set.seed() helps randomness for RFs? When we do sampling with replacement I'm thinking that by using the same seed (ex. set.seed(1234)) we will draw same rows for each forest? That is, if we used first 10 rows on tree_1, in random forest_1 then we will use the same rows in tree_1 of random_forest_2, or random_forest_3 etc.

Setting seed for random number generator makes the results reproducible. So if you use, and record the seed, then when running the algorithm next time with the same data and same hyperparameters, it will give you exactly the same results. Of course, we are talking here about setting seed before running the whole random forest algorithm, if you'd set the seed to the same value before training each of the trees within the random forest, all the trees would be identical, what would make them useless, since the algorithm would work not better then single decision tree.

  1. Why changing the order of features “improves” a bit OOB error rate, and overall class.error? (using the same seed)

It does not. If this is something that you observed, this must have happened by chance, or may suggest that there is some kind of bug in the code. In the Collinearity of features and random forest thread you can find more details that should shed some light on this.

  1. Speaking of R, how is confusion matrix made for Random Forest? Do we first train the model, and then we put all the data points in pre-trained RF so we can obtain TruePositives etc. by counting them.

Yes, it's exactly the same as with any other algorithm: you train it, then you plug-in the data and look at the predictions, to compare them with the true labels and calculate the metrics.

You seem to have many questions on this topic, Q&A sites like this are not best suited for explaining such cases in detail (you usually can expect rather brief and focused answers). I'd recommend you to start with a handbook, for example the great and freely available ISL and ESL. Finally, next time please try asking one question per thread, follow the be specific rule.

$\endgroup$
  • $\begingroup$ Thank you! I'll try to improve in my next questions. $\endgroup$ – Krushe Feb 15 at 11:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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