本文整理汇总了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