Is there a way to get a random sample? #3197
-
Looking at the docs, it seems there is no function to get a random sample of a dataframe. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Well, that's just a matter of generating a list of random indices from If the random samples are needed for K-fold cross validation, then please take a look at the parallel |
Beta Was this translation helpful? Give feedback.
Well, that's just a matter of generating a list of random indices from
0
tonrows - 1
and then using this list in the[i, j, ...]
selector asDT[list_of_random_indices, :]
. Thelist_of_random_indices
can be easily generated by using the standard Python modulerandom
. For instance,random.sample()
could be used for this purpose: https://docs.python.org/3/library/random.html#random.sampleIf the random samples are needed for K-fold cross validation, then please take a look at the parallel
kfold_random()
function, that is a part of thedatatable.models
: https://datatable.readthedocs.io/en/latest/api/models/kfold_random.html