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


Python SparseRealFeatures.obtain_from_simple方法代码示例

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


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

示例1: classifier_svmlin_modular

# 需要导入模块: from shogun.Features import SparseRealFeatures [as 别名]
# 或者: from shogun.Features.SparseRealFeatures import obtain_from_simple [as 别名]
def classifier_svmlin_modular (fm_train_real=traindat,fm_test_real=testdat,label_train_twoclass=label_traindat,C=0.9,epsilon=1e-5,num_threads=1):
	from shogun.Features import RealFeatures, SparseRealFeatures, BinaryLabels
	from shogun.Classifier import SVMLin

	realfeat=RealFeatures(fm_train_real)
	feats_train=SparseRealFeatures()
	feats_train.obtain_from_simple(realfeat)
	realfeat=RealFeatures(fm_test_real)
	feats_test=SparseRealFeatures()
	feats_test.obtain_from_simple(realfeat)

	labels=BinaryLabels(label_train_twoclass)

	svm=SVMLin(C, feats_train, labels)
	svm.set_epsilon(epsilon)
	svm.parallel.set_num_threads(num_threads)
	svm.set_bias_enabled(True)
	svm.train()

	svm.set_features(feats_test)
	svm.get_bias()
	svm.get_w()
	svm.apply().get_labels()
	predictions = svm.apply()
	return predictions, svm, predictions.get_labels()
开发者ID:AlexBinder,项目名称:shogun,代码行数:27,代码来源:classifier_svmlin_modular.py

示例2: svmlin

# 需要导入模块: from shogun.Features import SparseRealFeatures [as 别名]
# 或者: from shogun.Features.SparseRealFeatures import obtain_from_simple [as 别名]
def svmlin ():
	print 'SVMLin'

	from shogun.Features import RealFeatures, SparseRealFeatures, Labels
	from shogun.Classifier import SVMLin

	realfeat=RealFeatures(fm_train_real)
	feats_train=SparseRealFeatures()
	feats_train.obtain_from_simple(realfeat)
	realfeat=RealFeatures(fm_test_real)
	feats_test=SparseRealFeatures()
	feats_test.obtain_from_simple(realfeat)

	C=0.9
	epsilon=1e-5
	num_threads=1
	labels=Labels(label_train_twoclass)

	svm=SVMLin(C, feats_train, labels)
	svm.set_epsilon(epsilon)
	svm.parallel.set_num_threads(num_threads)
	svm.set_bias_enabled(True)
	svm.train()

	svm.set_features(feats_test)
	svm.get_bias()
	svm.get_w()
	svm.classify().get_labels()
开发者ID:polyactis,项目名称:test,代码行数:30,代码来源:classifier_svmlin_modular.py

示例3: compute_output_plot_isolines

# 需要导入模块: from shogun.Features import SparseRealFeatures [as 别名]
# 或者: from shogun.Features.SparseRealFeatures import obtain_from_simple [as 别名]
def compute_output_plot_isolines(classifier, kernel=None, train=None, sparse=False, pos=None, neg=None, regression=False):
	size=100
	if pos is not None and neg is not None:
		x1_max=max(1.2*pos[0,:])
		x1_min=min(1.2*neg[0,:])
		x2_min=min(1.2*neg[1,:])
		x2_max=max(1.2*pos[1,:])
		x1=linspace(x1_min, x1_max, size)
		x2=linspace(x2_min, x2_max, size)
	else:
		x1=linspace(-5, 5, size)
		x2=linspace(-5, 5, size)

	x, y=meshgrid(x1, x2)

	dense=RealFeatures(array((ravel(x), ravel(y))))
	if sparse:
		test=SparseRealFeatures()
		test.obtain_from_simple(dense)
	else:
		test=dense

	if kernel and train:
		kernel.init(train, test)
	else:
		classifier.set_features(test)

	labels = None
	if regression:
		labels=classifier.apply().get_labels()
	else:
		labels=classifier.apply().get_confidences()
	z=labels.reshape((size, size))

	return x, y, z
开发者ID:TharinduRusira,项目名称:shogun,代码行数:37,代码来源:util.py

示例4: subgradient_svm

