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


Python GaussianKernel.init方法代码示例

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


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

示例1: kernel_io_modular

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

# 需要导入模块: from shogun.Kernel import GaussianKernel [as 别名]
# 或者: from shogun.Kernel.GaussianKernel import init [as 别名]
def classify(classifier, features, labels, C=5, kernel_name=None, kernel_args=None):
    from shogun.Features import RealFeatures
    sigma = 10000
    kernel = GaussianKernel(features, features, sigma)
    # TODO
    # kernel = LinearKernel(features, features)
    # kernel = PolyKernel(features, features, 50, 2)
    # kernel = kernels[kernel_name](features, features, *kernel_args)

    svm = classifier(C, kernel, labels)
    svm.train(features)
    x_size = 640
    y_size = 400
    size = 100
    x1 = np.linspace(0, x_size, size)
    y1 = np.linspace(0, y_size, size)
    x, y = np.meshgrid(x1, y1)

    test = RealFeatures(np.array((np.ravel(x), np.ravel(y))))
    kernel.init(features, test)

    out = svm.apply(test).get_values()
    if not len(out):
        out = svm.apply(test).get_labels()
    z = out.reshape((size, size))
    z = np.transpose(z)

    return x, y, z
开发者ID:dvalcarce,项目名称:shogun-gsoc,代码行数:30,代码来源:svm.py

示例3: statistics_kmm

# 需要导入模块: from shogun.Kernel import GaussianKernel [as 别名]
# 或者: from shogun.Kernel.GaussianKernel import init [as 别名]
def statistics_kmm (n,d):
	from shogun.Features import RealFeatures
	from shogun.Features import DataGenerator
	from shogun.Kernel import GaussianKernel, MSG_DEBUG
	from shogun.Statistics import KernelMeanMatching
	from shogun.Mathematics import Math

	# init seed for reproducability
	Math.init_random(1)
	random.seed(1);

	data = random.randn(d,n)

	# create shogun feature representation
	features=RealFeatures(data)

	# use a kernel width of sigma=2, which is 8 in SHOGUN's parametrization
	# which is k(x,y)=exp(-||x-y||^2 / tau), in constrast to the standard
	# k(x,y)=exp(-||x-y||^2 / (2*sigma^2)), so tau=2*sigma^2
	kernel=GaussianKernel(10,8)
	kernel.init(features,features)

	kmm = KernelMeanMatching(kernel,array([0,1,2,3,7,8,9],dtype=int32),array([4,5,6],dtype=int32))
	w = kmm.compute_weights()
	#print w
	return w
开发者ID:Argram,项目名称:shogun,代码行数:28,代码来源:statistics_kmm.py

示例4: mlprocess

# 需要导入模块: from shogun.Kernel import GaussianKernel [as 别名]
# 或者: from shogun.Kernel.GaussianKernel import init [as 别名]
def mlprocess(task_filename, data_filename, pred_filename, verbose=True):
    """Demo of creating machine learning process."""
    task_type, fidx, lidx, train_idx, test_idx = parse_task(task_filename)
    outputs = init_output(task_type)
    all_data = parse_data(data_filename)
    train_ex, train_lab, test_ex, test_lab = split_data(all_data, fidx, lidx, train_idx, test_idx)
    label_train = outputs.str2label(train_lab)

    if verbose:
        print 'Number of features: %d' % train_ex.shape[0]
        print '%d training examples, %d test examples' % (len(train_lab), len(test_lab))

    feats_train = RealFeatures(train_ex)
    feats_test = RealFeatures(test_ex)
    width=1.0
    kernel=GaussianKernel(feats_train, feats_train, width)
    labels=Labels(label_train)
    svm = init_svm(task_type, kernel, labels)
    svm.train()

    kernel.init(feats_train, feats_test)
    preds = svm.classify().get_labels()
    pred_label = outputs.label2str(preds)

    pf = open(pred_filename, 'w')
    for pred in pred_label:
        pf.write(pred+'\n')
    pf.close()
开发者ID:jbeltram,项目名称:mldata-utils,代码行数:30,代码来源:mlprocess.py

示例5: regression_svrlight_modular

# 需要导入模块: from shogun.Kernel import GaussianKernel [as 别名]
# 或者: from shogun.Kernel.GaussianKernel import init [as 别名]
def regression_svrlight_modular(fm_train=traindat,fm_test=testdat,label_train=label_traindat, \
				    width=1.2,C=1,epsilon=1e-5,tube_epsilon=1e-2,num_threads=3):


	from shogun.Features import Labels, RealFeatures
	from shogun.Kernel import GaussianKernel
	try:
		from shogun.Regression import SVRLight
	except ImportError:
		print('No support for SVRLight available.')
		return

	feats_train=RealFeatures(fm_train)
	feats_test=RealFeatures(fm_test)

	kernel=GaussianKernel(feats_train, feats_train, width)

	labels=Labels(label_train)

	svr=SVRLight(C, epsilon, kernel, labels)
	svr.set_tube_epsilon(tube_epsilon)
	svr.parallel.set_num_threads(num_threads)
	svr.train()

	kernel.init(feats_train, feats_test)
	out = svr.apply().get_labels()
	
	return out, kernel 
