本文整理汇总了Python中model.Model.new方法的典型用法代码示例。如果您正苦于以下问题:Python Model.new方法的具体用法?Python Model.new怎么用?Python Model.new使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类model.Model
的用法示例。
在下文中一共展示了Model.new方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run_online
# 需要导入模块: from model import Model [as 别名]
# 或者: from model.Model import new [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 model import Model [as 别名]
# 或者: from model.Model import new [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]
#.........这里部分代码省略.........
示例3:
# 需要导入模块: from model import Model [as 别名]
# 或者: from model.Model import new [as 别名]
table_engine = row[1]
table_collation = row[2]
table_comment = row[3]
#creating new files
controller_file = writer.make_controller_file(table_name)
model_file = writer.make_model_file(table_name)
field_query = "SELECT TABLE_NAME, COLUMN_NAME, DATA_TYPE, COLUMN_KEY, COLUMN_COMMENT FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = '{0}' AND TABLE_NAME = '{1}'"
user_tb_cursor.execute(field_query.format(selected_db_name, table_name))
field_in_table = user_tb_cursor.fetchall()
#make new controller
controller.new(
controller_file,
writer.pascal_casing(table_name),
table_comment,
field_in_table)
#make new model
model.new(model_file,
writer.pascal_casing(table_name),
table_comment,
table_engine,
table_collation,
field_in_table)
counter_tables += 1
finish_time = datetime.datetime.now()
total_time = (finish_time - start_time).total_seconds()
print("================================================================================")
print("|| {0} tables processed in {1} seconds".format(counter_tables, total_time))
print("================================================================================")