當前位置: 首頁>>代碼示例>>Python>>正文


Python metrics.hamming_loss方法代碼示例

本文整理匯總了Python中sklearn.metrics.hamming_loss方法的典型用法代碼示例。如果您正苦於以下問題:Python metrics.hamming_loss方法的具體用法?Python metrics.hamming_loss怎麽用?Python metrics.hamming_loss使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在sklearn.metrics的用法示例。


在下文中一共展示了metrics.hamming_loss方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: multi_class_classification

# 需要導入模塊: from sklearn import metrics [as 別名]
# 或者: from sklearn.metrics import hamming_loss [as 別名]
def multi_class_classification(data_X,data_Y):
    '''
    calculate multi-class classification and return related evaluation metrics
    '''

    svc = svm.SVC(C=1, kernel='linear')
    # X_train, X_test, y_train, y_test = train_test_split( data_X, data_Y, test_size=0.4, random_state=0) 
    clf = svc.fit(data_X, data_Y) #svm
    # array = svc.coef_
    # print array
    predicted = cross_val_predict(clf, data_X, data_Y, cv=2)
    print "accuracy",metrics.accuracy_score(data_Y, predicted)
    print "f1 score macro",metrics.f1_score(data_Y, predicted, average='macro') 
    print "f1 score micro",metrics.f1_score(data_Y, predicted, average='micro') 
    print "precision score",metrics.precision_score(data_Y, predicted, average='macro') 
    print "recall score",metrics.recall_score(data_Y, predicted, average='macro') 
    print "hamming_loss",metrics.hamming_loss(data_Y, predicted)
    print "classification_report", metrics.classification_report(data_Y, predicted)
    print "jaccard_similarity_score", metrics.jaccard_similarity_score(data_Y, predicted)
    # print "log_loss", metrics.log_loss(data_Y, predicted)
    print "zero_one_loss", metrics.zero_one_loss(data_Y, predicted)
    # print "AUC&ROC",metrics.roc_auc_score(data_Y, predicted)
    # print "matthews_corrcoef", metrics.matthews_corrcoef(data_Y, predicted) 
開發者ID:RoyZhengGao,項目名稱:edge2vec,代碼行數:25,代碼來源:multi_class_classification.py

示例2: evaluation_analysis

# 需要導入模塊: from sklearn import metrics [as 別名]
# 或者: from sklearn.metrics import hamming_loss [as 別名]
def evaluation_analysis(true_label,predicted): 
    '''
    return all metrics results
    '''
    print "accuracy",metrics.accuracy_score(true_label, predicted)
    print "f1 score macro",metrics.f1_score(true_label, predicted, average='macro')     
    print "f1 score micro",metrics.f1_score(true_label, predicted, average='micro') 
    print "precision score",metrics.precision_score(true_label, predicted, average='macro') 
    print "recall score",metrics.recall_score(true_label, predicted, average='macro') 
    print "hamming_loss",metrics.hamming_loss(true_label, predicted)
    print "classification_report", metrics.classification_report(true_label, predicted)
    print "jaccard_similarity_score", metrics.jaccard_similarity_score(true_label, predicted)
    print "log_loss", metrics.log_loss(true_label, predicted)
    print "zero_one_loss", metrics.zero_one_loss(true_label, predicted)
    print "AUC&ROC",metrics.roc_auc_score(true_label, predicted)
    print "matthews_corrcoef", metrics.matthews_corrcoef(true_label, predicted) 
開發者ID:RoyZhengGao,項目名稱:edge2vec,代碼行數:18,代碼來源:link_prediction.py

示例3: test_multilabel_hamming_loss

# 需要導入模塊: from sklearn import metrics [as 別名]
# 或者: from sklearn.metrics import hamming_loss [as 別名]
def test_multilabel_hamming_loss():
    # Dense label indicator matrix format
    y1 = np.array([[0, 1, 1], [1, 0, 1]])
    y2 = np.array([[0, 0, 1], [1, 0, 1]])
    w = np.array([1, 3])

    assert_equal(hamming_loss(y1, y2), 1 / 6)
    assert_equal(hamming_loss(y1, y1), 0)
    assert_equal(hamming_loss(y2, y2), 0)
    assert_equal(hamming_loss(y2, 1 - y2), 1)
    assert_equal(hamming_loss(y1, 1 - y1), 1)
    assert_equal(hamming_loss(y1, np.zeros(y1.shape)), 4 / 6)
    assert_equal(hamming_loss(y2, np.zeros(y1.shape)), 0.5)
    assert_equal(hamming_loss(y1, y2, sample_weight=w), 1. / 12)
    assert_equal(hamming_loss(y1, 1-y2, sample_weight=w), 11. / 12)
    assert_equal(hamming_loss(y1, np.zeros_like(y1), sample_weight=w), 2. / 3)
    # sp_hamming only works with 1-D arrays
    assert_equal(hamming_loss(y1[0], y2[0]), sp_hamming(y1[0], y2[0]))
    assert_warns_message(DeprecationWarning,
                         "The labels parameter is unused. It was"
                         " deprecated in version 0.21 and"
                         " will be removed in version 0.23",
                         hamming_loss, y1, y2, labels=[0, 1]) 