开发者ID:harshitsyal,项目名称:shogun,代码行数:30,代码来源:regression_svrlight_modular.py

示例6: mkl_binclass_modular

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

示例7: kernel_gaussian_modular

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

示例8: gaussian

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

示例9: classifier_libsvm_minimal_modular

# 需要导入模块: from shogun.Kernel import GaussianKernel [as 别名]
# 或者: from shogun.Kernel.GaussianKernel import init [as 别名]
def classifier_libsvm_minimal_modular (fm_train_real=traindat,fm_test_real=testdat,label_train_twoclass=label_traindat,width=2.1,C=1):
	from shogun.Features import RealFeatures, BinaryLabels
	from shogun.Classifier import LibSVM
	from shogun.Kernel import GaussianKernel

	feats_train=RealFeatures(fm_train_real);
	feats_test=RealFeatures(fm_test_real);
	kernel=GaussianKernel(feats_train, feats_train, width);

	labels=BinaryLabels(label_train_twoclass);
	svm=LibSVM(C, kernel, labels);
	svm.train();

	kernel.init(feats_train, feats_test);
	out=svm.apply().get_labels();
	testerr=mean(sign(out)!=label_train_twoclass)
开发者ID:Argram,项目名称:shogun,代码行数:18,代码来源:classifier_libsvm_minimal_modular.py

示例10: classifier_libsvmoneclass_modular

# 需要导入模块: from shogun.Kernel import GaussianKernel [as 别名]
# 或者: from shogun.Kernel.GaussianKernel import init [as 别名]
def classifier_libsvmoneclass_modular (fm_train_real=traindat,fm_test_real=testdat,width=2.1,C=1,epsilon=1e-5):
	from shogun.Features import RealFeatures, Labels
	from shogun.Kernel import GaussianKernel
	from shogun.Classifier import LibSVMOneClass

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

	kernel=GaussianKernel(feats_train, feats_train, width)

	svm=LibSVMOneClass(C, kernel)
	svm.set_epsilon(epsilon)
	svm.train()

	kernel.init(feats_train, feats_test)
	svm.apply().get_labels()

	predictions = svm.apply()
	return predictions, svm, predictions.get_labels()
开发者ID:Anshul-Bansal,项目名称:gsoc,代码行数:21,代码来源:classifier_libsvmoneclass_modular.py

示例11: classifier_multiclassmachine_modular

# 需要导入模块: from shogun.Kernel import GaussianKernel [as 别名]
# 或者: from shogun.Kernel.GaussianKernel import init [as 别名]
def classifier_multiclassmachine_modular (fm_train_real=traindat,fm_test_real=testdat,label_train_multiclass=label_traindat,width=2.1,C=1,epsilon=1e-5):
	from shogun.Features import RealFeatures, Labels
	from shogun.Kernel import GaussianKernel
	from shogun.Classifier import LibSVM, KernelMulticlassMachine, ONE_VS_REST_STRATEGY

	feats_train=RealFeatures(fm_train_real)
	feats_test=RealFeatures(fm_test_real)
	kernel=GaussianKernel(feats_train, feats_train, width)

	labels=Labels(label_train_multiclass)

	classifier = LibSVM(C, kernel, labels)
	classifier.set_epsilon(epsilon)
	mc_classifier = KernelMulticlassMachine(ONE_VS_REST_STRATEGY,kernel,classifier,labels)
	mc_classifier.train()

	kernel.init(feats_train, feats_test)
	out = mc_classifier.apply().get_labels()
	return out
开发者ID:ashish-sadh,项目名称:shogun,代码行数:21,代码来源:classifier_multiclassmachine_modular.py

示例12: regression_kernel_ridge_modular

# 需要导入模块: from shogun.Kernel import GaussianKernel [as 别名]
# 或者: from shogun.Kernel.GaussianKernel import init [as 别名]
def regression_kernel_ridge_modular (fm_train=traindat,fm_test=testdat,label_train=label_traindat,width=0.8,tau=1e-6):

	from shogun.Features import Labels, RealFeatures
	from shogun.Kernel import GaussianKernel
	from shogun.Regression import KernelRidgeRegression

	feats_train=RealFeatures(fm_train)
	feats_test=RealFeatures(fm_test)

	kernel=GaussianKernel(feats_train, feats_train, width)

	labels=Labels(label_train)

	krr=KernelRidgeRegression(tau, kernel, labels)
	krr.train(feats_train)

	kernel.init(feats_train, feats_test)
	out = krr.apply().get_labels()
	return out,kernel,krr
