Esempio n. 1
0
 def test_topk_slicing(self):
     join_top_k = slicer.process(self.all_features, self.complete_x, self.loss, len(self.complete_x), self.y_test, self.errors,
                    self.debug, self.alpha, self.k, self.w, self.loss_type, self.b_update)
     union_top_k = union_slicer.process(self.all_features, self.complete_x, self.loss, len(self.complete_x), self.y_test, self.errors,
                    self.debug, self.alpha, self.k, self.w, self.loss_type, self.b_update)
     self.assertEqual(join_top_k.min_score, union_top_k.min_score)
     print("check1")
     self.assertEqual(join_top_k.keys, union_top_k.keys)
     print("check2")
     self.assertEqual(len(join_top_k.slices), len(union_top_k.slices))
     print("check3")
     idx = -1
     for sliced in join_top_k.slices:
         idx += 1
         self.assertEqual(sliced.score, union_top_k.slices[idx].score)
     print("check4")
Esempio n. 2
0
    # alpha is size significance coefficient
    # verbose option is for returning debug info while creating slices and printing it
    # k is number of top-slices we want
    # w is a weight of error function significance (1 - w) is a size significance propagated into optimization function

    # enumerator <union>/<join> indicates an approach of next level slices combination process:
    # in case of <join> in order to create new node of current level slicer
    # combines only nodes of previous layer with each other
    # <union> case implementation is based on DPSize algorithm
    if enumerator == "join":
        slicer.process(all_features,
                       complete_x,
                       f_l2,
                       x_size,
                       y_test,
                       errors,
                       debug=debug,
                       alpha=alpha,
                       k=k,
                       w=w,
                       loss_type=loss_type,
                       b_update=b_update)
    elif enumerator == "union":
        union_slicer.process(all_features,
                             complete_x,
                             f_l2,
                             x_size,
                             y_test,
                             errors,
                             debug=debug,
                             alpha=alpha,
                             k=k,
Esempio n. 3
0
                n_estimators=10, n_jobs=2, oob_score=False, random_state=0,
                verbose=0, warm_start=False)

    # alpha is size significance coefficient
    # verbose option is for returning debug info while creating slices and printing it
    # k is number of top-slices we want
    # w is a weight of error function significance (1 - w) is a size significance propagated into optimization function
    # loss_type = 0 (l2 in case of regression model
    # loss_type = 1 (cross entropy in case of classification model)
    preds = clf.predict(x_test)
    predictions = []
    counter = 0
    mistakes = 0
    for pred in preds:
        predictions.append((counter, pred))
        if y_test[counter] != pred:
            mistakes = mistakes + 1
        counter = counter + 1
    lossF = mistakes / counter

    # enumerator <union>/<join> indicates an approach of next level slices combination process:
    # in case of <join> in order to create new node of current level slicer
    # combines only nodes of previous layer with each other
    # <union> case implementation is based on DPSize algorithm
    if enumerator == "join":
        slicer.process(all_features, complete_x, lossF, x_size, complete_y, predictions, debug=debug, alpha=alpha, k=k,
                       w=w, loss_type=loss_type, b_update=b_update)
    elif enumerator == "union":
        union_slicer.process(all_features, complete_x, lossF, x_size, complete_y, predictions, debug=debug, alpha=alpha,
                             k=k, w=w, loss_type=loss_type, b_update=b_update)