開發者ID:PacktPublishing,項目名稱:Mastering-Elasticsearch-7.0,代碼行數:25,代碼來源:test_classification.py

示例4: val_fn_epoch

# 需要導入模塊: from sklearn import metrics [as 別名]
# 或者: from sklearn.metrics import hamming_loss [as 別名]
def val_fn_epoch(classn, val_fn, X_val, a_val, y_val):
    val_err = 0;
    Pr = np.empty(shape = (10000, classn), dtype = np.int32);
    Or = np.empty(shape = (10000, classn), dtype = np.float32);
    Tr = np.empty(shape = (10000, classn), dtype = np.int32);
    val_batches = 0;
    nline = 0;
    for batch in iterate_minibatches(X_val, a_val, y_val, BatchSize, shuffle = False):
        inputs, augs, targets = batch;
        err, output = multi_win_during_val(val_fn, inputs, augs, targets);
        pred = from_output_to_pred(output);
        val_err += err;
        Pr[nline:nline+len(output)] = pred;
        Or[nline:nline+len(output)] = output;
        Tr[nline:nline+len(output)] = targets;
        val_batches += 1;
        nline += len(output);
    Pr = Pr[:nline];
    Or = Or[:nline];
    Tr = Tr[:nline];
    val_err = val_err / val_batches;
    val_ham = (1 - hamming_loss(Tr, Pr));
    val_acc = accuracy_score(Tr, Pr);
    return val_err, val_ham, val_acc, Pr, Or, Tr; 
開發者ID:SBU-BMI,項目名稱:u24_lymphocyte,代碼行數:26,代碼來源:deep_conv_classification_alt48_luad10_skcm10.py

示例5: val_fn_epoch

# 需要導入模塊: from sklearn import metrics [as 別名]
# 或者: from sklearn.metrics import hamming_loss [as 別名]
def val_fn_epoch(classn, val_fn, X_val, a_val, y_val):
    val_err = 0;
    Pr = np.empty(shape = (100000, classn), dtype = np.int32);
    Or = np.empty(shape = (100000, classn), dtype = np.float32);
    Tr = np.empty(shape = (100000, classn), dtype = np.int32);
    val_batches = 0;
    nline = 0;
    for batch in iterate_minibatches(X_val, a_val, y_val, BatchSize, shuffle = False):
        inputs, augs, targets = batch;
        err, output = multi_win_during_val(val_fn, inputs, augs, targets);
        pred = from_output_to_pred(output);
        val_err += err;
        Pr[nline:nline+len(output)] = pred;
        Or[nline:nline+len(output)] = output;
        Tr[nline:nline+len(output)] = targets;
        val_batches += 1;
        nline += len(output);
    Pr = Pr[:nline];
    Or = Or[:nline];
    Tr = Tr[:nline];
    val_err = val_err / val_batches;
    val_ham = (1 - hamming_loss(Tr, Pr));
    val_acc = accuracy_score(Tr, Pr);
    return val_err, val_ham, val_acc, Pr, Or, Tr; 
開發者ID:SBU-BMI,項目名稱:u24_lymphocyte,代碼行數:26,代碼來源:deep_conv_classification_alt60.py

示例6: val_fn_epoch

# 需要導入模塊: from sklearn import metrics [as 別名]
# 或者: from sklearn.metrics import hamming_loss [as 別名]
def val_fn_epoch(classn, val_fn, X_val, y_val):
    val_err = 0;
    Pr = np.empty(shape = (100000, classn), dtype = np.int32);
    Or = np.empty(shape = (100000, classn), dtype = np.float32);
    Tr = np.empty(shape = (100000, classn), dtype = np.int32);
    val_batches = 0;
    nline = 0;
    for batch in iterate_minibatches(X_val, y_val, BatchSize, shuffle = False):
        inputs, targets = batch;
        err, output = multi_win_during_val(val_fn, inputs, targets);
        pred = from_output_to_pred(output);
        val_err += err;
        Pr[nline:nline+len(output)] = pred;
        Or[nline:nline+len(output)] = output;
        Tr[nline:nline+len(output)] = targets;
        val_batches += 1;
        nline += len(output);
    Pr = Pr[:nline];
    Or = Or[:nline];
    Tr = Tr[:nline];
    val_err = val_err / val_batches;
    val_ham = (1 - hamming_loss(Tr, Pr));
    val_acc = accuracy_score(Tr, Pr);
    return val_err, val_ham, val_acc, Pr, Or, Tr; 
