本文整理汇总了Python中lib.util.Util.str_to_tuple方法的典型用法代码示例。如果您正苦于以下问题:Python Util.str_to_tuple方法的具体用法?Python Util.str_to_tuple怎么用?Python Util.str_to_tuple使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lib.util.Util
的用法示例。
在下文中一共展示了Util.str_to_tuple方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: infer
# 需要导入模块: from lib.util import Util [as 别名]
# 或者: from lib.util.Util import str_to_tuple [as 别名]
def infer(self, params):
window = {'tweets':[], 'start':0} # storing tweets
""" User distribution updating """
for tweet in self.tweets.stream():
if type(tweet) == type({}):
self.update_user_distributions(tweet, params)
""" Location prediction using user distribution """
for user in self.users.iter():
if user['location_point'] == None:
""" unlabeled user """
if user['id'] in self.user_distributions and len(self.user_distributions[user['id']]) > 0:
inferred_city = self.predict(self.user_distributions[user['id']], params)
inferred_location = Util.str_to_tuple(inferred_city)
user['location_point'] = inferred_location
示例2: infer_one
# 需要导入模块: from lib.util import Util [as 别名]
# 或者: from lib.util.Util import str_to_tuple [as 别名]
def infer_one(self, user_id):
tweets = self.tweets.get(user_id)
user_words = {}
for tweet in tweets:
for w in Util.get_nouns(tweet['text'], params['lang']):
if not w in user_words: user_words[w] = 0
user_words[w] += 1
city_probs = {}
for w in self.model['pwc']:
for city in self.model['pwc'][w]:
if not city in city_probs:
city_probs[city] = self.model['pc'][city]
city_probs[city] *= self.model['pwc'][w][city]
max_city = None
max_prob = 0
for city in city_probs:
if max_prob < city_probs[city]:
max_prob = city_probs[city]
max_city = city
return Util.str_to_tuple(max_city)