def plot_prim_time_series(boxes, data, outcome): x, results = data outcomes = results[outcome] try: time = results.get('TIME')[0, :] except KeyError: time = np.arange(0, outcomes.shape[1]) #the plotting grid = gridspec.GridSpec(len(boxes)-1, 1) grid.update(wspace = 0.05, hspace = 0.4) figure = plt.figure() for i, box in enumerate(boxes[0:-1]): logical = in_box(x, box.box) #make the axes ax = figure.add_subplot(grid[i, 0]) value = outcomes[logical] ax.plot(time.T[:, np.newaxis], value.T) return figure
def make_boxes(tree, data, classify, threshold): ''' Function that turns a classification tree into prim boxes, including the scenario discovery metrics. :param tree: the return from :func:`orangeFunctions.tree`. :param data: the return from :meth:`perform_experiments`. :param classify: the classify function used in making the tree. :param threshold: the minimum mean that the boxes should meet. :return: a list of prim boxes. ''' branches = find_branches(tree.tree, [("root", "")]) data, results = data init_box = make_box(data) boxes = [] for branch in branches: box = copy.copy(init_box) for name in branch[1:]: name, limit = name if name=="root" or type(name) != StringType: continue if limit.startswith('>'): limit = limit[1:] limit = float(limit) box[name][0] = limit else: limit = limit[2:] limit = float(limit) box[name][1] = limit boxes.append(box) y = classify(results) n = y.shape[0] threshold=0.8 threshold_type=1 #turn boxes into prim objects new_boxes = [] for box in boxes: logical = in_box(data, box) box = Prim(data[logical], y[logical], box, y[logical].shape[0]/n) new_boxes.append(box) boxes = prim_hdr(new_boxes, threshold=threshold, threshold_type=threshold_type) boxes = calculate_sd_metrics(boxes, y, threshold, threshold_type) return boxes