開發者ID:SBU-BMI,項目名稱:u24_lymphocyte,代碼行數:26,代碼來源:deep_conv_classification_alt55.py

示例7: val_fn_epoch

# 需要導入模塊: from sklearn import metrics [as 別名]
# 或者: from sklearn.metrics import hamming_loss [as 別名]
def val_fn_epoch(classn, val_fn, X_val, a_val, y_val):
    val_err = 0;
    Pr = np.empty(shape = (1000000, classn), dtype = np.int32);
    Or = np.empty(shape = (1000000, classn), dtype = np.float32);
    Tr = np.empty(shape = (1000000, classn), dtype = np.int32);
    val_batches = 0;
    nline = 0;
    for batch in iterate_minibatches(X_val, a_val, y_val, BatchSize, shuffle = False):
        inputs, augs, targets = batch;
        err, output = multi_win_during_val(val_fn, inputs, augs, targets);
        pred = from_output_to_pred(output);
        val_err += err;
        Pr[nline:nline+len(output)] = pred;
        Or[nline:nline+len(output)] = output;
        Tr[nline:nline+len(output)] = targets;
        val_batches += 1;
        nline += len(output);
    Pr = Pr[:nline];
    Or = Or[:nline];
    Tr = Tr[:nline];
    val_err = val_err / val_batches;
    val_ham = (1 - hamming_loss(Tr, Pr));
    val_acc = accuracy_score(Tr, Pr);
    return val_err, val_ham, val_acc, Pr, Or, Tr; 
開發者ID:SBU-BMI,項目名稱:u24_lymphocyte,代碼行數:26,代碼來源:deep_conv_classification_alt48_adeno_t1_heatmap.py

示例8: val_fn_epoch

# 需要導入模塊: from sklearn import metrics [as 別名]
# 或者: from sklearn.metrics import hamming_loss [as 別名]
def val_fn_epoch(classn, val_fn, X_val, y_val):
    val_err = 0;
    Pr = np.empty(shape = (1000000, classn), dtype = np.int32);
    Or = np.empty(shape = (1000000, classn), dtype = np.float32);
    Tr = np.empty(shape = (1000000, classn), dtype = np.int32);
    val_batches = 0;
    nline = 0;
    for batch in iterate_minibatches(X_val, y_val, BatchSize, shuffle = False):
        inputs, targets = batch;
        err, output = multi_win_during_val(val_fn, inputs, targets);
        pred = from_output_to_pred(output);
        val_err += err;
        Pr[nline:nline+len(output)] = pred;
        Or[nline:nline+len(output)] = output;
        Tr[nline:nline+len(output)] = targets;
        val_batches += 1;
        nline += len(output);
    Pr = Pr[:nline];
    Or = Or[:nline];
    Tr = Tr[:nline];
    val_err = val_err / val_batches;
    val_ham = (1 - hamming_loss(Tr, Pr));
    val_acc = accuracy_score(Tr, Pr);
    return val_err, val_ham, val_acc, Pr, Or, Tr; 
開發者ID:SBU-BMI,項目名稱:u24_lymphocyte,代碼行數:26,代碼來源:deep_conv_classification_alt51_luad10_luad10in20_brca10x1_heatmap.py

示例9: val_fn_epoch

# 需要導入模塊: from sklearn import metrics [as 別名]
# 或者: from sklearn.metrics import hamming_loss [as 別名]
def val_fn_epoch(classn, val_fn, X_val, a_val, y_val):
    val_err = 0;
    Pr = np.empty(shape = (100000, classn), dtype = np.int32);
    Or = np.empty(shape = (100000, classn), dtype = np.float32);
    Tr = np.empty(shape = (100000, classn), dtype = np.int32);
    val_batches = 0;
    nline = 0;
    for batch in iterate_minibatches(X_val, a_val, y_val, batchsize = 100, shuffle = False):
        inputs, augs, targets = batch;
        err, output = multi_win_during_val(val_fn, inputs, augs, targets);
        pred = from_output_to_pred(output);
        val_err += err;
        Pr[nline:nline+len(output)] = pred;
        Or[nline:nline+len(output)] = output;
        Tr[nline:nline+len(output)] = targets;
        val_batches += 1;
        nline += len(output);
    Pr = Pr[:nline];
    Or = Or[:nline];
    Tr = Tr[:nline];
    val_err = val_err / val_batches;
    val_ham = (1 - hamming_loss(Tr, Pr));
    val_acc = accuracy_score(Tr, Pr);
    return val_err, val_ham, val_acc, Pr, Or, Tr; 
開發者ID:SBU-BMI,項目名稱:u24_lymphocyte,代碼行數:26,代碼來源:deep_conv_classification_alt34.py


注:本文中的sklearn.metrics.hamming_loss方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。