Exemplo n.º 1
0
 def calculate(self, learner):
     '''
 calculate the improvements for one learner
 '''
     res = []
     oldresult = result(self.old_path).read()
     newresult = result(self.new_path).read()
     for old, new in zip(oldresult[learner], newresult[learner]):
         try:
             res.append(new - old)
         except:
             continue
     return res
Exemplo n.º 2
0
 def calculate(self, learner):
   '''
   calculate the improvements for one learner
   '''
   res = []
   oldresult = result(self.old_path).read()
   newresult = result(self.new_path).read()
   for old, new in zip(oldresult[learner], newresult[learner]):
     try:
       res.append(new - old)
     except:
       continue
   return res
Exemplo n.º 3
0
  def csv(self, name):
    naive_learner = ['Naive_Where', 'Naive_CART', 'Naive_RF']
    tuned_learner = ['Tuned_Where', 'Tuned_CART', 'Tuned_RF']

    oldresult = result(self.old_path).read()
    newresult = result(self.new_path).read()
    res = "Name," + ",".join(newresult["Dataset"]) + '\n'
    for j, aresult in enumerate([oldresult, newresult]):
      for one in naive_learner:
        if j == 0:
          res += "Old_" + str(one) + "," + ",".join([str(i) for i in aresult[one]]) + '\n'
        else:
          res += "New_" + str(one) + "," + ",".join([str(i) for i in aresult[one]]) + '\n'
    f = open("RX4_" + name + '.csv', "w")
    f.write(res)
Exemplo n.º 4
0
def tune_over_naive(path):
  '''
  :param path: the path of experiment results, e.g: "allf"
  :return: a list of results for each learner with respect to Naive, Tuned, Grid.
  '''
  result_dict = result(path).read()
  # pdb.set_trace()
  out = []
  # if "f" in path:
  #   result_dict["Grid_CART"] = [0,52,11,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
  #   result_dict["Grid_RF"] = [0,0,11,33,0,46,18,36,0,0,0,0,0,0,56,0,0]
  # else:
  #   result_dict["Grid_CART"] = [85,85,19,93,0,0,100,0,67,60,0,60,0,0,66,0,0]
  #   result_dict["Grid_RF"] = [59,40,0,0,0,0,0,0,46,0,100,100,100,75,0,0,25]
  # for learner in ["CART", "RF"]:
  for learner in ["CART","RF"]:
    res = {}
    naive = None
    for task in ["Naive_", "Tuned_", "Cluster_","Nbrs_","NaiveTest_"]:
      name = task + learner
      if task == "Naive_":
        naive = name
      res[name] = np.array(result_dict[name])
    sorted_index = np.argsort(res[naive])
    res_sorted = {}
    for key, val in res.iteritems():
      res_sorted[key] = val[sorted_index]
    # print(str(res))
    out.append(res_sorted)
  return out
Exemplo n.º 5
0
    def csv(self, name):
        naive_learner = ['Naive_Where', 'Naive_CART', 'Naive_RF']
        tuned_learner = ['Tuned_Where', 'Tuned_CART', 'Tuned_RF']

        oldresult = result(self.old_path).read()
        newresult = result(self.new_path).read()
        res = "Name," + ",".join(newresult["Dataset"]) + '\n'
        for j, aresult in enumerate([oldresult, newresult]):
            for one in naive_learner:
                if j == 0:
                    res += "Old_" + str(one) + "," + ",".join(
                        [str(i) for i in aresult[one]]) + '\n'
                else:
                    res += "New_" + str(one) + "," + ",".join(
                        [str(i) for i in aresult[one]]) + '\n'
        f = open("RX4_" + name + '.csv', "w")
        f.write(res)
Exemplo n.º 6
0
  def csv_rx4(self, name):
    naive_learner = ['Naive_Where', 'Naive_CART', 'Naive_RF']
    tuned_learner = ['Tuned_Where', 'Tuned_CART', 'Tuned_RF']

    # oldresult = result(self.old_path).read()
    newresult = result(self.new_path).read()
    res = "Name," + ",".join(newresult["Dataset"]) + '\n'
    for j, aresult in enumerate([newresult]):
      for naive, tuned in zip(naive_learner, tuned_learner):
        res += "RX4_" + str(naive) + "," + ",".join([str(i) for i in aresult[naive]]) + '\n'
        res += "RX4_" + str(tuned) + "," + ",".join([str(i) for i in aresult[tuned]]) + '\n'
    f = open("RX4_" + name + '.csv', "w")
    f.write(res)
Exemplo n.º 7
0
    def csv_rx4(self, name):
        naive_learner = ['Naive_Where', 'Naive_CART', 'Naive_RF']
        tuned_learner = ['Tuned_Where', 'Tuned_CART', 'Tuned_RF']

        # oldresult = result(self.old_path).read()
        newresult = result(self.new_path).read()
        res = "Name," + ",".join(newresult["Dataset"]) + '\n'
        for j, aresult in enumerate([newresult]):
            for naive, tuned in zip(naive_learner, tuned_learner):
                res += "RX4_" + str(naive) + "," + ",".join(
                    [str(i) for i in aresult[naive]]) + '\n'
                res += "RX4_" + str(tuned) + "," + ",".join(
                    [str(i) for i in aresult[tuned]]) + '\n'
        f = open("RX4_" + name + '.csv', "w")
        f.write(res)