当前位置: 首页>>代码示例>>Python>>正文


Python SVMLight.set_linear_term方法代码示例

本文整理汇总了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
开发者ID:coodoing,项目名称:shogun,代码行数:29,代码来源:classifier_svmlight_linear_term_modular.py

示例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()

开发者ID:polyactis,项目名称:test,代码行数:30,代码来源:classifier_svmlight_linear_term_modular.py

示例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
开发者ID:cwidmer,项目名称:multitask,代码行数:31,代码来源:debug_shogun_trunk.py

示例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)
开发者ID:cwidmer,项目名称:multitask,代码行数:33,代码来源:debug_shogun_dasvm.py


注:本文中的shogun.Classifier.SVMLight.set_linear_term方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。