Skip to main content

Recommender System using Python


Recommender systems are everywhere. Amazon recommends buys we like, google recommends searches, Youtube recommends systems and Facebook recommends people.
All of these implementations describe Recommender Systems.

There are 2 types of Recommender Systems.

Collaborative Systems - Systems that recommend information based on what you like and what the others like.

Content Based Systems- Based on what you have viewed









This is a simple ML based recommender System in python. It uses the LightFM library as the dataset


import numpy as np
from lightfm import LightFM
from fetch_lastfm import fetch_lastfm
data = fetch_lastfm()
model = LightFM(loss='warp')
model.fit(data['matrix'], epochs=30, num_threads=2)
# Get recommendationns function
def get_recommendations(model, coo_mtrx, users_ids):
n_items = coo_mtrx.shape[1]
for user in users_ids:
# TODO create known positives
# Artists the model predicts they will like
scores = model.predict(user, np.arange(n_items))
top_scores = np.argsort(-scores)[:3]
print 'Recomendations for user %s:' % user
for x in top_scores.tolist():
for artist, values in data['artists'].iteritems():
if int(x) == values['id']:
print ' - %s' % values['name']
print '\n' # Get it pretty
user_1 = raw_input('Select user_1 (0 to %s): ' % data['users'])
user_2 = raw_input('Select user_2 (0 to %s): ' % data['users'])
user_3 = raw_input('Select user_3 (0 to %s): ' % data['users'])
print '\n' # Get it pretty
get_recommendations(model, data['matrix'], [user_1, user_2, user_3])

Comments

  1. Replies
    1. Thanks ... please subscribe and share this ... stay tuned for future posts :)

      Delete
  2. We make it easier for businesses to achieve their KPI’s with personalized recommendations. We deliver highly personal, automated, and contextual insights to improve your customers’ experience and business results.https://divedeep.ai/recommendation-systems-services-and-solutions

    ReplyDelete
  3. The blog was really helpful, thanks for such quality content
    customer survey satisfaction

    ReplyDelete

Post a Comment

Popular posts from this blog

Why online learning needs AI augmentation

With a large portion of schools having moved to online based learning through platforms like Zoom and Microsoft Teams, students are required to grasp concepts in a one-dimensional online medium as opposed to a constructive and collaborative class environment. Being a student during the pandemic, I have first hand experience with the mundane manner of teaching- and why we need to augment this with Artificial Intelligence algorithms. In a classroom, teachers can somehow manage to personalise some parts of learning or pay attention to weak students. However, in an online medium, with all the latency issues and network constraints, also moving in a general pace can be tough. Therefore for online learning,AI can be key, by providing a personalised learning path for the students. Using algorithms like NLP ( Natural Language Processing ), the online class can be transcribed according to the student's intellectual levels. AI, in this case, can make a specific-tailored learning path ...

Book Review : Zero to One by Peter Thiel

Introduction Zero to One is a  condensed and updated version of a highly popular set of online notes taken by Masters for the CS183 class on startups taught by Thiel at  Stanford University  in Spring 2012 [Source: Wikipedia ] . In short, it's about creating value in the world. Business Background of the Author Peter Thiel was the founder of Confinity, a company making electronic payment systems which merged with Elon Musk's " X.com", a similar venture to create what we now know as Paypal, which is now a $40 billion company with one share worth $ 80. He owned a 3.7 per cent stake at Paypal. Not long after eBay ... the online retail giant, made an acquisition offer to Paypal valuing the entire company at $1 billion. After taxes and financial customs, Peter Thiel netted $55 Million, making him filthy rich. He started a hedge fund and private equity firm named Clarium funds and made an angel investment in Facebook, which made him $1.2 Billion dollars. He...