예제 #1
0
def accuracy(train, test):
    turn = 4
    entityScoreSum = 0
    emotionScoreSum = 0
    for i in range(turn):
        # 切分数据
        data_split('../coreEntityEmotion_baseline/data',
                   'coreEntityEmotion_train.txt')
        # 训练
        train.train_ents()
        # 测试
        test.test()
        # 计算F1
        entityScore, emotionScore = computeF1Score(
            '../coreEntityEmotion_baseline/data/coreEntityEmotion_train.txt',
            'result/result_lgb.txt')
        print('turn:', i + 1, 'lgb:', 'entityScore:', entityScore,
              'emotionScore:', emotionScore)
        entityScore, emotionScore = computeF1Score(
            '../coreEntityEmotion_baseline/data/coreEntityEmotion_train.txt',
            'result/result_xgb.txt')
        print('turn:', i + 1, 'xgb:', 'entityScore:', entityScore,
              'emotionScore:', emotionScore)
        # 统计F1
        entityScoreSum += entityScore
        emotionScoreSum += emotionScore
    # 输出平均值
    print('平均entityScore:', entityScoreSum / turn, '平均emotionScore:',
          emotionScoreSum / turn)
    return entityScoreSum / turn, emotionScoreSum / turn
예제 #2
0
def accuracy(test, input_param=None):
    turn = 5
    entityScoreSum = 0
    emotionScoreSum = 0
    for i in range(turn):
        # 切分数据
        data_split('../coreEntityEmotion_baseline/data',
                   'coreEntityEmotion_train.txt')

        # 测试
        test.testCoreEntity(
            '../coreEntityEmotion_baseline/data/2_coreEntityEmotion_train.txt',
            '../coreEntityEmotion_baseline/data/2_coreEntityEmotion_train_result.txt',
            param=input_param)
        # 计算F1
        entityScore, emotionScore = computeF1Score(
            '../coreEntityEmotion_baseline/data/coreEntityEmotion_train.txt',
            '../coreEntityEmotion_baseline/data/2_coreEntityEmotion_train_result.txt'
        )
        print('turn:', i + 1, 'entityScore:', entityScore, 'emotionScore:',
              emotionScore)
        # 统计F1
        entityScoreSum += entityScore
        emotionScoreSum += emotionScore
    # 输出平均值
    print('平均entityScore:', entityScoreSum / turn, '平均emotionScore:',
          emotionScoreSum / turn)
    return entityScoreSum / turn, emotionScoreSum / turn
예제 #3
0
if __name__ == '__main__':
    from time import time

    start = time()
    test = Test()
    turn = 5
    entityScoreSum = 0
    emotionScoreSum = 0
    for i in range(turn):
        # 切分数据
        data_split('../coreEntityEmotion_baseline/data', 'coreEntityEmotion_train.txt')
        # 训练
        # trainer = Train()
        # trainer.trainCoreEntity()
        # trainer.trainEmotion()
        # 测试
        test.testCoreEntity('../coreEntityEmotion_baseline/data/2_coreEntityEmotion_train.txt',
                            '../coreEntityEmotion_baseline/data/2_coreEntityEmotion_train_result.txt')
        # 计算F1
        entityScore, emotionScore = computeF1Score('../coreEntityEmotion_baseline/data/coreEntityEmotion_train.txt',
                                                   '../coreEntityEmotion_baseline/data/2_coreEntityEmotion_train_result.txt')
        print('turn:', i + 1, 'entityScore:', entityScore, 'emotionScore:', emotionScore)
        # 统计F1
        entityScoreSum += entityScore
        emotionScoreSum += emotionScore
    # 输出平均值
    print('平均entityScore:', entityScoreSum / turn, '平均emotionScore:', emotionScoreSum / turn)

    print('end:', time() - start)