Skip to content

Commit 4619b99

Browse files
author
Tomasz Latkowski
committed
added tests to Fisher method
1 parent 9f9f6a9 commit 4619b99

File tree

8 files changed

+64
-1
lines changed

8 files changed

+64
-1
lines changed

methods/__init__.py

Whitespace-only changes.

selection.py renamed to methods/selection.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
import tensorflow as tf
2+
import pandas as pd
3+
4+
data_file = '../data/autism.tsv'
5+
df = pd.read_csv(data_file, sep='\t', header=None, index_col=0).T
26

37

48
def fisher(data, num_instances: list, top_k=10):
@@ -15,7 +19,7 @@ def fisher(data, num_instances: list, top_k=10):
1519
class1, class2 = tf.split(data, num_instances)
1620
mean1, std1 = tf.nn.moments(class1, axes=0)
1721
mean2, std2 = tf.nn.moments(class2, axes=0)
18-
fisher_coeffs = (mean1 - mean2) / (std1 + std2)
22+
fisher_coeffs = tf.abs((mean1 - mean2)) / (std1 + std2)
1923
return tf.nn.top_k(fisher_coeffs, k=top_k)
2024

2125

@@ -46,3 +50,12 @@ def t_test(data, num_instances: list, top_k=10):
4650
t_test_coeffs = (mean1 - mean2) / tf.sqrt(tf.square(std1)/num_instances[0] + tf.square(std2) / num_instances[1])
4751
return tf.nn.top_k(t_test_coeffs, k=top_k)
4852

53+
with tf.Session() as session:
54+
input_data = df.as_matrix()
55+
instances_per_class = [82, 64]
56+
fisher_coeffs = session.run(fisher(data=input_data, num_instances=instances_per_class))
57+
corr_coeffs = session.run(feature_correlation_with_class(data=input_data, num_instances=instances_per_class))
58+
t_test_coeff = session.run(t_test(data=input_data, num_instances=instances_per_class))
59+
print(fisher_coeffs)
60+
print(corr_coeffs)
61+
print(t_test_coeff)

tests/__init__.py

Whitespace-only changes.

tests/corr.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import tensorflow as tf
2+
3+
4+
class CorrelationWithClassSelectionTest(tf.test.TestCase):
5+
6+
def testCorrelationWithClassCorrectScore(self):
7+
raise NotImplementedError
8+
9+
10+
if __name__ == '__main__':
11+
tf.test.main()

tests/fisher.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import tensorflow as tf
2+
from methods.selection import fisher
3+
import numpy as np
4+
5+
6+
class FisherSelectionTest(tf.test.TestCase):
7+
8+
def testFisherCorrectScore(self):
9+
with self.test_session() as test_session:
10+
data = np.array([[2, 2],
11+
[4, 4],
12+
[3, 6],
13+
[5, 6]])
14+
num_instances = [2, 2]
15+
top_k = 2
16+
actual_most_significant_features = test_session.run(fisher(data, num_instances, top_k))
17+
18+
correct_most_significant_features = tf.constant([3., .5])
19+
self.assertAllEqual(actual_most_significant_features.values, correct_most_significant_features.eval())
20+
21+
def testFisherCorrectOrderOfFeatures(self):
22+
raise NotImplementedError
23+
24+
def testMoreThan2ClassesIsNotAllowed(self):
25+
raise NotImplementedError
26+
27+
if __name__ == '__main__':
28+
tf.test.main()

tests/ttest.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import tensorflow as tf
2+
3+
4+
class TtestSelectionTest(tf.test.TestCase):
5+
6+
def testTtestCorrectScore(self):
7+
raise NotImplementedError
8+
9+
10+
if __name__ == '__main__':
11+
tf.test.main()

utils/__init__.py

Whitespace-only changes.
File renamed without changes.

0 commit comments

Comments
 (0)