コード例 #1
0
def mensure(sent):

    results = []
    acuracias = []
    logs = []
    nv_roc = Roc()
    svm_roc = Roc()
    dt_roc = Roc()
    rf_roc = Roc()
    gd_roc = Roc()
    rl_roc = Roc()
    cm_roc = Roc()
    fpr = []
    tpr = []
    auc = []

    custos = pd.DataFrame()

    start = time.time()
    nv_acc, nv_ac, nv_p, nv_r, nv_f1, nv_e, nv_cm, nv_roc = sent.CMultinomialNV(
    )
    end = time.time()
    custos['nv'] = [end - start]
    print('Naive')
    print('ac = %f' % nv_acc)
    print('p = %f' % nv_p)
    print('r = %f' % nv_r)
    print('f1 = %f' % nv_f1)
    print('e = %f' % nv_e)
    print("time %f" % (end - start))
    print('---------------')

    sent.plot_confuse_matrix(nv_cm, 'Matriz de Confusao - Naive Bayes',
                             'matriz-nv')

    l = 'nv', nv_acc, nv_p, nv_r, nv_f1, nv_e, str(dt.now())
    logs.append(l)
    fpr.append(nv_roc.get_fpr())
    tpr.append(nv_roc.get_tpr())
    auc.append(nv_roc.get_auc())

    start = time.time()
    sgd_acc, sgd_ac, sgd_p, sgd_r, sgd_f1, sgd_e, sgd_cm, sgd_roc = sent.gradienteDesc(
    )
    end = time.time()
    custos['sgd'] = [end - start]
    print('Gradiente')
    print('ac = %f' % sgd_acc)
    print('p = %f' % sgd_p)
    print('r = %f' % sgd_r)
    print('f1 = %f' % sgd_f1)
    print('e = %f' % sgd_e)
    print("time %f" % (end - start))
    print('---------------')

    sent.plot_confuse_matrix(sgd_cm, 'Matriz de Confusao - SGD', 'matriz-sgd')

    l = 'sgd', sgd_acc, sgd_p, sgd_r, sgd_f1, sgd_e, str(dt.now())
    logs.append(l)

    fpr.append(sgd_roc.get_fpr())
    tpr.append(sgd_roc.get_tpr())
    auc.append(sgd_roc.get_auc())

    results.append(sgd_ac)
    results.append(nv_ac)

    sent.write_csv(custos, 'Result/tempo-exe')

    sent.write_csv(logs, 'Result/metricas')

    label = ['sgd', 'naive']

    sent.plot_roc_all(fpr, tpr, auc, label)
コード例 #2
0
    acuracias = []

    nv_ac, _, nv_p, nv_r, nv_f1, nv_e, nv_cm, nv_roc = sent.CMultinomialNV()

    print("Naive")
    print('ac = %f' % nv_ac)
    print('p = %f' % nv_p)
    print('r = %f' % nv_r)
    print('f1 = %f' % nv_f1)
    print('e = %f' % nv_e)
    print('---------------')

    acuracias.append(nv_ac)
    fpr.append(nv_roc.get_fpr())
    tpr.append(nv_roc.get_tpr())
    auc.append(nv_roc.get_auc())

    #sent.plot_confuse_matrix(nv_cm)

    svm_ac, _, svm_p, svm_r, svm_f1, svm_e, svm_cm, svm_roc = sent.CSuportVectorMachine(
    )

    print("SVM")
    print('ac = %f' % svm_ac)
    print('p = %f' % svm_p)
    print('r = %f' % svm_r)
    print('f1 = %f' % svm_f1)
    print('e = %f' % svm_e)
    print('---------------')

    acuracias.append(svm_ac)