本文整理汇总了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)
示例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)
示例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])
示例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;
示例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;
示例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;
示例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;
示例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;