本文整理汇总了Python中timer.Timer.pick方法的典型用法代码示例。如果您正苦于以下问题:Python Timer.pick方法的具体用法?Python Timer.pick怎么用?Python Timer.pick使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类timer.Timer
的用法示例。
在下文中一共展示了Timer.pick方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: compute_category
# 需要导入模块: from timer import Timer [as 别名]
# 或者: from timer.Timer import pick [as 别名]
def compute_category(self,item):
t = Timer()
t.pick("debut")
voc = self.voc_from_item(item)
if self.product:
voc = self.word_product(voc)
voc_dic = self.word_dic_from_list(voc)
best_score = 0
best_cat = 1000009411
t.pick("vocabulaire construit")
cat_set = set()
for word in voc_dic["dic"].keys():
try:
cat_set = cat_set.union(self.word_cats_dict[word])
#print 'word : "%s", count : %s ' % (word,len(self.word_cats_dict[word]))
except KeyError:
#Si on ne peut pas trouver de catégorie pour ce mot, c'est qu'il n'a jamais été trouvé
# dans le set train
pass
#print "total : %s " % (len(cat_set) ,)
#print len(voc_dic["dic"])
for cat in cat_set:
score = 0
for word in voc_dic["dic"].keys():
if smart_in(self.centroids[cat],word):
score += self.centroids[cat][word]*voc_dic["dic"][word]
if score > best_score:
best_score = score
best_cat = cat
if best_score == 0:
#print "nothing found"
pass
t.pick("best_cat chope")
return best_cat
示例2: __init__
# 需要导入模块: from timer import Timer [as 别名]
# 或者: from timer.Timer import pick [as 别名]
class Model:
def __init__(
self,
limit=None,
talkative=True,
skip_cdiscount=False,
skip_book=False,
batch=False,
train=False,
cat_count=None,
**kwargs
):
self.skip_cdiscount = skip_cdiscount
self.skip_book = skip_book
self.limit = limit
self.talkative = talkative
self.batch = batch
self.train = train
self.score = 0
self.path = TRAIN_FILE
self.train_len = TRAIN_LEN
self.cdiscount_position = CDISCOUNT_POSITION
self.output_name = RESULT_PATH + self.name + ".csv"
self.no_brand = NO_BRAND
self.cat_count = cat_count
self.id_position = ID_POSITION
self.brand_position = BRAND_POSITION
self.price_position = PRICE_POSITION
self.c3_position = C3_ID_POSITION
self.cdiscount_position = CDISCOUNT_POSITION
self.desc_position = DESCRIPTION_POSITION
self.libelle_position = LIBELLE_POSITION
self.desc_position_test = DESCRIPTION_POSITION_TEST
self.brand_position_test = BRAND_POSITION_TEST
self.price_position_test = PRICE_POSITION_TEST
self.libelle_position_test = LIBELLE_POSITION_TEST
self.counting_timer = Timer()
for key in kwargs.keys():
setattr(self, key, kwargs[key])
print "Model initialized !"
def build(self, skip_cdiscount):
raise Exception("Not Implemented yet")
##################################################################################
## COUNTING FUNCTIONS
def reset_count(self, count_len):
self.count = 0
self.loop_break = False
if self.limit is not None:
self.local_limit = min(count_len, self.limit)
else:
self.local_limit = count_len
self.counting_timer.clean()
self.counting_timer.pick()
def smart_count(self, so_far=False):
self.count += 1
try:
boule = not (self.count % int(self.local_limit / 10)) and self.talkative
except ZeroDivisionError:
boule = False
if self.limit is not None and self.count == self.local_limit:
self.loop_break = True
if self.talkative:
print "100% done"
elif boule:
self.counting_timer.pick()
print "%s%% done (%s s)" % (int(100 * self.count / float(self.local_limit)), self.counting_timer.last_dif())
if so_far:
print "score so far : %s " % (self.temp_score / float(self.count) * 100)
##################################################################################
## CATEGORY COMPUTING FUNCTIONS
def compute_category(self, item):
raise Exception("Not Implemented yet")
def compute_output(self):
result = [["Id_Produit", "Id_Categorie"]]
id_position = ID_POSITION
if self.train:
file_name = VALIDATION_FILE
brand_position = BRAND_POSITION
price_positin = PRICE_POSITION
file_len = TRAIN_LEN
validation_len = VALIDATION_LEN
cat_position = C3_ID_POSITION
cdiscount_position = CDISCOUNT_POSITION
else:
file_name = TEST_FILE
brand_position = BRAND_POSITION_TEST
file_len = TEST_LEN
cdiscount_position = 1
spam_reader = parser(file_name)
#.........这里部分代码省略.........