本文整理汇总了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))
示例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))