开发者ID:harshitsyal,项目名称:shogun,代码行数:21,代码来源:regression_kernel_ridge_modular.py

示例13: classifier_multiclasslibsvm_modular

# 需要导入模块: from shogun.Kernel import GaussianKernel [as 别名]
# 或者: from shogun.Kernel.GaussianKernel import init [as 别名]
def classifier_multiclasslibsvm_modular (fm_train_real=traindat,fm_test_real=testdat,label_train_multiclass=label_traindat,width=2.1,C=1,epsilon=1e-5):
	from shogun.Features import RealFeatures, Labels
	from shogun.Kernel import GaussianKernel
	from shogun.Classifier import MulticlassLibSVM

	feats_train=RealFeatures(fm_train_real)
	feats_test=RealFeatures(fm_test_real)
	kernel=GaussianKernel(feats_train, feats_train, width)

	labels=Labels(label_train_multiclass)

	svm=MulticlassLibSVM(C, kernel, labels)
	svm.set_epsilon(epsilon)
	svm.train()

	kernel.init(feats_train, feats_test)
	out = svm.apply().get_labels()
	predictions = svm.apply()
	return predictions, svm, predictions.get_labels()
开发者ID:serialhex,项目名称:shogun,代码行数:21,代码来源:classifier_multiclasslibsvm_modular.py

示例14: classifier_gmnpsvm_modular

# 需要导入模块: from shogun.Kernel import GaussianKernel [as 别名]
# 或者: from shogun.Kernel.GaussianKernel import init [as 别名]
def classifier_gmnpsvm_modular (fm_train_real=traindat,fm_test_real=testdat,label_train_multiclass=label_traindat,width=2.1,C=1,epsilon=1e-5):

	from shogun.Features import RealFeatures, MulticlassLabels
	from shogun.Kernel import GaussianKernel
	from shogun.Classifier import GMNPSVM

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

	kernel=GaussianKernel(feats_train, feats_train, width)

	labels=MulticlassLabels(label_train_multiclass)

	svm=GMNPSVM(C, kernel, labels)
	svm.set_epsilon(epsilon)
	svm.train(feats_train)
	kernel.init(feats_train, feats_test)
	out=svm.apply(feats_test).get_labels()
	return out,kernel
开发者ID:behollis,项目名称:muViewBranch,代码行数:21,代码来源:classifier_gmnpsvm_modular.py

示例15: regression_libsvr_modular

# 需要导入模块: from shogun.Kernel import GaussianKernel [as 别名]
# 或者: from shogun.Kernel.GaussianKernel import init [as 别名]
def regression_libsvr_modular (svm_c=1, svr_param=0.1, n=100,n_test=100, \
		x_range=6,x_range_test=10,noise_var=0.5,width=1, seed=1):

	from shogun.Features import RegressionLabels, RealFeatures
	from shogun.Kernel import GaussianKernel
	from shogun.Regression import LibSVR, LIBSVR_NU_SVR, LIBSVR_EPSILON_SVR

	# reproducable results
	random.seed(seed)
	
	# easy regression data: one dimensional noisy sine wave
	n=15
	n_test=100
	x_range_test=10
	noise_var=0.5;
	X=random.rand(1,n)*x_range
	
	X_test=array([[float(i)/n_test*x_range_test for i in range(n_test)]])
	Y_test=sin(X_test)
	Y=sin(X)+random.randn(n)*noise_var
	
	# shogun representation
	labels=RegressionLabels(Y[0])
	feats_train=RealFeatures(X)
	feats_test=RealFeatures(X_test)

	kernel=GaussianKernel(feats_train, feats_train, width)
	
	# two svr models: epsilon and nu
	svr_epsilon=LibSVR(svm_c, svr_param, kernel, labels, LIBSVR_EPSILON_SVR)
	svr_epsilon.train()
	svr_nu=LibSVR(svm_c, svr_param, kernel, labels, LIBSVR_NU_SVR)
	svr_nu.train()

	# predictions
	kernel.init(feats_train, feats_test)
	out1_epsilon=svr_epsilon.apply().get_labels()
	out2_epsilon=svr_epsilon.apply(feats_test).get_labels()
	out1_nu=svr_epsilon.apply().get_labels()
	out2_nu=svr_epsilon.apply(feats_test).get_labels()

	return out1_epsilon,out2_epsilon,out1_nu,out2_nu ,kernel
开发者ID:Argram,项目名称:shogun,代码行数:44,代码来源:regression_libsvr_modular.py


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