本文整理汇总了Python中feature.Feature.load_all方法的典型用法代码示例。如果您正苦于以下问题:Python Feature.load_all方法的具体用法?Python Feature.load_all怎么用?Python Feature.load_all使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类feature.Feature
的用法示例。
在下文中一共展示了Feature.load_all方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run_online
# 需要导入模块: from feature import Feature [as 别名]
# 或者: from feature.Feature import load_all [as 别名]
def run_online(self):
# load feature matrix
online_features = Feature.load_all(self.config.get('DIRECTORY', 'feature_pt'),
self.config.get('FEATURE', 'feature_selected').split(),
self.config.get('MODEL', 'online_rawset_name'),
self.config.get('FEATURE', 'will_save'))
model = Model.new(self.config.get('MODEL', 'model_name'), self.config)
model_fp = self.config.get('DIRECTORY', 'model_pt') + '/se.%s.model' % self.config.get('MODEL', 'model_name')
model.load(model_fp)
online_preds = model.predict(online_features)
online_preds_fp = '%s/se_online.%s.pred' % (self.config.get('DIRECTORY', 'pred_pt'),
self.config.get('MODEL', 'online_test_rawset_name'))
DataUtil.save_vector(online_preds_fp, online_preds, 'w')
示例2: run_offline
# 需要导入模块: from feature import Feature [as 别名]
# 或者: from feature.Feature import load_all [as 别名]
def run_offline(self):
LogUtil.log('INFO', 'cv_tag(%s)' % self.cv_tag)
# load feature matrix
offline_features = Feature.load_all(self.config.get('DIRECTORY', 'feature_pt'),
self.config.get('FEATURE', 'feature_selected').split(),
self.config.get('MODEL', 'offline_rawset_name'),
self.config.get('FEATURE', 'will_save'))
# load labels
offline_labels = DataUtil.load_vector('%s/%s.label' % (self.config.get('DIRECTORY', 'label_pt'),
self.config.get('MODEL', 'offline_rawset_name')),
True)
# generate index file
if '' == self.cv_tag:
self.cv_tag = self.out_tag
self.__generate_index(offline_features.shape[0])
# cross validation
offline_valid_preds_all = [0.] * offline_features.shape[0]
offline_test_preds_all = [0.] * offline_features.shape[0]
for fold_id in range(self.cv_num):
LogUtil.log('INFO', 'cross validation fold_id(%d) begin' % fold_id)
# generate training data set
offline_train_pos_rate = float(self.config.get('MODEL', 'train_pos_rate'))
offline_train_indexs_fp = '%s/cv_tag%s_n%d_f%d_train.%s.index' % (self.config.get('DIRECTORY', 'index_pt'),
self.cv_tag,
self.cv_num,
fold_id,
self.config.get('MODEL',
'offline_rawset_name'))
offline_train_indexs = DataUtil.load_vector(offline_train_indexs_fp, 'int')
offline_train_features, offline_train_labels, offline_train_balanced_indexs = \
CrossValidation.__generate_data(offline_train_indexs,
offline_labels,
offline_features,
offline_train_pos_rate)
LogUtil.log('INFO', 'offline train data generation done')
# generate validation data set
offline_valid_pos_rate = float(self.config.get('MODEL', 'valid_pos_rate'))
offline_valid_indexs_fp = '%s/cv_tag%s_n%d_f%d_valid.%s.index' % (self.config.get('DIRECTORY', 'index_pt'),
self.cv_tag,
self.cv_num,
fold_id,
self.config.get('MODEL',
'offline_rawset_name'))
offline_valid_indexs = DataUtil.load_vector(offline_valid_indexs_fp, 'int')
offline_valid_features, offline_valid_labels, offline_valid_balanced_indexs = \
CrossValidation.__generate_data(offline_valid_indexs,
offline_labels,
offline_features,
offline_valid_pos_rate)
LogUtil.log('INFO', 'offline valid data generation done')
# generate test data set
offline_test_pos_rate = float(self.config.get('MODEL', 'test_pos_rate'))
offline_test_indexs_fp = '%s/cv_tag%s_n%d_f%d_test.%s.index' % (self.config.get('DIRECTORY', 'index_pt'),
self.cv_tag,
self.cv_num,
fold_id,
self.config.get('MODEL',
'offline_rawset_name'))
offline_test_indexs = DataUtil.load_vector(offline_test_indexs_fp, 'int')
offline_test_features, offline_test_labels, offline_test_balanced_indexs = \
CrossValidation.__generate_data(offline_test_indexs,
offline_labels,
offline_features,
offline_test_pos_rate)
LogUtil.log('INFO', 'offline test data generation done')
model = Model.new(self.config.get('MODEL', 'model_name'), self.config)
model_fp = self.config.get('DIRECTORY', 'model_pt') + '/cv_n%d_f%d.%s.model' % \
(self.cv_num,
fold_id,
self.config.get('MODEL', 'model_name'))
model.save(model_fp)
offline_train_preds, offline_valid_preds, offline_test_preds = model.fit(offline_train_features,
offline_train_labels,
offline_valid_features,
offline_valid_labels,
offline_test_features,
offline_test_labels)
offline_train_score = Evaluator.evaluate(self.config.get('MODEL', 'evaluator_name'),
offline_train_labels,
offline_train_preds)
offline_valid_score = Evaluator.evaluate(self.config.get('MODEL', 'evaluator_name'),
offline_valid_labels,
offline_valid_preds)
offline_test_score = Evaluator.evaluate(self.config.get('MODEL', 'evaluator_name'),
offline_test_labels,
offline_test_preds)
score_fp = '%s/%s.score' % (self.config.get('DIRECTORY', 'score_pt'), 'cv')
score_file = open(score_fp, 'a')
score_file.write('fold:%d\ttrain:%s\tvalid:%s\ttest:%s\n' % (fold_id,
offline_train_score,
offline_valid_score,
offline_test_score))
score_file.close()
# merge prediction results
for index in range(len(offline_valid_balanced_indexs)):
offline_valid_preds_all[offline_valid_balanced_indexs[index]] = offline_valid_preds[index]
#.........这里部分代码省略.........