aboutsummaryrefslogtreecommitdiff
path: root/test/import_data.py
diff options
context:
space:
mode:
authorCalvin <calvin@EESI>2013-03-26 13:54:21 -0400
committerCalvin <calvin@EESI>2013-03-26 13:54:21 -0400
commit63f3535a58191997dd2f9704dda635a3bf3f8fce (patch)
treee79c10f48aa47c13ef83c54ca5836ff46760e8fa /test/import_data.py
parenteac04614526d7d619822bbabf46543053e5e7200 (diff)
moved out of src, added a basic setup.py
Diffstat (limited to 'test/import_data.py')
-rw-r--r--test/import_data.py58
1 files changed, 58 insertions, 0 deletions
diff --git a/test/import_data.py b/test/import_data.py
new file mode 100644
index 0000000..6d4bd9e
--- /dev/null
+++ b/test/import_data.py
@@ -0,0 +1,58 @@
+
+
+
+
+##################################################################
+##################################################################
+##################################################################
+def read_digits(fname='digit.txt'):
+ '''
+ read_digits(fname='digit.txt')
+
+ read a data file that contains the features and class labels.
+ each row of the file is a feature vector with the class
+ label appended.
+ '''
+ import csv
+ import numpy as np
+
+ fw = csv.reader(open(fname,'rb'), delimiter='\t')
+ data = []
+ for line in fw:
+ data.append( [float(x) for x in line] )
+ data = np.array(data)
+ labels = data[:,len(data.transpose())-1]
+ data = data[:,:len(data.transpose())-1]
+ return data, labels
+##################################################################
+##################################################################
+##################################################################
+
+
+
+##################################################################
+##################################################################
+##################################################################
+def uniform_data(n_observations = 1000, n_features = 50, n_relevant = 5):
+ import numpy as np
+ xmax = 10
+ xmin = 0
+ data = np.random.randint(xmax + 1, size = (n_features, n_observations))
+ labels = np.zeros(n_observations)
+ delta = n_relevant * (xmax - xmin) / 2.0
+
+ for m in range(n_observations):
+ zz = 0.0
+ for k in range(n_relevant):
+ zz += data[k, m]
+ if zz > delta:
+ labels[m] = 1
+ else:
+ labels[m] = 2
+ data = data.transpose()
+
+ return data, labels
+
+##################################################################
+##################################################################
+##################################################################