本文整理汇总了Python中shogun.Features.SparseRealFeatures.set_sparse_feature_vector方法的典型用法代码示例。如果您正苦于以下问题:Python SparseRealFeatures.set_sparse_feature_vector方法的具体用法?Python SparseRealFeatures.set_sparse_feature_vector怎么用?Python SparseRealFeatures.set_sparse_feature_vector使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类shogun.Features.SparseRealFeatures
的用法示例。
在下文中一共展示了SparseRealFeatures.set_sparse_feature_vector方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: convSparseToShog
# 需要导入模块: from shogun.Features import SparseRealFeatures [as 别名]
# 或者: from shogun.Features.SparseRealFeatures import set_sparse_feature_vector [as 别名]
def convSparseToShog(data,delFeature=False):
resFeat = SparseRealFeatures()
resFeat.create_sparse_feature_matrix(len(data))
for iRec in xrange(len(data)):
feat = data[iRec]["feature"]
resFeat.set_sparse_feature_vector(iRec,feat["ind"].astype('i4')-1,feat["val"].astype('f8'))
if delFeature:
data[iRec]["feature"] = None
return resFeat
示例2: getSparseRealFeatures
# 需要导入模块: from shogun.Features import SparseRealFeatures [as 别名]
# 或者: from shogun.Features.SparseRealFeatures import set_sparse_feature_vector [as 别名]
def getSparseRealFeatures(self,sequences,method="frequences"):
maxSeqLen = max( ( len(seq) for seq in sequences ) )
kmer_ind = numpy.zeros(maxSeqLen,dtype='i8')
if method == 'frequences':
kmer_val = numpy.zeros(maxSeqLen,dtype='f4')
else:
kmer_val = numpy.zeros(maxSeqLen,dtype='i4')
kmerMethod = getattr(self,method)
resFeat = SparseRealFeatures()
resFeat.create_sparse_feature_matrix(len(sequences))
for iSeq in xrange(len(sequences)):
seq = sequences[iSeq]
if isinstance(seq,str):
seq = numpy.fromstring(seq,'S1')
self.process(seq)
(size,total) = kmerMethod(kmer_val,kmer_ind)
#print size, total, kmer_val[:10],kmer_ind[:10]
resFeat.set_sparse_feature_vector(iSeq,kmer_ind[:size].astype('i4')-1,kmer_val[:size].astype('f8'))
#pdb.set_trace()
return resFeat