def test_stratified_validation_k_fold():
 skip_if_no_sklearn()
 from pylearn2.cross_validation.subset_iterators import StratifiedValidationKFold
 n = 30
 y = np.concatenate((np.zeros((n / 2), dtype=int), np.ones((n / 2), dtype=int)))
 cv = StratifiedValidationKFold(y)
 for (train, valid, test) in cv:
  assert (np.unique(np.concatenate((train, valid, test))).size == n)
  assert (valid.size == (n / cv.n_folds))
  assert (test.size == (n / cv.n_folds))
  assert (np.count_nonzero(y[valid]) == ((n / 2) * (1.0 / cv.n_folds)))
  assert (np.count_nonzero(y[test]) == ((n / 2) * (1.0 / cv.n_folds)))

def test_stratified_validation_k_fold ( ) : skip_if_no_sklearn ( ) from pylearn2 . cross_validation . subset_iterators import StratifiedValidationKFold n = 30 y = np . concatenate ( ( np . zeros ( ( n / 2 ) , dtype = int ) , np . ones ( ( n / 2 ) , dtype = int ) ) ) cv = StratifiedValidationKFold ( y ) for ( train , valid , test ) in cv : assert ( np . unique ( np . concatenate ( ( train , valid , test ) ) ) . size == n ) assert ( valid . size == ( n / cv . n_folds ) ) assert ( test . size == ( n / cv . n_folds ) ) assert ( np . count_nonzero ( y [ valid ] ) == ( ( n / 2 ) * ( 1.0 / cv . n_folds ) ) ) assert ( np . count_nonzero ( y [ test ] ) == ( ( n / 2 ) * ( 1.0 / cv . n_folds ) ) )
test stratifiedvalidationkfold .