Product recommendation III

by kai on 11/01/2005

Finally, here’s a .zip-file containing the components, example files with CFC method calls and a MySQL-database script.


Further explanation and documentation is in the extended entry.The database consists of five tables:

CAR_ID is the PK
CAR_CUS_ID is a FK and refers to a customer

CUS_ID is the customer ID and PK
CUS_NAME is the name of the customer

PRO_ID as product ID and PK
PRO_NAME is the product name

CCO_ID is the PK
CCO_CAR_ID is the cart ID and a FK
CCO_PRO_ID is the product ID and a FK
CCO_PRO_AMOUNT is the product amount

CUR_ID is the PK
CUR_CUS_ID_A ID of customer A
CUR_CUS_ID_B ID of customer B
CUR_RATING is the rating (in this particular implementation following the cosinus metric) between A and B

Furthermore there a two CFCs included. CorrelationMatrix.cfc contains logic to fill an empty customerrating table, Recommendation.cfc contains the logic to create a set of recommended products. These two basic CFCs make several assumptions, like that the products are numbered from 1 to n, that the customer IDs are numbered from 1 to m etc. If you want something more sophisticated, feel free to add your own logic or change my stuff, but I’d really appreciate if you provide me with your extensions/additions.

The first (and a regular step – maybe with a nightly run) is to fill the customerrating table. This is done by:

myCMObject = CreateObject(“component”, “CorrelationMatrix”).init(100,26);



where 100 is the number of products, and 26 the number of customers – those are the amounts I provided in the example database (btw: it’s filled with randomly created carts already).

The useMetric() method internally calls the cosinusMetric method. This could be changed by just adding another metric method in the component. Also – a much better approach would be to do it more abstract with using inheritance or whatever…

Getting a set of recommended products is quite simple also:

myRecommendationObject = CreateObject(“component”, “Recommendation”).init(100,26,1);



ausgabe = myRecommendationObject.getNearestProducts(8);

The constructor is called with the number of products and customers again but this time I also have to specifiy the id of the customer I want to be given the recommendations for.

In the example above, I first get the ten nearest customers and create a product vector of them after that. Finally the best eight products are selected and delivered in an array called “ausgabe”.

It’s far away from being optimal right now, if my time allows I’ll provide a better version later…;)

Comments on this entry are closed.

Previous post:

Next post: