How to implement a recommendation system?

I have a book of Collective Intelligence, but I'm not sure how it can be put into practice.

Say I have a PHP website with a mySQL database. The user can embed articles with title and content into the database. For simplicity, we simply compare the name.

  • How to make coffee ?
  • 15 things about coffee .
  • The big question.
  • How to sharpen a pencil?
  • Guy hits the balls

We open "How to make coffee?" and because there are similarities in the words with the second and fourth headings, they will appear in the โ€œRelated articleโ€ section.

How can I implement this with PHP and mySQL? This is fine if I have to use Python. Thanks in advance.

+4
source share
3 answers

Keep a set of keywords next to each product, which should essentially be everything in the name, except for a set of stop words . When the title is displayed, you will find other products that share common keywords (with those who have one or more common priorities).

You could further improve this by assigning a rating to each keyword based on its deficit (with shorter words a higher score is given, since a match in "PHP", for example, will be more relevant than a match in "programming") or by tracking the number of manual attempts by the user between a set of products.

Whatever your best bet is to start by making it simple, and then improve it when you continue. Depending on the size of your database, more sophisticated methods may not be as prolific.

+5
source

It is best to use a set of tags that are parsed and stored in db when inserting the header, and then based on this query.

If you need to parse the header, you'll basically make a LIKE request:

SELECT * FROM ENTRIES WHERE TITLE LIKE '%<keyword>%'; 

For a more detailed answer:

 // You need some test to see if the word is valid. // "is" should not be considered a valid match. // This is a simple one based on length, a // "blacklist" would be better, but that up to you. function isValidEntry( $word ) { return strlen( $word ) >= 4; } //to hold all relevant search strings: $terms = array(); $postTitleWords = explode( ' ' , strtolower( 'How to Make Coffee' ) ); for( $postTitleWords as $index => $word ) { if( isValidEntry( $word ) ) $terms[] = $word; else { $bef = @$postTitleWords[ $index - 1 ]; if( $bef && !isValidEntry( $bef ) ) $terms[] = "$bef $word"; $aft = @$postTitleWords[ $index + 1 ]; if( $aft && !isValidEntry( $aft ) ) $terms[] = "$word $aft"; } } $terms = array_unique( $terms ); if( !count( $terms ) ) { //This is a completely unique title! } $search = 'SELECT * FROM ENTRIES WHERE lower( TITLE ) LIKE \'%' . implode( '%\' OR lower( TITLE ) LIKE \'%' $terms ) . '\'%'; // either pump that through your mysql_search or PDO. 
+2
source

This can simply be achieved using wildcards in SQL queries. If you have large texts, and the wildcard doesn't seem to be able to capture the middle part of the text, then check if the substring matches one of the other. Hope this helps. By the way, your question name asks about the implementation of the recommendation system, and the description of the question simply requires coordination of the field between database records. The recommendation system is a wide topic and contains many interesting algorithms (for example, joint filtering, content method, matrix factorization, neural networks, etc.). Please feel free to study these advanced topics if your project fits this scale.

0
source

All Articles