# 需要导入模块: from shogun.Features import SparseRealFeatures [as 别名]
# 或者: from shogun.Features.SparseRealFeatures import obtain_from_simple [as 别名]
def subgradient_svm ():
	print 'SubGradientSVM'

	from shogun.Features import RealFeatures, SparseRealFeatures, Labels
	from shogun.Classifier import SubGradientSVM

	realfeat=RealFeatures(fm_train_real)
	feats_train=SparseRealFeatures()
	feats_train.obtain_from_simple(realfeat)
	realfeat=RealFeatures(fm_test_real)
	feats_test=SparseRealFeatures()
	feats_test.obtain_from_simple(realfeat)

	C=0.9
	epsilon=1e-3
	num_threads=1
	max_train_time=1.
	labels=Labels(label_train_twoclass)

	svm=SubGradientSVM(C, feats_train, labels)
	svm.set_epsilon(epsilon)
	svm.parallel.set_num_threads(num_threads)
	svm.set_bias_enabled(False)
	svm.set_max_train_time(max_train_time)
	svm.train()

	svm.set_features(feats_test)
	svm.classify().get_labels()
开发者ID:polyactis,项目名称:test,代码行数:30,代码来源:classifier_subgradientsvm_modular.py

示例5: classify

# 需要导入模块: from shogun.Features import SparseRealFeatures [as 别名]
# 或者: from shogun.Features.SparseRealFeatures import obtain_from_simple [as 别名]
def classify (true_labels):
	num_feats=2
	num_vec=true_labels.get_num_labels()

	data_train=numpy.concatenate(
		(numpy.random.randn(num_feats, num_vec/2)-1,
			numpy.random.randn(num_feats, num_vec/2)+1),
		axis=1)
	realfeat=RealFeatures(data_train)
	feats_train=SparseRealFeatures()
	feats_train.obtain_from_simple(realfeat)
	C=3.
	svm=SVMOcas(C, feats_train, true_labels)
	svm.train()

	data_test=numpy.concatenate(
		(numpy.random.randn(num_feats, num_vec/2)-1,
			numpy.random.randn(num_feats, num_vec/2)+1),
		axis=1)
	realfeat=RealFeatures(data_test)
	feats_test=SparseRealFeatures()
	feats_test.obtain_from_simple(realfeat)
	svm.set_features(feats_test)

	return numpy.array(svm.classify().get_labels())
开发者ID:AsherBond,项目名称:shogun,代码行数:27,代码来源:all_evaluation.py

示例6: svmsgd

# 需要导入模块: from shogun.Features import SparseRealFeatures [as 别名]
# 或者: from shogun.Features.SparseRealFeatures import obtain_from_simple [as 别名]
def svmsgd ():
	print 'SVMSGD'

	from shogun.Features import RealFeatures, SparseRealFeatures, Labels
	from shogun.Classifier import SVMSGD

	realfeat=RealFeatures(fm_train_real)
	feats_train=SparseRealFeatures()
	feats_train.obtain_from_simple(realfeat)
	realfeat=RealFeatures(fm_test_real)
	feats_test=SparseRealFeatures()
	feats_test.obtain_from_simple(realfeat)

	C=0.9	
	num_threads=1
	num_iter=5
	labels=Labels(label_train_twoclass)

	svm=SVMSGD(C, feats_train, labels)
	svm.set_epochs(num_iter)
	#svm.io.set_loglevel(0)
	svm.train()
	
	
	svm.set_features(feats_test)
	labelPrediction = svm.classify().get_labels()
	print labelPrediction>0
开发者ID:polyactis,项目名称:test,代码行数:29,代码来源:classifier_svmsgd_modular.py

示例7: distance_sparseeuclidean_modular

# 需要导入模块: from shogun.Features import SparseRealFeatures [as 别名]
# 或者: from shogun.Features.SparseRealFeatures import obtain_from_simple [as 别名]
def distance_sparseeuclidean_modular (fm_train_real=traindat,fm_test_real=testdat):
	from shogun.Features import RealFeatures, SparseRealFeatures
	from shogun.Distance import SparseEuclidianDistance

	realfeat=RealFeatures(fm_train_real)
	feats_train=SparseRealFeatures()
	feats_train.obtain_from_simple(realfeat)
	realfeat=RealFeatures(fm_test_real)
	feats_test=SparseRealFeatures()
	feats_test.obtain_from_simple(realfeat)

	distance=SparseEuclidianDistance(feats_train, feats_train)

	dm_train=distance.get_distance_matrix()
	distance.init(feats_train, feats_test)
	dm_test=distance.get_distance_matrix()

	return distance,dm_train,dm_test
开发者ID:behollis,项目名称:muViewBranch,代码行数:20,代码来源:distance_sparseeuclidean_modular.py

