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


Python GaussianKernel.get_kernel_matrix方法代码示例

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


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

示例1: kernel_io_modular

# 需要导入模块: from shogun.Kernel import GaussianKernel [as 别名]
# 或者: from shogun.Kernel.GaussianKernel import get_kernel_matrix [as 别名]
def kernel_io_modular (fm_train_real=traindat,fm_test_real=testdat,width=1.9):
	from shogun.Features import RealFeatures
	from shogun.Kernel import GaussianKernel
	from shogun.Library import AsciiFile, BinaryFile
	
	feats_train=RealFeatures(fm_train_real)
	feats_test=RealFeatures(fm_test_real)


	kernel=GaussianKernel(feats_train, feats_train, width)
	km_train=kernel.get_kernel_matrix()
	f=AsciiFile("gaussian_train.ascii","w")
	kernel.save(f)
	del f

	kernel.init(feats_train, feats_test)
	km_test=kernel.get_kernel_matrix()
	f=AsciiFile("gaussian_test.ascii","w")
	kernel.save(f)
	del f

	#clean up
	import os
	os.unlink("gaussian_test.ascii")
	os.unlink("gaussian_train.ascii")
	
	return km_train, km_test, kernel
开发者ID:AsherBond,项目名称:shogun,代码行数:29,代码来源:kernel_io_modular.py

示例2: mkl_binclass_modular

# 需要导入模块: from shogun.Kernel import GaussianKernel [as 别名]
# 或者: from shogun.Kernel.GaussianKernel import get_kernel_matrix [as 别名]
def mkl_binclass_modular (train_data, testdata, train_labels, test_labels, d1, d2):
        # create some Gaussian train/test matrix
    	tfeats = RealFeatures(train_data)
    	tkernel = GaussianKernel(128, d1)
    	tkernel.init(tfeats, tfeats)
    	K_train = tkernel.get_kernel_matrix()

    	pfeats = RealFeatures(test_data)
    	tkernel.init(tfeats, pfeats)
    	K_test = tkernel.get_kernel_matrix()

    	# create combined train features
    	feats_train = CombinedFeatures()
    	feats_train.append_feature_obj(RealFeatures(train_data))

    	# and corresponding combined kernel
    	kernel = CombinedKernel()
    	kernel.append_kernel(CustomKernel(K_train))
    	kernel.append_kernel(GaussianKernel(128, d2))
    	kernel.init(feats_train, feats_train)

    	# train mkl
    	labels = Labels(train_labels)
    	mkl = MKLClassification()
	
        # not to use svmlight
        mkl.set_interleaved_optimization_enabled(0)

    	# which norm to use for MKL
    	mkl.set_mkl_norm(2)

    	# set cost (neg, pos)
    	mkl.set_C(1, 1)

    	# set kernel and labels
    	mkl.set_kernel(kernel)
    	mkl.set_labels(labels)

    	# train
    	mkl.train()

    	# test
	# create combined test features
    	feats_pred = CombinedFeatures()
    	feats_pred.append_feature_obj(RealFeatures(test_data))

    	# and corresponding combined kernel
    	kernel = CombinedKernel()
    	kernel.append_kernel(CustomKernel(K_test))
    	kernel.append_kernel(GaussianKernel(128, d2))
    	kernel.init(feats_train, feats_pred)

	# and classify
    	mkl.set_kernel(kernel)
    	output = mkl.apply().get_labels()
	output = [1.0 if i>0 else -1.0 for i in output]
	accu = len(where(output == test_labels)[0]) / float(len(output))
	return accu
开发者ID:leiding326,项目名称:data-science,代码行数:60,代码来源:mkl_binclass_modular.py

示例3: kernel_gaussian_modular

# 需要导入模块: from shogun.Kernel import GaussianKernel [as 别名]
# 或者: from shogun.Kernel.GaussianKernel import get_kernel_matrix [as 别名]
def kernel_gaussian_modular (fm_train_real=traindat,fm_test_real=testdat, width=1.3):
	from shogun.Features import RealFeatures
	from shogun.Kernel import GaussianKernel

	feats_train=RealFeatures(fm_train_real)
	feats_test=RealFeatures(fm_test_real)

	kernel=GaussianKernel(feats_train, feats_train, width)
	km_train=kernel.get_kernel_matrix()

	kernel.init(feats_train, feats_test)
	km_test=kernel.get_kernel_matrix()
	return km_train,km_test,kernel
开发者ID:coodoing,项目名称:shogun,代码行数:15,代码来源:kernel_gaussian_modular.py

示例4: gaussian

# 需要导入模块: from shogun.Kernel import GaussianKernel [as 别名]
# 或者: from shogun.Kernel.GaussianKernel import get_kernel_matrix [as 别名]
def gaussian ():
	print 'Gaussian'
	from shogun.Features import RealFeatures
	from shogun.Kernel import GaussianKernel

	feats_train=RealFeatures(fm_train_real)
	feats_test=RealFeatures(fm_test_real)
	width=1.9

	kernel=GaussianKernel(feats_train, feats_train, width)
	km_train=kernel.get_kernel_matrix()

	kernel.init(feats_train, feats_test)
	km_test=kernel.get_kernel_matrix()
开发者ID:memimo,项目名称:shogun-liblinear,代码行数:16,代码来源:kernel_gaussian_modular.py


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