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


Python SVMLight.classify方法代码示例

本文整理汇总了Python中shogun.Classifier.SVMLight.classify方法的典型用法代码示例。如果您正苦于以下问题:Python SVMLight.classify方法的具体用法?Python SVMLight.classify怎么用?Python SVMLight.classify使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在shogun.Classifier.SVMLight的用法示例。


在下文中一共展示了SVMLight.classify方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: svm_light

# 需要导入模块: from shogun.Classifier import SVMLight [as 别名]
# 或者: from shogun.Classifier.SVMLight import classify [as 别名]
def svm_light ():
	print 'SVMLight'

	from shogun.Features import StringCharFeatures, Labels, DNA
	from shogun.Kernel import WeightedDegreeStringKernel
	try:
		from shogun.Classifier import SVMLight
	except ImportError:
		print 'No support for SVMLight available.'
		return

	feats_train=StringCharFeatures(DNA)
	feats_train.set_features(fm_train_dna)
	feats_test=StringCharFeatures(DNA)
	feats_test.set_features(fm_test_dna)
	degree=20

	kernel=WeightedDegreeStringKernel(feats_train, feats_train, degree)

	C=1.2
	epsilon=1e-5
	num_threads=1
	labels=Labels(label_train_dna)

	svm=SVMLight(C, kernel, labels)
	svm.set_epsilon(epsilon)
	svm.parallel.set_num_threads(num_threads)
	svm.train()

	kernel.init(feats_train, feats_test)
	svm.classify().get_labels()
开发者ID:memimo,项目名称:shogun-liblinear,代码行数:33,代码来源:classifier_svmlight_modular.py

示例2: classifier_svmlight_linear_term_modular

# 需要导入模块: from shogun.Classifier import SVMLight [as 别名]
# 或者: from shogun.Classifier.SVMLight import classify [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, 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)
    
    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()
    return out,kernel
开发者ID:AsherBond,项目名称:shogun,代码行数:29,代码来源:classifier_svmlight_linear_term_modular.py

示例3: do_batch_linadd

# 需要导入模块: from shogun.Classifier import SVMLight [as 别名]
# 或者: from shogun.Classifier.SVMLight import classify [as 别名]
def do_batch_linadd ():
	print 'SVMlight batch'

	from shogun.Features import StringCharFeatures, Labels, DNA
	from shogun.Kernel import WeightedDegreeStringKernel
	try:
		from shogun.Classifier import SVMLight
	except ImportError:
		print 'No support for SVMLight available.'
		return

	feats_train=StringCharFeatures(DNA)
	feats_train.set_features(fm_train_dna)
	feats_test=StringCharFeatures(DNA)
	feats_test.set_features(fm_test_dna)
	degree=20

	kernel=WeightedDegreeStringKernel(feats_train, feats_train, degree)

	C=1
	epsilon=1e-5
	num_threads=2
	labels=Labels(label_train_dna)

	svm=SVMLight(C, kernel, labels)
	svm.set_epsilon(epsilon)
	svm.parallel.set_num_threads(num_threads)
	svm.train()

	kernel.init(feats_train, feats_test)

	#print 'SVMLight Objective: %f num_sv: %d' % \
	#	(svm.get_objective(), svm.get_num_support_vectors())
	svm.set_batch_computation_enabled(False)
	svm.set_linadd_enabled(False)
	svm.classify().get_labels()

	svm.set_batch_computation_enabled(True)
	svm.classify().get_labels()
开发者ID:memimo,项目名称:shogun-liblinear,代码行数:41,代码来源:classifier_svmlight_batch_linadd_modular.py

示例4: classifier_svmlight_batch_linadd_modular

# 需要导入模块: from shogun.Classifier import SVMLight [as 别名]
# 或者: from shogun.Classifier.SVMLight import classify [as 别名]
def classifier_svmlight_batch_linadd_modular(fm_train_dna, fm_test_dna,
		label_train_dna, degree, C, epsilon, num_threads):

	from shogun.Features import StringCharFeatures, Labels, DNA
	from shogun.Kernel import WeightedDegreeStringKernel, MSG_DEBUG
	try:
		from shogun.Classifier import SVMLight
	except ImportError:
		print 'No support for SVMLight available.'
		return

	feats_train=StringCharFeatures(DNA)
	#feats_train.io.set_loglevel(MSG_DEBUG)
	feats_train.set_features(fm_train_dna)
	feats_test=StringCharFeatures(DNA)
	feats_test.set_features(fm_test_dna)
	degree=20

	kernel=WeightedDegreeStringKernel(feats_train, feats_train, degree)

	labels=Labels(label_train_dna)

	svm=SVMLight(C, kernel, labels)
	svm.set_epsilon(epsilon)
	svm.parallel.set_num_threads(num_threads)
	svm.train()

	kernel.init(feats_train, feats_test)

	#print 'SVMLight Objective: %f num_sv: %d' % \
	#	(svm.get_objective(), svm.get_num_support_vectors())
	svm.set_batch_computation_enabled(False)
	svm.set_linadd_enabled(False)
	svm.classify().get_labels()

	svm.set_batch_computation_enabled(True)
	labels = svm.classify().get_labels()
	return labels, svm
开发者ID:AsherBond,项目名称:shogun,代码行数:40,代码来源:classifier_svmlight_batch_linadd_modular.py

示例5:

# 需要导入模块: from shogun.Classifier import SVMLight [as 别名]
# 或者: from shogun.Classifier.SVMLight import classify [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

示例6: int

# 需要导入模块: from shogun.Classifier import SVMLight [as 别名]
# 或者: from shogun.Classifier.SVMLight import classify [as 别名]
        sv_id = int(old_svm.get_support_vectors()[j])
        alpha = old_svm.get_alpha(j)

        inner_sum = inner_sum + alpha * kv.kernel(sv_id, idx)
        
    inner.append(inner_sum)


    #general case
    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
开发者ID:cwidmer,项目名称:multitask,代码行数:32,代码来源:debug_shogun_dasvm.py


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