コード例 #1
0
ファイル: run.py プロジェクト: queenstina/Transfer-Learning
 def __init__(
         self,
         pred=rforest,
         _smoteit=True,
         _n=-1,
         _tuneit=False,
         dataName=None,
         reps=1,
         extent=0.5,
         fSelect=False,
         Prune=False,
         infoPrune=0.75):
   self.pred = pred
   self.extent = extent
   self.fSelect = fSelect
   self.Prune = Prune
   self.infoPrune = infoPrune
   self.dataName = dataName
   self.out, self.out_pred = [], []
   self._smoteit = _smoteit
   self.train, self.test = self.categorize()
   self.reps = reps
   self._n = _n
   self.tunedParams = None if not _tuneit else tuner(
       self.pred, self.train[_n])
コード例 #2
0
 def __init__(
         self,
         pred=CART,
         _smoteit=True,
         _n=-1,
         _tuneit=False,
         dataName=None,
         reps=1,
         extent=0.5,
         fSelect=False,
         Prune=False,
         infoPrune=0.75):
   self.pred = pred
   self.extent = extent
   self.fSelect = fSelect
   self.Prune = Prune
   self.infoPrune = infoPrune
   self.dataName = dataName
   self.out, self.out_pred = [], []
   self._smoteit = _smoteit
   self.train, self.test = self.categorize()
   self.reps = reps
   self._n = _n
   self.tunedParams = None if not _tuneit else tuner(
       self.pred, self.train[_n])
コード例 #3
0
ファイル: run.py プロジェクト: ai-se/Tree-Learner
 def __init__(
         self, pred=rforest, _smoteit=True, _n=-1
         , _tuneit=False, dataName=None, reps=1):
   self.pred = pred
   self.dataName = dataName
   self.out, self.out_pred = [self.dataName], []
   self._smoteit = _smoteit
   self.train, self.test = self.categorize()
   self.reps = reps
   self._n = _n
   self.tunedParams = None if not _tuneit \
   else tuner(self.pred, self.train[_n])
   self.headers = createTbl(self.train[self._n], isBin=False
                            , bugThres=1).headers
コード例 #4
0
ファイル: testOracle.py プロジェクト: rahlk/Bellwether
 def __init__(self, file='ant', tuned=True):
     self.file = file
     self.train = createTbl(data(dataName=self.file).train[-1], isBin=True)
     self.test = createTbl(data(dataName=self.file).test[-1], isBin=True)
     self.param = dEvol.tuner(rforest, data(dataName=self.file).train[-1]) if \
         tuned else None
コード例 #5
0
ファイル: testOracle.py プロジェクト: ai-se/Tree-Learner
 def __init__(self, file='ant'):
   self.file = file
   self.train = createTbl(data(dataName=self.file).train[-1], isBin=False)
   self.test  = createTbl(data(dataName=self.file).test[-1],  isBin=False)
   self.param = tuner(rforest, data(dataName=self.file).train[-1])
コード例 #6
0
def main():
  dir = '../Data'
  from os import walk
  dataName = [Name for _, Name, __ in walk(dir)][0]
  numData = len(dataName)  # Number of data
  Prd = [CART]  # , rforest]  # , adaboost, logit, knn]
  _smoteit = [True]  # , False]
  _tuneit = [False]
  cd = {}
  abcd = []
  res = {}
  for n in xrange(numData):

    out11 = []
    outA1 = []
    out1 = []
    outFar = []
    outNear = []
    outa = []
    one, two = explore(dir)
    data = [one[i] + two[i] for i in xrange(len(one))]
    print('##', dataName[n])
    for p in Prd:
      train = [dat[0] for dat in withinClass(data[n])]
      test = [dat[1] for dat in withinClass(data[n])]
      reps = 10
      abcd = [[], []]
      for t in _tuneit:
        tunedParams = None if not t else params
        print('### Tuning') if t else print('### No Tuning')
        for _smote in _smoteit:
          #          for _n in xrange(0):
          _n = -1
          # Training data
          for _ in xrange(reps):

            train_DF = createTbl(train[_n], isBin=True)
#            set_trace()
            # Testing data
            test_df = createTbl(test[_n], isBin=True)
            predRows = []
            # Tune?
            actual = Bugs(test_df)
            before = p(train_DF, test_df,
                       tunings=tunedParams,
                       smoteit=True)
            tunedParams = None if not t else tuner(p, train[_n])
            for predicted, row in zip(before, test_df._rows):
              tmp = row.cells
              tmp[-2] = predicted
              if predicted > 0:
                predRows.append(tmp)
            predTest = clone(test_df, rows=predRows)
            # Find and apply contrast sets
#             newTab = treatments(train = train[_n],
#                                 test = test[_n],
#                                 verbose = False,
#                                 smoteit = False).main()

            newTab_near = treatments2(train=train[_n], far=False, test=test[_n]  # ).main()
                                      , test_df=predTest).main() \
                if predRows \
                else treatments2(train=train[_n], test=test[_n]).main()
            newTab_far = treatments2(train=train[_n], test=test[_n]  # ).main()
                                     , test_df=predTest).main() \
                if predRows \
                else treatments2(train=train[_n], test=test[_n]).main()

            after_far = p(train_DF, newTab_far,
                          tunings=tunedParams,
                          smoteit=True)
            after_near = p(train_DF, newTab_near,
                           tunings=tunedParams,
                           smoteit=True)
#             print(showoff(dataName[n], before, after))
            outa.append(_Abcd(before=actual, after=before))
#            set_trace()
            cliffsFar = cliffsdelta(Bugs(predTest), after_far)
            cliffsNear = cliffsdelta(Bugs(predTest), after_near)
#             print(cliffsDelta(Bugs(predTest), after))
#            print('Gain =  %1.2f' % float(\
#            	   (sum(Bugs(predTest)) - sum(after)) / sum(Bugs(predTest)) * 100), r'%')
            outFar.append(cliffsFar)
            outNear.append(cliffsNear)
#            out1.append(float((sum(before) - sum(after)) / sum(before) * 100))
#           out1 = [o for o in out1 if np.isfinite(o)]
          outNear.insert(0, dataName[n] + '_Far')
          outFar.insert(0, dataName[n] + '_Near')

          outa.insert(0, dataName[n])
        out11.extend([outNear, outFar])
        outA1.append(outa)
        try:
          print('```')
          rdivDemo(out11, isLatex=False)
    #      rdivDemo(outA1, isLatex = False)
          print('```')
        except IndexError:
          pass