feature_utils.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:2020plus 作者: KarchinLab 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号