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