Repository navigation
Expand file tree
/
Copy pathtest_split.py
More file actions
70 lines (58 loc) · 2.67 KB
/
Copy pathtest_split.py
File metadata and controls
70 lines (58 loc) · 2.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import inspect
import os
import unittest
import numpy as np
from openml import OpenMLSplit
class OpenMLSplitTest(unittest.TestCase):
def setUp(self):
__file__ = inspect.getfile(OpenMLSplitTest)
self.directory = os.path.dirname(__file__)
# This is for dataset
self.arff_filename = os.path.join(
self.directory, "..", "files", "tasks", "1882", "datasplits.arff")
self.pd_filename = self.arff_filename.replace(".arff", ".pkl")
def tearDown(self):
try:
os.remove(self.pd_filename)
except:
pass
def test_eq(self):
split = OpenMLSplit._from_arff_file(self.arff_filename)
self.assertEqual(split, split)
split2 = OpenMLSplit._from_arff_file(self.arff_filename)
split2.name = "a"
self.assertNotEqual(split, split2)
split2 = OpenMLSplit._from_arff_file(self.arff_filename)
split2.description = "a"
self.assertNotEqual(split, split2)
split2 = OpenMLSplit._from_arff_file(self.arff_filename)
split2.split[10] = dict()
self.assertNotEqual(split, split2)
split2 = OpenMLSplit._from_arff_file(self.arff_filename)
split2.split[0][10] = dict()
self.assertNotEqual(split, split2)
def test_from_arff_file(self):
split = OpenMLSplit._from_arff_file(self.arff_filename)
self.assertIsInstance(split.split, dict)
self.assertIsInstance(split.split[0], dict)
self.assertIsInstance(split.split[0][0][0], np.ndarray)
self.assertIsInstance(split.split[0][0].train, np.ndarray)
self.assertIsInstance(split.split[0][0].train, np.ndarray)
self.assertIsInstance(split.split[0][0][1], np.ndarray)
self.assertIsInstance(split.split[0][0].test, np.ndarray)
self.assertIsInstance(split.split[0][0].test, np.ndarray)
for i in range(10):
for j in range(10):
self.assertGreaterEqual(split.split[i][j].train.shape[0], 808)
self.assertGreaterEqual(split.split[i][j].test.shape[0], 89)
self.assertEqual(split.split[i][j].train.shape[0] +
split.split[i][j].test.shape[0], 898)
def test_get_split(self):
split = OpenMLSplit._from_arff_file(self.arff_filename)
train_split, test_split = split.get(fold=5, repeat=2)
self.assertEqual(train_split.shape[0], 808)
self.assertEqual(test_split.shape[0], 90)
self.assertRaisesRegexp(ValueError, "Repeat 10 not known",
split.get, 10, 2)
self.assertRaisesRegexp(ValueError, "Fold 10 not known",
split.get, 2, 10)