示例#1
0
 def evaluate(self, test, y_test, print_output=False):
     pred = _prepare_prediction(test, self._ests_store, self.threshold)
     return evaluate_prediction(self.method,
                                self.labels,
                                y_test,
                                pred,
                                print_output=print_output)
示例#2
0
 def train(self, train, y_train):
     thresholds = np.linspace(0, 1, 10, endpoint=False)
     lambdas = np.linspace(0, 1, 10, endpoint=False)
     ngrams = range(2, 10) if self.use_ngram else [0]
     for _lambda in lambdas:
         for n in ngrams:
             pred = self._prepare_prediction(train, _lambda, n)
             for t in thresholds:
                 p = pred.apply(lambda x: _set_label(x, t), axis=1)
                 f1 = get_aggregate_evaluation(
                     self.labels,
                     evaluate_prediction(
                         "{}-{}-{}-{}".format(self.method, t, _lambda, n),
                         self.labels,
                         y_train,
                         p,
                     ),
                 )
                 if f1 > self.max_f1:
                     self.max_f1 = f1
                     self.threshold = t
                     self._lambda = _lambda
                     self.ngram = n
     logging.debug(
         f"training found an optimum f1 of {self.max_f1} with threshold {self.threshold} and lambda {self._lambda} and ngram {self.ngram}"
     )
示例#3
0
 def evaluate(self, test, y_test, print_output):
     return evaluate_prediction(
         self.method,
         self.labels,
         y_test,
         self.predict(test),
         print_output=print_output,
     )
示例#4
0
 def evaluate(self, test, y_test, print_output=False):
     pred = self._prepare_prediction(test, self._lambda, self.ngram)
     pred = pred.apply(lambda x: _set_label(x, self.threshold), axis=1)
     return evaluate_prediction(self.method,
                                self.labels,
                                y_test,
                                pred,
                                print_output=print_output)
示例#5
0
 def train(self, train, y_train):
     thresholds = np.linspace(0, 1, 10, endpoint=False)
     for t in thresholds:
         p = _prepare_prediction(train, self._ests_store, t)
         f1 = get_aggregate_evaluation(
             self.labels,
             evaluate_prediction(self.method, self.labels, y_train, p))
         if f1 > self.max_f1:
             self.max_f1 = f1
             self.threshold = t
     logging.debug(
         "training found an optimum f1 of {} with threshold {}".format(
             self.max_f1, self.threshold))
示例#6
0
 def train(self, train, y_train):
     thresholds = np.linspace(0, 1, 10, endpoint=False)
     pred = _prepare_prediction(train)
     for t in thresholds:
         p = pred.apply(lambda x: _set_label(x, t), axis=1)
         f1 = get_aggregate_evaluation(
             self.labels,
             evaluate_prediction("{}-{}".format(self.method, t),
                                 self.labels, y_train, p),
         )
         if f1 > self.max_f1:
             self.max_f1 = f1
             self.threshold = t
     logging.debug(
         "training found an optimum f1 of {} with threshold {}".format(
             self.max_f1, self.threshold))