def predict_sent(self, sent, with_prob=False):
if self.voting == 'hard':
# sub_res -> (estimator_dim, )
sub_res = np.array([estimator.predict_sent(sent) for estimator in self.estimators],
dtype=np.float32)
mode_res, count = mode(sub_res)
return (mode_res[0], count[0]/self.n_estimators) if with_prob else mode_res[0]
else:
# sub_res -> (estimator_dim, target_dim)
sub_res = np.array([estimator.predict_sent(sent, with_prob=True) for estimator in self.estimators],
dtype=np.float32)
sub_res = sub_res.mean(axis=0)
max_res = np.argmax(sub_res)
mean_prob = sub_res[max_res]
return (max_res, mean_prob) if with_prob else max_res
评论列表
文章目录