本文整理汇总了Python中shogun.Classifier.SVMLight.set_linear_term方法的典型用法代码示例。如果您正苦于以下问题:Python SVMLight.set_linear_term方法的具体用法?Python SVMLight.set_linear_term怎么用?Python SVMLight.set_linear_term使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类shogun.Classifier.SVMLight
的用法示例。
在下文中一共展示了SVMLight.set_linear_term方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: classifier_svmlight_linear_term_modular
# 需要导入模块: from shogun.Classifier import SVMLight [as 别名]
# 或者: from shogun.Classifier.SVMLight import set_linear_term [as 别名]
def classifier_svmlight_linear_term_modular(fm_train_dna=traindna,fm_test_dna=testdna, \
label_train_dna=label_traindna,degree=3, \
C=10,epsilon=1e-5,num_threads=1):
from shogun.Features import StringCharFeatures, BinaryLabels, DNA
from shogun.Kernel import WeightedDegreeStringKernel
from shogun.Classifier import SVMLight
feats_train=StringCharFeatures(DNA)
feats_train.set_features(fm_train_dna)
feats_test=StringCharFeatures(DNA)
feats_test.set_features(fm_test_dna)
kernel=WeightedDegreeStringKernel(feats_train, feats_train, degree)
labels=BinaryLabels(label_train_dna)
svm=SVMLight(C, kernel, labels)
svm.set_qpsize(3)
svm.set_linear_term(-numpy.array([1,2,3,4,5,6,7,8,7,6], dtype=numpy.double));
svm.set_epsilon(epsilon)
svm.parallel.set_num_threads(num_threads)
svm.train()
kernel.init(feats_train, feats_test)
out = svm.apply().get_labels()
return out,kernel
示例2:
# 需要导入模块: from shogun.Classifier import SVMLight [as 别名]
# 或者: from shogun.Classifier.SVMLight import set_linear_term [as 别名]
print 'SVMLight'
from shogun.Features import StringCharFeatures, Labels, DNA
from shogun.Kernel import WeightedDegreeStringKernel
from shogun.Classifier import SVMLight
feats_train=StringCharFeatures(DNA)
feats_train.set_features(fm_train_dna)
feats_test=StringCharFeatures(DNA)
feats_test.set_features(fm_test_dna)
kernel=WeightedDegreeStringKernel(feats_train, feats_train, degree)
C=10
epsilon=1e-5
num_threads=1
labels=Labels(label_train_dna)
svm=SVMLight(C, kernel, labels)
svm.set_qpsize(3)
svm.set_linear_term(-numpy.array([1,2,3,4,5,6,7,8,7,6], dtype=numpy.double));
svm.set_epsilon(epsilon)
svm.parallel.set_num_threads(num_threads)
svm.train()
kernel.init(feats_train, feats_test)
out = svm.classify().get_labels()
示例3: xrange
# 需要导入模块: from shogun.Classifier import SVMLight [as 别名]
# 或者: from shogun.Classifier.SVMLight import set_linear_term [as 别名]
f = -numpy.ones(N)
for idx in xrange(10):
#f = (-numpy.ones(N)-2)*numpy.random.randn()
print "############################"
print "############################"
print ""
print "f:", f
print "\n"
svm.set_linear_term(numpy.double(f))
svm.train()
sv_idx = svm.get_support_vectors()
alphas = svm.get_alphas()
alphas_full = numpy.zeros(N)
alphas_full[sv_idx] = alphas
alphas_full = alphas_full * y
print "svmlight objective:", svm.get_objective()
print "svmlight alphas:", numpy.array(alphas_full[0:5])
external_objective = 0.0
示例4: xrange
# 需要导入模块: from shogun.Classifier import SVMLight [as 别名]
# 或者: from shogun.Classifier.SVMLight import set_linear_term [as 别名]
p[idx] = B * tmp_lab[idx] * inner_sum - 1.0
################
#checking inner term
presvm.set_bias(0.0)
tmp_out = presvm.classify(feat).get_labels()
for i in xrange(len(examples)):
#print inner[i], tmp_out[i]
assert(abs(inner[i]-tmp_out[i])<= 0.001)
svm = SVMLight(1.0, wdk, lab)
svm.set_linear_term(p)
Math_init_random(1)
svm.train()
###############
#compare to LibSVM
svm2 = LibSVM(1.0, wdk, lab)
svm2.set_linear_term(p)
Math_init_random(1)
svm2.train()
svm3 = LibSVM(1.0, wdk, lab)
Math_init_random(1)