示例8: sparse_euclidian_distance

# 需要导入模块: from shogun.Features import SparseRealFeatures [as 别名]
# 或者: from shogun.Features.SparseRealFeatures import obtain_from_simple [as 别名]
def sparse_euclidian_distance ():
	print 'SparseEuclidianDistance'

	from shogun.Features import RealFeatures, SparseRealFeatures
	from shogun.Distance import SparseEuclidianDistance

	realfeat=RealFeatures(fm_train_real)
	feats_train=SparseRealFeatures()
	feats_train.obtain_from_simple(realfeat)
	realfeat=RealFeatures(fm_test_real)
	feats_test=SparseRealFeatures()
	feats_test.obtain_from_simple(realfeat)

	distance=SparseEuclidianDistance(feats_train, feats_train)

	dm_train=distance.get_distance_matrix()
	distance.init(feats_train, feats_test)
	dm_test=distance.get_distance_matrix()
开发者ID:memimo,项目名称:shogun-liblinear,代码行数:20,代码来源:distance_sparseeuclidean_modular.py

示例9: classifier_svmsgd_modular

# 需要导入模块: from shogun.Features import SparseRealFeatures [as 别名]
# 或者: from shogun.Features.SparseRealFeatures import obtain_from_simple [as 别名]
def classifier_svmsgd_modular (fm_train_real=traindat,fm_test_real=testdat,label_train_twoclass=label_traindat,C=0.9,num_threads=1,num_iter=5):

	from shogun.Features import RealFeatures, SparseRealFeatures, Labels
	from shogun.Classifier import SVMSGD

	realfeat=RealFeatures(fm_train_real)
	feats_train=SparseRealFeatures()
	feats_train.obtain_from_simple(realfeat)
	realfeat=RealFeatures(fm_test_real)
	feats_test=SparseRealFeatures()
	feats_test.obtain_from_simple(realfeat)

	labels=Labels(label_train_twoclass)

	svm=SVMSGD(C, feats_train, labels)
	svm.set_epochs(num_iter)
	#svm.io.set_loglevel(0)
	svm.train()

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

示例10: classifier_subgradientsvm_modular

# 需要导入模块: from shogun.Features import SparseRealFeatures [as 别名]
# 或者: from shogun.Features.SparseRealFeatures import obtain_from_simple [as 别名]
def classifier_subgradientsvm_modular(fm_train_real, fm_test_real, label_train_twoclass, C, epsilon, max_train_time):

    from shogun.Features import RealFeatures, SparseRealFeatures, Labels
    from shogun.Classifier import SubGradientSVM

    realfeat = RealFeatures(fm_train_real)
    feats_train = SparseRealFeatures()
    feats_train.obtain_from_simple(realfeat)
    realfeat = RealFeatures(fm_test_real)
    feats_test = SparseRealFeatures()
    feats_test.obtain_from_simple(realfeat)

    labels = Labels(label_train_twoclass)

    svm = SubGradientSVM(C, feats_train, labels)
    svm.set_epsilon(epsilon)
    svm.set_max_train_time(max_train_time)
    svm.train()

    svm.set_features(feats_test)
    labels = svm.apply().get_labels()

    return labels, svm
开发者ID:Anshul-Bansal,项目名称:gsoc,代码行数:25,代码来源:classifier_subgradientsvm_modular.py

示例11: svmsgd

# 需要导入模块: from shogun.Features import SparseRealFeatures [as 别名]
# 或者: from shogun.Features.SparseRealFeatures import obtain_from_simple [as 别名]
def svmsgd ():
	print 'SVMSGD'

	from shogun.Features import RealFeatures, SparseRealFeatures, Labels
	from shogun.Classifier import SVMSGD

	realfeat=RealFeatures(fm_train_real)
	feats_train=SparseRealFeatures()
	feats_train.obtain_from_simple(realfeat)
	realfeat=RealFeatures(fm_test_real)
	feats_test=SparseRealFeatures()
	feats_test.obtain_from_simple(realfeat)

	C=0.9
	epsilon=1e-5
	num_threads=1
	labels=Labels(label_train_twoclass)

	svm=SVMSGD(C, feats_train, labels)
	#svm.io.set_loglevel(0)
	svm.train()

	svm.set_features(feats_test)
	svm.classify().get_labels()
开发者ID:memimo,项目名称:shogun-liblinear,代码行数:26,代码来源:classifier_svmsgd_modular.py


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