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


Python SparseRealFeatures.get_sparse_feature_matrix方法代码示例

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


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

示例1: features_sparse_modular

# 需要导入模块: from shogun.Features import SparseRealFeatures [as 别名]
# 或者: from shogun.Features.SparseRealFeatures import get_sparse_feature_matrix [as 别名]
def features_sparse_modular(A):
	from scipy.sparse import csc_matrix
	from shogun.Features import SparseRealFeatures
	from numpy import array, float64, all

	# sparse representation X of dense matrix A
	# note, will work with types other than float64 too,
	# but requires recent scipy.sparse
	X=csc_matrix(A)
	#print A

	# create sparse shogun features from dense matrix A
	a=SparseRealFeatures(A)
	a_out=a.get_full_feature_matrix()
	#print a_out
	assert(all(a_out==A))
	#print a_out

	# create sparse shogun features from sparse matrix X
	a.set_sparse_feature_matrix(X)
	a_out=a.get_full_feature_matrix()
	#print a_out
	assert(all(a_out==A))

	# create sparse shogun features from sparse matrix X
	a=SparseRealFeatures(X)
	a_out=a.get_full_feature_matrix()
	#print a_out
	assert(all(a_out==A))

	# obtain (data,row,indptr) csc arrays of sparse shogun features
	z=csc_matrix(a.get_sparse_feature_matrix())
	z_out=z.todense()
	#print z_out
	assert(all(z_out==A))
开发者ID:Anshul-Bansal,项目名称:gsoc,代码行数:37,代码来源:features_sparse_modular.py

示例2: assert

# 需要导入模块: from shogun.Features import SparseRealFeatures [as 别名]
# 或者: from shogun.Features.SparseRealFeatures import get_sparse_feature_matrix [as 别名]
# note, will work with types other than float64 too,
# but requires recent scipy.sparse
A=array([[1,2,3],[4,0,0],[0,0,0],[0,5,0],[0,0,6],[9,9,9]], dtype=float64)
X=csc_matrix(A)
print A

# create sparse shogun features from dense matrix A
a=SparseRealFeatures(A)
a_out=a.get_full_feature_matrix()
print a_out
assert(all(a_out==A))
print a_out

# create sparse shogun features from sparse matrix X
a.set_sparse_feature_matrix(X)
a_out=a.get_full_feature_matrix()
print a_out
assert(all(a_out==A))

# create sparse shogun features from sparse matrix X
a=SparseRealFeatures(X)
a_out=a.get_full_feature_matrix()
print a_out
assert(all(a_out==A))

# obtain (data,row,indptr) csc arrays of sparse shogun features
z=csc_matrix(a.get_sparse_feature_matrix())
z_out=z.todense()
print z_out
assert(all(z_out==A))
开发者ID:memimo,项目名称:shogun-liblinear,代码行数:32,代码来源:features_sparse_modular.py


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