コード例 #1
0
 def testKFoldsRandomize(self):
   kfolds = data_split.KFolds(2)
 
   partition1 = kfolds.split(range(10))
   partition2 = kfolds.split(range(10), randomize=True)
 
   self.assertNotEqual(partition1, partition2)
   self.assertItemsEqual(
     partition1[0][0]+partition1[0][1], partition2[0][0]+partition2[0][1])
コード例 #2
0
  def testKFolds3(self):
    kfolds = data_split.KFolds(3)

    with self.assertRaises(ValueError):
      kfolds.split(xrange(2))

    self.assertSequenceEqual(
        kfolds.split(xrange(3)),
        [([1, 2], [0]), ([0, 2], [1]), ([0, 1], [2])])

    self.assertSequenceEqual(
        kfolds.split(xrange(4)),
        [([1, 2, 3], [0]), ([0, 2, 3], [1]), ([0, 1, 3], [2])])
コード例 #3
0
 def testKFoldsBadKValue(self):
   with self.assertRaises(ValueError):
     data_split.KFolds(1)
コード例 #4
0
 def testKFoldsBadKType(self):
   with self.assertRaises(TypeError):
     data_split.KFolds(3.0)