def csv(self): import csv sep = self._init.get('CSV', 'separator') if not sep: print('give CSV separator in pyquan.ini file') sys.exit(2) CSV = csv.CSV(sep=sep) return CSV
def process_csv_file(self, file_defn): from data_importer.importers import csv kls = csv.CSV(file_defn=file_defn, options=self.options, stdout=self.stdout, stderr=self.stderr, debug_mode=self.debug_mode, meta_args=self.meta_args) return kls.process()
class MyConfig: conf = csv.CSV('config.csv') @classmethod def get_region(cls, cur_time: MyTime): raw_record = cls.__parse_record( cls.conf.binary_search( lambda record: cls.__parse_record(record)['time'] > cur_time)) # TODO: None 的情况 if raw_record['time'] < cur_time: cls.conf.cur_record() # 跳过当前记录 while True: if not cls.conf.cur_record(move_to_next=False): return [cls.__parse_record(cls.conf.prev_record()), None] if cls.__parse_record( cls.conf.cur_record())['time'] > cur_time: cls.conf.prev_record() break cls.conf.prev_record() elif raw_record['time'] > cur_time: while True: if cls.conf.get_cur_record_id() == 0: return [None, cls.__parse_record(cls.conf.cur_record())] if cls.__parse_record( cls.conf.prev_record())['time'] <= cur_time: break return [ cls.__parse_record(cls.conf.cur_record()), cls.__parse_record(cls.conf.cur_record()) ] @staticmethod def __parse_record(record): return { 'time': MyTime([int(item) for item in record[:-2]] + [0]), 'angle': { 'pitch': float(record[5]), 'yaw': int(record[4]) } if record else None }
def modWeights(self): for layer in self.layers: for l, error in zip(layer, self.errorList): newWeights = [] #print l.weights for w, e in zip(l.weights, error): new = w - (l.learn * e * l.actv) newWeights.append(new) l.weights = newWeights #print l.weights #getting data and user preferences data = csv.CSV().data[:10] np.seterr(all='ignore') numLayers = int(raw_input('how many hidden layers?: ')) + 1 nodeCounts = [] for x in range(numLayers): if x == numLayers - 1: nodeCounts.append(int(raw_input('how many targets: '))) else: nodeCounts.append( int(raw_input('nodes for hidden layer ' + str(x + 1) + ': ')) + 1) #add 1 for bias ######################## #initializing neural network n = Network(len(data[0]), numLayers, nodeCounts)
return fileName[fIndex] ################################ def multiply(data, yes): if yes: newData = [] for x in range(5): for d in data: newData.append(d) return newData return data p = prompt() data = csv.CSV(p[0], p[1]).data data = multiply(data, p[1]) d = DecisionTree(data, p[2]) d.swap() d.fit() d.predict() d.compare() show(d) d.display(d.nodes.children[0]) d.display(d.nodes.children[len(d.nodes.children) - 1], 2) ################################
############################### def prompt(): fileName = { '1': ('parties.txt', False, True), '2': ('iris.txt', False, False), '3': ('lenses.txt', True, False), '4': ('credit.txt', True, False) } for key, value in fileName.iteritems(): print key + ': ' + value[0] fIndex = '' while not fIndex in fileName: fIndex = raw_input('Which file#: ') return fileName[fIndex] ################################ p = prompt() d = DecisionTree(csv.CSV(p[0], p[1]).data, p[2]) d.start() show(d) ################################