本文整理匯總了Python中recommender.Recommender.recommend方法的典型用法代碼示例。如果您正苦於以下問題:Python Recommender.recommend方法的具體用法?Python Recommender.recommend怎麽用?Python Recommender.recommend使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類recommender.Recommender
的用法示例。
在下文中一共展示了Recommender.recommend方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: TestRecommender
# 需要導入模塊: from recommender import Recommender [as 別名]
# 或者: from recommender.Recommender import recommend [as 別名]
class TestRecommender(unittest.TestCase):
def setUp(self):
self.recommender = Recommender('../data/sample.db') #樣本數據庫
def test_recommend(self):
self.recommender.train()
for user in self.recommender.users:
print 'user = {0}, {1}'.format(user, self.recommender.recommend(user, 3))
示例2: main
# 需要導入模塊: from recommender import Recommender [as 別名]
# 或者: from recommender.Recommender import recommend [as 別名]
def main():
startTime = datetime(2016,4,30,8)
endTime = datetime(2016,5,1,18)
recom = Recommender()
recom.setTimeInterval(startTime,endTime)
recom.setHabit({"0":90,"1":40,"2":50})
recom.setBudget(1) # allow 1,2,3
travelList = recom.recommend()
print(travelList)
day = 1
travelDict = {}
for _list in travelList:
travelDict[day] = {}
for spot in _list:
travelDict[day][spot.name] = {"coord":spot.coord,"popularity":spot.popularity,"priceLevel":spot.priceLevel,"topic":spot.topicList,"order":spot.order}
day += 1
示例3: retrieve_recommendations
# 需要導入模塊: from recommender import Recommender [as 別名]
# 或者: from recommender.Recommender import recommend [as 別名]
def retrieve_recommendations(alphas, removed_scores_file_path, users_wanted_recommendations):
users_recommended = {}
print "Initializing recommender..."
recommender = Recommender("movie_matcher/new_oliwer_data.txt", removed_scores_file_path, 0.5)
print "Recommender initialization done."
for alpha in alphas:
print "Current alfa: ", alpha
recommender.set_alpha(alpha)
users_recommended[alpha] = {}
i = 0
for user in users_wanted_recommendations.keys():
print "Recommending for user: ", users_wanted_recommendations.keys()[i]
recommendations = recommender.recommend(users_wanted_recommendations.keys()[i])
users_recommended[alpha][user] = recommendations
i += 1
print "Recommendations done."
return users_recommended
示例4: post
# 需要導入模塊: from recommender import Recommender [as 別名]
# 或者: from recommender.Recommender import recommend [as 別名]
def post(self):
json_obj = json_decode(self.request.body)
print('Post data received')
for key in list(json_obj.keys()):
print('key: %s , value: %s' % (key, json_obj[key]))
#response_to_send = {}
#response_to_send['newkey'] = 'hello'
#print('Response to return')
#self.write(json.dumps(response_to_send))
#print('yoooooo')
start_date = json_obj['startDate'].split('-')
end_date = json_obj['endDate'].split('-')
#schedule
startTime = datetime(int(start_date[0]),int(start_date[1]),int(start_date[2]),int(json_obj['startTime']))
endTime = datetime(int(end_date[0]),int(end_date[1]),int(end_date[2]),int(json_obj['endTime']))
recom = Recommender()
recom.setTimeInterval(startTime,endTime)
recom.setHabit(json_obj['like'])
recom.setBudget(json_obj['Budget']) # allow 1,2,3
travelList = recom.recommend()
#print(travelList)
day = 1
travelDict = {}
for _list in travelList:
travelDict[day] = {}
for spot in _list:
#print(spot)
#weather_icon = search_api.get_weather(spot.coord).get('weather')[0].get('icon')
#weather_icon_url = 'http://openweathermap.org/img/w/' + weather_icon + '.png'
weather_icon_url= ''
# print('weather_icon_url = ' + weather_icon_url)
travelDict[day][spot.name] = {"coord":spot.coord,"popularity":spot.popularity,
"priceLevel":spot.priceLevel,"topic":spot.topicList,
"order":spot.order,"ref":spot.ref,
"weather": weather_icon_url}
day += 1
#web_util.write_json(travelDict,"travelList.json")
#self.write(json_encode(travelDict))
self.write(json.dumps(travelDict))
示例5: run
# 需要導入模塊: from recommender import Recommender [as 別名]
# 或者: from recommender.Recommender import recommend [as 別名]
def run():
mse_hist = []
mde_hist = []
samples = 100
config_dict = yaml.load(open(sys.argv[1], 'r'))
uniq = config_dict['uniq_map_file']
runiq = config_dict['runiq_map_file']
path = config_dict['pickle_dir']
rec = Recommender(path, uniq, runiq)
for sample in range(samples):
ch = []
tags_in_agg1 = []
tags_in_agg2 = []
user = rec.generate_user()
ch = rec.recommend(user, n=5)
for fname in user:
prettyprint_song(config_dict, fname)
print user, ' --> ', ch
print '-->'
for fname in ch:
prettyprint_song(config_dict, fname)
agg1 = aggregate_tags(config_dict, user)
agg2 = aggregate_tags(config_dict, ch)
tags_in_agg1.append(len(agg1))
tags_in_agg2.append(len(agg2))
mse, mde = compare_aggregators(agg1, agg2)
mde_hist.append(mde)
mse_hist.append(mse)
print "*************** SAMPLE %d" % (sample)
_, (mse_plot, mde_plot) = plt.subplots(2)
print float(sum(tags_in_agg1)) / len(tags_in_agg1)
print float(sum(tags_in_agg2)) / len(tags_in_agg2)
mse_plot.set_title("Mean Squared Error / Tags Hist")
mde_plot.set_title("Manhattan Dist Error / Tags Hist")
mse_plot.hist(mse_hist, bins=100)
mde_plot.hist(mde_hist, bins=100)
plt.savefig(config_dict['hist_path'])