本文整理汇总了Python中DBUtil.initDB方法的典型用法代码示例。如果您正苦于以下问题:Python DBUtil.initDB方法的具体用法?Python DBUtil.initDB怎么用?Python DBUtil.initDB使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DBUtil
的用法示例。
在下文中一共展示了DBUtil.initDB方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: vectorize
# 需要导入模块: import DBUtil [as 别名]
# 或者: from DBUtil import initDB [as 别名]
def vectorize():
db = DBUtil.initDB()
emails = db.get_all_brushed_emails()
sentences = LabeledLineSentence(emails)
model = Doc2Vec(min_count=1, window=10, size=100, sample=1e-4, negative=5, workers=8)
model.build_vocab(sentences.to_array())
for epoch in range(10): # @UnusedVariable
model.train(sentences.sentences_perm())
model.save(model_file)
示例2: LabeledLineSentence
# 需要导入模块: import DBUtil [as 别名]
# 或者: from DBUtil import initDB [as 别名]
sentences = LabeledLineSentence(emails)
model = Doc2Vec(min_count=1, window=10, size=100, sample=1e-4, negative=5, workers=8)
model.build_vocab(sentences.to_array())
for epoch in range(10): # @UnusedVariable
model.train(sentences.sentences_perm())
model.save(model_file)
if not os.path.isfile(model_file):
print("Model doesn't exist, vectorizing...")
vectorize()
model = Doc2Vec.load(model_file)
db = DBUtil.initDB()
emails = db.get_all_brushed_emails()
train_arrays = []
train_labels = []
test_arrays = []
test_labels = []
for email in emails:
email_id = email.id
prefix_train_pos = 'email_' + str(email_id)
if email_id % 5 != 0:
train_arrays.append(model.docvecs[prefix_train_pos])
train_labels.append(int(email.is_scheduling))
else:
test_arrays.append(model.docvecs[prefix_train_pos])