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


Python LibSVM.get_objective方法代碼示例

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


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

示例1: xrange

# 需要導入模塊: from shogun.Classifier import LibSVM [as 別名]
# 或者: from shogun.Classifier.LibSVM import get_objective [as 別名]
km = wdk.get_kernel_matrix()

for i in xrange(N):
    for j in xrange(N):
        km[i,j] = km[i,j]*relate_tasks(i,j)
        #km = km*1.0

print km
#precompute kernel matrix using shogun
y = numpy.array(labels)
K = numpy.transpose(y.flatten() * (km*y.flatten()).transpose())
f = -numpy.ones(N)
C = 1.0

# Important!! QP does not accept ndarray as a type, it must be an array
p = QP(K, f, Aeq=y, beq=0, lb=numpy.zeros(N), ub=C*numpy.ones(N))
r = p.solve('cvxopt_qp', iprint = 0)

#print "cvxopt objective:", r.ff
print "externally modified kernel. objective:", r.ff

ck = CustomKernel()
ck.set_full_kernel_matrix_from_full(km)
#
svm = LibSVM(1, ck, lab)
svm.train()

print "externally modified kernel. objective:", svm.get_objective()


開發者ID:cwidmer,項目名稱:multitask,代碼行數:30,代碼來源:debug_multitask_kernel_bias.py

示例2: StringCharFeatures

# 需要導入模塊: from shogun.Classifier import LibSVM [as 別名]
# 或者: from shogun.Classifier.LibSVM import get_objective [as 別名]

feat_presvm = StringCharFeatures(DNA)
feat_presvm.set_features(examples_presvm)
wdk_presvm = WeightedDegreeStringKernel(feat_presvm, feat_presvm, 1)
lab_presvm = Labels(numpy.array(labels_presvm))


presvm = SVMLight(1, wdk_presvm, lab_presvm)
presvm.train()

presvm2 = LibSVM(1, wdk_presvm, lab_presvm)
presvm2.train()

print "svmlight", presvm.get_objective()
print "libsvm", presvm2.get_objective()

assert(abs(presvm.get_objective() - presvm2.get_objective())<= 0.001)

print "simple svm", presvm.get_objective()

print "len(examples_presvm)", len(examples_presvm)

print "##############"


#############################################
#    compute linear term manually
#############################################

examples = [i.example for i in d[subset_size:subset_size*2]]
開發者ID:cwidmer,項目名稱:multitask,代碼行數:32,代碼來源:debug_shogun_dasvm.py


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