本文整理匯總了Python中joblib.Parallel.argmax方法的典型用法代碼示例。如果您正苦於以下問題:Python Parallel.argmax方法的具體用法?Python Parallel.argmax怎麽用?Python Parallel.argmax使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類joblib.Parallel
的用法示例。
在下文中一共展示了Parallel.argmax方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: svm_ova_from_kernel
# 需要導入模塊: from joblib import Parallel [as 別名]
# 或者: from joblib.Parallel import argmax [as 別名]
def svm_ova_from_kernel(ktrain, train_labels,
ktest, test_labels,
C=DEFAULT_REGULARIZATION,
bkg_categories=None):
def sighandler_svm(signum, frame):
logger.info('Caught signal %i while training SVMs in paralell.'
% signum)
signal.signal(signal.SIGTERM, sighandler_svm)
n_test = ktest.shape[0]
categories = np.unique(train_labels)
# -- remove background categories
if bkg_categories is not None:
categories = list(set(categories).difference(set(bkg_categories)))
n_categories = len(categories)
cat_index = {}
predictions = np.empty((n_test, n_categories))
# -- train OVA SVMs in parallel
predictions = Parallel(n_jobs=-1) (delayed(one_svm) (ktrain,
train_labels.reshape(-1),
ktest,
cat, C)
for cat in categories)
predictions = np.array(predictions).T
# -- iterates over categories
for icat, cat in enumerate(categories):
cat_index[cat] = icat
gt = np.array([cat_index[e]
for e in test_labels.reshape(-1)]).astype('int')
pred = predictions.argmax(axis=1)
acc = (pred == gt).sum() / float(n_test)
return acc, predictions, gt