shuffleSplit() function in python

parameter:

 

n : int

The total number of elements in the dataset.

n_iter : int (default 10)

Reshuffle and split the number of iterations.

test_size : float (default 0.1), int, or None

If it is float type data, this number should be between 0-1.0, representing the proportion of the test set. If it is an int type, it represents the number of test sets. If it is None, the value will be automatically set to the complement of the size of the train set set

train_size : float, int, or None (default is None)

If it is a float type, it should be between 0 and 1, and represents the proportion of the data set in the train set split. If it is an int type, it represents the number of samples in the train set. If it is None, the value will be automatically set to test complement of set size

random_state : int or RandomState

Pseudo-random number generator state for random sampling.

 

[python]  view plain copy  
 
  1. >>> from sklearn import cross_validation  
  2. >>> rs = cross_validation.ShuffleSplit(4, n_iter=3,  
  3. ...     test_size=.25, random_state=0)  
  4. >>> len(rs)  
  5. 3  
  6. >>> print(rs)  
  7. ...   
  8. ShuffleSplit(4, n_iter=3, test_size=0.25, ...)  
  9. >>> for train_index, test_index in rs:  
  10. ...    print("TRAIN:", train_index, "TEST:", test_index)  
  11. ...  
  12. TRAIN: [0] TEST: [2]  
  13. TRAIN: [3] TEST: [0]  
  14. TRAIN: [1] TEST: [3]  
 

[python]  view plain copy  
 
  1. >>> rs = cross_validation.ShuffleSplit(4, n_iter=3,  
  2. ...     train_size=0.5, test_size=.25, random_state=0)  
  3. >>> for train_index, test_index in rs:  
  4. ...    print("TRAIN:", train_index, "TEST:", test_index)  
  5. ...  
  6. TRAIN: [1] TEST: [2]  
  7. TRAIN: [1] TEST: [0]  
  8. TRAIN: [2] TEST: [3]  
  9. .. automethod :: __init__  

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325518928&siteId=291194637