For an e-commerce website, There is always need of the product up-selling and recommending other products based on previous purchases, for this we need a recommendation engine to manage such tasks, In interplay it is really easy to deploy one.
Here we are creating an recommendation engine for a small e-commerce website
Prerequisites:
1) The clear requirement of recommendation engine (Content based or Collaborative)
2) The cleaned and ready data file (Preferable to be in .csv format)
3) Precise information collection over products, their categories, previous purchases and other information in required form
Steps
1) First we need an API to continuously trained over user input while selecting product and their entry in cart. Search and drop 'HTTP' and 'Python function' in editor, we are creating a recommendation model in collaboration form which needed input in user with their 'userID' and 'ItemID'. and we making our model based on 'Turi' Recommender system. We would like to suggest to read documentations of Turi Machine learning platform.
find and drag the 'http' , 'console' and 'python function' nodes in editer and connect them as :
('Console' is used on command output in debugger Console and it is optional )
2) Edit 'http in' properties to take input address for example:
The python 3 function is used for model training, Here this is an example code:
def read_csv(path,model_save_path):
actions = tc.SFrame.read_csv(path)
status = "Importing csv..."
actions = actions.dropna()
training_data, validation_data = tc.recommender.util.random_split_by_user(actions, user_id_column_name, item_id_column_name.
ranking_factorization_model = tc.recommender.item_similarity_recommender.create(training_data,user_id_column_name, item_id_column_name
status_2 = "Traing Started..."
ranking_factorization_model.save(model_save_path)
status_3 = "Training Completed..."
status_4 = save_model_at
return status,status_2,status_4
stat = read_csv(training_csv,save_model_at)
msg['payload'] = stat
return msg
2) After all set, let's head to make an API integrating the model in Interplay, Search and drop for 'HTTP get' , 'Node.js function', 'Turi','Python 3 function' and 'HTTP out'
(Console 'msg' are used for checking console output while testing and they are completely optional)
then combine them as shown:
3) Here we get the productID(Which is assigned to every product on store) and passing to Node.js function
Edit 'HTTP' node properties where 'productID' is required:
4) For Turi:
5) For second Node.js function we are removing the given productID from recommendation engine, although it is optional.
Sample Code:
results = json.loads(msg['payload']
try:
for i in range(len(results[0])):
for j in range(len(results[0]["Query"])):
if results[0]["Data"][i]["UPC_for_img"] == results[0]["Query"][j]
["UPC_for_img"]: results[0]["Data"].pop(i)
break
msg["payload"] = json.dumps(results)
except:
msg["payload"] = json.dumps(results)
return msg
6) For HTTP out, we can set Header parameter, but for this example, it relies on default one:
Looks like training and using Turi model is quite easy