本文整理汇总了Python中feature.Feature.save_feature方法的典型用法代码示例。如果您正苦于以下问题:Python Feature.save_feature方法的具体用法?Python Feature.save_feature怎么用?Python Feature.save_feature使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类feature.Feature
的用法示例。
在下文中一共展示了Feature.save_feature方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: extract
# 需要导入模块: from feature import Feature [as 别名]
# 或者: from feature.Feature import save_feature [as 别名]
def extract(self, data_set_name, part_num=1, part_id=0):
"""
Extract the feature from original data set
:param data_set_name: name of data set
:param part_num: number of partitions of data
:param part_id: partition ID which will be extracted
:return:
"""
# load data set from disk
data = pd.read_csv('%s/%s.csv' % (self.config.get('DEFAULT', 'source_pt'), data_set_name)).fillna(value="")
begin_id = int(1. * len(data) / part_num * part_id)
end_id = int(1. * len(data) / part_num * (part_id + 1))
# set feature file path
feature_pt = self.config.get('DEFAULT', 'feature_pt')
if 1 == part_num:
self.data_feature_fp = '%s/%s.%s.smat' % (feature_pt, self.feature_name, data_set_name)
else:
self.data_feature_fp = '%s/%s.%s.smat.%03d_%03d' % (feature_pt,
self.feature_name,
data_set_name,
part_num,
part_id)
feature_file = open(self.data_feature_fp, 'w')
feature_file.write('%d %d\n' % (end_id - begin_id, int(self.get_feature_num())))
# extract feature
for index, row in data[begin_id:end_id].iterrows():
feature = self.extract_row(row)
Feature.save_feature(feature, feature_file)
feature_file.close()
LogUtil.log('INFO',
'save features (%s, %s, %d, %d) done' % (self.feature_name, data_set_name, part_num, part_id))