# Building the dataset for Random Forest training procedure

I should use the bagging (bootstrap aggregating) technique in order to train a random forest classifier. I read here the description of this learning technique, but I have not figured out how I initially organize the dataset.

Currently I first load all the positive examples and immediately after the negative ones. Moreover, positive examples are less than half of the negative ones, so by sampling from the dataset uniformly, the probability of obtaining a negative example is greater than that of obtaining a positive example.

How should I build the initial dataset? Should I shuffle the initial dataset containing positive and negative examples?

If your former dataset has $N$ elements, you will have to sample with replacement $N$ elements from that dataset to obtain a bootstrap sample.
About standard bootstrapping, you might just generate a random number between $1$ and $N$ to obtain one record of the bootstrap sample.
In the unbalanced case we might go for oversampling for example. In order to produce one record in the bootstrap sample you might flip a coin (random number in $\{0,1\}$): if head you choose a random record from the positive ones; if tail you choose a random one from negatives. The classes will be balanced in the bootstrap sample.