def random_sort(df, prng=None):
"""Randomly shuffle a DataFrame.
NOTE: if the training data is not randomly shuffled, then
supervised learning may find artifacts related to the order
of the data.
Parameters
----------
df : pd.DataFrame
dataframe with feature information
Returns
-------
df : pd.DataFrame
Randomly shuffled data frame
"""
# get new random state if not specified
if prng is None:
prng = np.random.RandomState()
# get random order
random_indices = prng.choice(df.index.values, # sample from 'genes'
len(df), # number of samples
replace=False) # sample without replacement
# change order of df
random_df = df.ix[random_indices].copy()
return random_df
评论列表
文章目录