Building a system of “Suggestions …”

Introduce

The system, or the hint function – I don't know what to say. Something like this. You use Facebook, it will suggest friends for you. Make sure you guys are thinking, "What is this smart guy who is eating facebook, how do I know that I know this guy and introduce me". Or as right below this article, you will see the related article section, this computer is looking for it, not random, nor do I have to find the article inserted below for you, very lazy.

This is a suggestion system (Suggest system / service) or something like that. About the actual application is very high, it can suggest what movies you should watch, suggest to customers whether you want to buy this product, … At first I saw it, think "what This must be very difficult, the big horse heads and the horse faces can do it. " In fact, it is not that hard, so today I will guide building a simple suggestion system.

P / S: The fact that I just read at the time just wrote it for you, but I haven't built it successfully yet.

Project (Project)

I'll start with the most difficult step – name the project. After a bit of deliberation, I finished drinking my father's coffee cup, so I decided to name this project as Professor x .

Plot

The story is the teacher x, on the way to gather the mutants (x-men) to create a walking team. However, each guy has a different way like Wolverine only likes to play with Jean (Phoenix), Uncle X and Mangeto, all want to "confide" with Mystique (the beautiful older sister I introduced in the Startup post) film something ), … Our job is to arrange those mutants to stay together, but the economy is difficult, the land in Q7 is so expensive that Mr. X can only rent a small house. People are few but the ass is crowded. What should I do???

Screen Shot 2016-08-12 at 12.13.30 PM

Uncle X decided to arrange mutants who could "fit together" to stay together. And you are uncle X thanks. If you put sida, then it will fight the field ball, it will be considered as the world to kill the round. Destiny is in your hands

Suit Up and Save the world!

Language

In this project, I will use Nodejs and framework Express languages, there can be a little Coffeescript for alerting you guys . Of course it can't be without the HTML and CSS duo .

Project management is, of course, git used, not to regret it

Create a project

Open CMDER. Create projectx folder

Completely run the basic linux command on Windows if the Cmder executives I've introduced before . Okey now initializes git and npm only

You enter the information that it asks and then just Enter . This is mine

Screen Shot 2016-08-12 at 12.16.11 PM

So that's the basic setup.

Idea

First, I have to see how my ideas suggest room for mates. With a system of suggestions like this, it is not necessary to first see which guys are the same.

For example

Professor X likes Mystique and Uncle Wolf.
Jean Gray also liked Mystique and Wolf, and also, paired with Scott

According to the transitive nature … Professor X and Jean Gray's personality is quite similar, infer that Professor X is quite fond of Scott.

Example 2

This suggestion is quite similar to the suggestion system for Facebook friends

You and A have a lot of common friends. So facebook will think of some guy A guy familiar, perhaps you are familiar. However, its suggestion system also has many other impact factors such as residence, age, gender, etc..

So the idea for the suggestion system I want to say is: It will find out which guys have the most behavior, personality like you, then will take the difference between 2 people and suggest to you.

Algorithm

There is an idea, now it has to be communicated to the computer, it is not so smart that you repeat the idea that it understands. So we have to reimplement our model for computers to understand. I have learned this subject on the school called Mathematical Modeling, I actually go to school, through the subject has not imbued any knowledge at all.

We will talk about group math (Sets) . This is from 6th grade.

Call the set of people who match with the first person, U1 , the second one is U2

For example

The first one is Uncle X. Inferring U1 = {mystique, wolf}
The second is Jean. Infer
U2 = {mystique, wolf, scott}

With 6th grade knowledge, we have:

The likes of both U1 and U2 will be U1 ∩ U2

Everyone who likes both will be U1 ∪ U2

For example

U1 ∩ U2 = {mystique, wolf}
U1 ∪ U2 = {mystique, wolf, scott}

Since then we have a formula to see if the similarities of U1 and U2 will be

| U1 ∩ U2 | / | U1 ∪ U2 |

Looking at the above formula, it will run from 0 to 1. If the value is 1 then U1 and U2 have the same preference. On the other hand, if the value is 0, then … these two guys can't live together. BTW, this formula is known as Paul Jaccard's "coefficient de communauté", not mine.

For example

* The liking level of Uncle X and Jean will be: 2/3 = 0.6666666666666666666666666666666666666666666666666666 …

Come here, I guess you will imagine that we will have a recipe for applying for Uncle X

U2 U1 = {scott} (Ph 2 gathers pressed except that promote c c c á)

According to me, that's Ok. We will suggest all those who match X Youth with the above formula and arrange according to the degree of similarity between 2 people.

However, in the article I refer to it how to calculate the level of Youth X any youth like K does not follow the formula

P (X, K) = Z / M

In which P (X, K) is the X-score youth formula that likes Youth K. Z is the sum of X's similarities with everyone in the X-Men team "dropping their hearts" too . M is the total number of people who like K in the X-Men team . And of course, the value of P (X, K) also runs from 0 to 1.

For example

The fact that Uncle X fits Scott is not as good as the formula above
Suppose an additional character is Storm with
U3 = {wolf, scott}
The similarity between Uncle X and Storm will be

| U1 U3 | / | U1 U3 | = 1/3 = 0, 333 333 333

And of the three characters considered here, there were 2 people who liked Scott. Should M = 2

P (publish c X , scott) = ( 0 , 333 + 0 , 666 ) / 2 = 0.5

I said in part 1 that I just read the material, I just tried it and wrote the article for you guys so I don't know the way of the article I refer to or how I see it, which one is better. So I will build in both ways to the end to see which one is better!

Link reference: https://www.toptal.com/algorithms/predicting-likes-inside-a-simple-recommendation-engine

Conclude

If you understand the algorithm, you want to build on any language, so if you study other languages, then try to follow this algorithm. Let's build together to see if the ending is like me.

ITZone via cuthanh

Share the news now