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


Python SparseRealFeatures.load方法代码示例

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


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

示例1: features_io_modular

# 需要导入模块: from shogun.Features import SparseRealFeatures [as 别名]
# 或者: from shogun.Features.SparseRealFeatures import load [as 别名]
def features_io_modular(fm_train_real, label_train_twoclass):
	import numpy
	from shogun.Features import SparseRealFeatures, RealFeatures, Labels
	from shogun.Kernel import GaussianKernel
	from shogun.IO import AsciiFile, BinaryFile, HDF5File

	feats=SparseRealFeatures(fm_train_real)
	feats2=SparseRealFeatures()

	f=BinaryFile("fm_train_sparsereal.bin","w")
	feats.save(f)

	f=AsciiFile("fm_train_sparsereal.ascii","w")
	feats.save(f)

	f=BinaryFile("fm_train_sparsereal.bin")
	feats2.load(f)

	f=AsciiFile("fm_train_sparsereal.ascii")
	feats2.load(f)

	feats=RealFeatures(fm_train_real)
	feats2=RealFeatures()

	f=BinaryFile("fm_train_real.bin","w")
	feats.save(f)

	f=HDF5File("fm_train_real.h5","w", "/data/doubles")
	feats.save(f)

	f=AsciiFile("fm_train_real.ascii","w")
	feats.save(f)

	f=BinaryFile("fm_train_real.bin")
	feats2.load(f)
	#print "diff binary", numpy.max(numpy.abs(feats2.get_feature_matrix().flatten()-fm_train_real.flatten()))

	f=AsciiFile("fm_train_real.ascii")
	feats2.load(f)
	#print "diff ascii", numpy.max(numpy.abs(feats2.get_feature_matrix().flatten()-fm_train_real.flatten()))

	lab=Labels(numpy.array([1.0,2.0,3.0]))
	lab2=Labels()
	f=AsciiFile("label_train_twoclass.ascii","w")
	lab.save(f)

	f=BinaryFile("label_train_twoclass.bin","w")
	lab.save(f)

	f=HDF5File("label_train_real.h5","w", "/data/labels")
	lab.save(f)

	f=AsciiFile("label_train_twoclass.ascii")
	lab2.load(f)

	f=BinaryFile("label_train_twoclass.bin")
	lab2.load(f)

	f=HDF5File("fm_train_real.h5","r", "/data/doubles")
	feats2.load(f)
	#print feats2.get_feature_matrix()
	f=HDF5File("label_train_real.h5","r", "/data/labels")
	lab2.load(f)
	#print lab2.get_labels()

	#clean up
	import os
	for f in ['fm_train_sparsereal.bin','fm_train_sparsereal.ascii',
			'fm_train_real.bin','fm_train_real.h5','fm_train_real.ascii',
			'label_train_real.h5', 'label_train_twoclass.ascii','label_train_twoclass.bin']:
		os.unlink(f)
	return feats, feats2, lab, lab2
开发者ID:ashish-sadh,项目名称:shogun,代码行数:74,代码来源:features_io_modular.py


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