コード例 #1
0
def get_classification(feature, incr=False):
    """
    获得分类器
    :param feature:
    :param incr
    :return:
    """
    train_datas, class_label, _ = feature.get_key_words()

    train = train_datas
    # 构建适合 bayes 分类的数据集
    if not sp.issparse(train_datas):
        train = feature.cal_weight_improve(train_datas, class_label)

    if incr:
        bayes = IncrBayes()
    else:
        bayes = Bayes()
    clf = Classification(bayes=bayes, subjective=feature.subjective)
    clf.get_classificator(train, class_label)
    if incr:
        incr_train_datas = Load.load_incr_datas()
        incr_train, incr_class_label, _ = feature.get_key_words(incr_train_datas)
        # 构建适合 bayes 分类的增量集
        if not sp.issparse(incr_train):
            incr_train = feature.cal_weight_improve(incr_train, incr_class_label)

        clf.get_incr_classificator(incr_train, incr_class_label, train, class_label, method="five")
    return clf
コード例 #2
0
def get_classification(feature, incr=False):
    """
    获得分类器
    :param feature:
    :param incr
    :return:
    """
    train_datas, class_label, _ = feature.get_key_words()

    train = train_datas
    # 构建适合 bayes 分类的数据集
    if not sp.issparse(train_datas):
        train = feature.cal_weight_improve(train_datas, class_label)

    if incr:
        bayes = IncrBayes()
    else:
        bayes = Bayes()
    clf = Classification(bayes=bayes, subjective=feature.subjective)
    clf.get_classificator(train, class_label)
    if incr:
        incr_train_datas = Load.load_incr_datas()
        incr_train, incr_class_label, _ = feature.get_key_words(
            incr_train_datas)
        # 构建适合 bayes 分类的增量集
        if not sp.issparse(incr_train):
            incr_train = feature.cal_weight_improve(incr_train,
                                                    incr_class_label)

        clf.get_incr_classificator(incr_train,
                                   incr_class_label,
                                   train,
                                   class_label,
                                   method="five")
    return clf
コード例 #3
0
        out = os.path.join(TEXT_OUT, "best_train_test_index/test_index.txt")
        if not FileUtil.isexist(out) or FileUtil.isempty(out):
            clf0 = Classification()
            clf0.cross_validation(train, class_label, score="recall")
        test_index = np.loadtxt(out, dtype=int)
        test = train[test_index]
        test_label = np.asanyarray(class_label)[test_index].tolist()

    method_options = ("second", "four", "five")
    method_options_0 = ("B", "C", "D")
    linestyle = (':', '--', '-')
    plot.get_instance()
    for i in range(len(method_options)):
        bayes = IncrBayes()
        clf = Classification(bayes=bayes)
        clf.get_classificator(train, class_label, iscrossvalidate=crossvalidate,
                              isbalance=False, minority_target=EMOTION_CLASS.keys())
#        clf.get_classificator(train, class_label, isbalance=True, minority_target=["anger", "fear", "surprise"])
        if(i == 0):
            pred = clf.predict(test)
            pred_unknow = clf.predict_unknow(test)

            print "origin precision:", clf.metrics_precision(test_label, pred_unknow)
            print "origin recall:", clf.metrics_recall(test_label, pred_unknow)
            print "origin f1:", clf.metrics_f1(test_label, pred_unknow)
            print "origin accuracy:", clf.metrics_accuracy(test_label, pred_unknow)
            print "origin zero_one_loss:", clf.metrics_zero_one_loss(test_label, pred_unknow)
            test_proba = clf.predict_max_proba(test)
            print "origin my_zero_one_loss:", clf.metrics_my_zero_one_loss(test_proba)
            print
            clf.metrics_correct(test_label, pred_unknow)
#            plot.plot_roc(test_label, clf.predict_proba(test), classes=clf.bayes.classes_.tolist(), text='origin')