def get_data(): raw_data = [] # loop through the csv and get each row with open('data/forestFireData.csv', 'rb') as csvfile: # reader reads the csv reader = csv.reader(csvfile, delimiter=',', quotechar='|') # append to the list the row for row in reader: raw_data.append(row) # get the header from the raw_data header = raw_data[0] # get the rest of the data data = raw_data[1:len(raw_data)] # make the nodes nodes = [] # loop through the dimensions and make a node for each one for i in range(0, len(header)): node = BNNode(['0', '1'], util.col(data, i)) node.col_index = i node.name = header[i] nodes.append(node) # set the classes classes = nodes[-1] del nodes[-1] # return everything return (nodes, data, classes.row_values)
def test_remove_parental_diff_from_pred(self): a = BNNode([], []) b = BNNode([], []) c = BNNode([], []) pred = [a,b,c] node = BNNode([], []) node.parents = [c] new_pred = BN.remove_parental_diff_from_pred(node, pred) self.assertEquals(2, len(new_pred)) self.assertEquals(True, new_pred[0] == a) self.assertEquals(True, new_pred[1] == b)
def test_get_list_of_cols(self): n1 = BNNode([], []) n1.col_index = 0 n2 = BNNode([], []) n2.col_index = 1 n3 = BNNode([], []) n3.col_index = 2 n1.parents.append(n2) n1.parents.append(n3) col_list = BNClassifier.get_list_of_cols(n1) self.assertEquals(1, col_list[0]) self.assertEquals(2, col_list[1])
def test_get_count(self): n1 = BNNode([], []) n1.col_index = 0 n2 = BNNode([], []) n2.col_index = 1 n3 = BNNode([], []) n3.col_index = 2 n1.parents.append(n2) n1.parents.append(n3) cols = [1,2] row = [0,1,0] data = [[0,1,0], [0,1,0], [0,0,0], [0,1,0]] classes = ['a', 'b', 'a', 'b'] poss = ['a', 'b'] counts = BNClassifier.get_count(row, n1, data, classes, poss)