From 553edf5a8c482c8fd1d6009c134a1ef41aef8996 Mon Sep 17 00:00:00 2001 From: Gregory Ditzler Date: Mon, 25 Mar 2013 13:40:18 -0400 Subject: added import_data.py --- python/import_data.py | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 python/import_data.py diff --git a/python/import_data.py b/python/import_data.py new file mode 100644 index 0000000..c97ce7e --- /dev/null +++ b/python/import_data.py @@ -0,0 +1,40 @@ + + + + +################################################################## +################################################################## +################################################################## +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 + + 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 + +################################################################## +################################################################## +################################################################## -- cgit v1.2.3