zoukankan      html  css  js  c++  java
  • 随机打乱工具sklearn.utils.shuffle,将原有的序列打乱,返回一个全新的错乱顺序的值

    Shuffle arrays or sparse matrices in a consistent way

    This is a convenience alias to resample(*arrays, replace=False) to do random permutations of the collections.

    Parameters:

    *arrays : sequence of indexable data-structures

    Indexable data-structures can be arrays, lists, dataframes or scipy sparse matrices with consistent first dimension.

    random_state : int or RandomState instance

    Control the shuffling for reproducible behavior.

    n_samples : int, None by default

    Number of samples to generate. If left to None this is automatically set to the first dimension of the arrays.

    Returns:

    shuffled_arrays : sequence of indexable data-structures

    Sequence of shuffled views of the collections. The original arrays are not impacted.

    # -*- coding: utf-8 -*-
    """
    Spyder Editor
    
    This is a temporary script file.
    """
    
    import numpy as np
    
    X = np.array([[1., 0.], [2., 1.], [0., 0.]])
    y = np.array([0, 1, 2])
    
    from scipy.sparse import coo_matrix
    X_sparse = coo_matrix(X)
    
    print '稀疏矩阵%s
    ',X_sparse
    
    from sklearn.utils import shuffle
    X, X_sparse, y = shuffle(X, X_sparse, y, random_state=0)
    print 'X值
    ', X
    
    print 'X_sparse值
    ', X_sparse
    
    print 'y值
    ', y
    
    '''
    稀疏矩阵%s
      (0, 0)        1.0
      (1, 0)        2.0
      (1, 1)        1.0
    X值
    [[ 0.  0.]
     [ 2.  1.]
     [ 1.  0.]]
    X_sparse值
      (1, 1)        1.0
      (1, 0)        2.0
      (2, 0)        1.0
    y值
    [2 1 0]
    '''
  • 相关阅读:
    mac 终端命令
    安装和使用Carthage
    Mac下的常用终端命令与vim常用命令
    swift 获取推送deviceToken
    使mac版的MYSQL支持emoji表情
    iOS --- 通过CPU实现的简单滤镜效果
    IOS多选单选相册图片
    AVCaptureDevice iOS摄像头属性
    GPUImage 滤镜介绍
    苹果IOS开发者账号如何续费-Appstore
  • 原文地址:https://www.cnblogs.com/qqhfeng/p/5762471.html
Copyright © 2011-2022 走看看