forked from kaz-Anova/py_ml_utils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmisc_tests.py
70 lines (55 loc) · 2.12 KB
/
misc_tests.py
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 unittest
import numpy as np
from misc import *
from sklearn import linear_model
class TestMisc(unittest.TestCase):
def test_mean_score(self):
self.assertEqual('2.000 (+/-0.577)', mean_score([1., 2., 3.]))
def test_scale(self):
arr = np.linspace(10, 100, 5)
arr_scaled = scale(arr)
exp = [-1.4142, -0.7071, 0., 0.7071, 1.4142]
self.assertTrue(np.allclose(exp, arr_scaled))
def test_scale_with_min_max(self):
scaled = scale(np.matrix('1. 2.; 3. 4.'), (0, 1))
exp = np.matrix('0. 0.; 1. 1.')
self.assertTrue(np.allclose(exp, scaled))
def test_do_n_sample_search(self):
pass
def test_cv(self):
c = linear_model.LinearRegression()
X = np.matrix('1. 1. 1. 1;2. 2. 2. 2;3. 3. 3. 3.')
y = np.matrix('1. ;2. ;3.')
cv = do_cv(c, X, y)
def test_gs(self):
c = linear_model.LinearRegression()
X = np.matrix('1. 1. 1. 1;2. 2. 2. 2;3. 3. 3. 3.')
y = np.matrix('1. ;2. ;3.')
cv = do_gs(c, X, y, {})
def test_one_hot_encode(self):
df = pd.DataFrame({'col0': [1.1, 1.2, 1.3, 1.4, 1.5], 'col1':[1, 2, 3, 3, 1], 'col2': ['a', 'b', 'c', 'd', 'e']})
df2 = one_hot_encode(df, [1], drop_originals=True)
self.assertEqual(5, df2.shape[1])
exp = [[1., 0., 0.],[0., 1., 0.],[0., 0., 1.],[0., 0., 1.],[1., 0., 0.]]
self.assertTrue((np.array(exp) == df2[:, 2:]).all())
def test_to_index(self):
df = pd.DataFrame({'col0': [1.1, 1.2, 1.3, 1.4, 1.5], 'col1':[1, 2, 3, 3, 1], 'col2': ['a', 'b', 'c', 'd', 'e']})
df2 = to_index(df, [1], drop_originals=True)
self.assertEqual(3, df2.shape[1])
exp = [0, 1, 2, 2, 0]
self.assertTrue((df2.col1_indexes.values == exp).all())
def test_save_data(self):
pass
def test_read_data(self):
pass
def test_save_data_gzip(self):
pass
def test_read_data_gzip(self):
pass
def test_inv_hyp_sine(self):
arr = np.array([1.1, 1.2, 1.3, 1.4, 1.5])
trans = np.arcsinh([1.1, 1.2, 1.3, 1.4, 1.5])
arr2 = np.sinh(trans)
np.testing.assert_array_equal(arr, arr2)
if __name__ == '__main__':
unittest.main()