# Compare two arrays by the number of occurances

I have the following dictionary:

``````{ "Drama": 8, "Adventure": 8, "Action": 4, "Comedy": 3, "Thriller": 1 }
``````

This dictionary is like a representation of a user's preferences in movies. (in the past he selected like 8 drama movies, 8 adventure ones etc).

Then I have another movie with genres:

``````["Action","Adventure","Fantasy"]
``````

Is there a way to have like a measure to say that the movie is pretty recommendable to the user (having the fact that adventure and action movies are the ones he likes the most)?

I've tried not to create a dictionary, but an array with all the genres combined and then compare the two arrays. (this doesn't take into account the fact that I have multiple drama movies liked by the user i.e.).

I've tried to create two strings from those arrays and apply the Jaccard method, but this is just like an intersection and it doesn't take into account how many times the genre appeared in the first string. Also I've tried the Levensthein method, but I'm not really looking to see how many changes do I need to make in order to have 2 equal strings.

I'm not sure how to approach this.

• you have lost quite a lot of information by summing up the previouslt watched movie categories. Do you have the raw data for each film watched? then you could use the categories as 0/1 columns and try to predict the preference score – Ewan Jan 13 '19 at 17:29

You could try an ad-hoc method such as summing the weight of all tags, but that is not a meaningful metric.

A better approach would be to perform statistical inference to answer a question like “what is the probability that the user will like this movie?” That requires that we have some model based on previous data submitted by the user. I.e. your dictionary with weights might not be suitable.

A simple model to get started is a Naive Bayes Classifier. Bayes theorem allows us to calculate the conditional probability P(A|B) of some event. Here, we want to calculate the likelihood that the user likes some movie conditional on the the user's like or dislike for a category.

``````p(user likes movie m | movie categories A, B, C)
= p(any user likes move m)
·  p(movie x has category A | user likes a movie x)
·  p(movie x has category B | user likes a movie x)
·  p(movie x has category C | user likes a movie x)
``````

This result is not a probability and is not scaled to the interval [0,1] but can be used for ranking. The required input probabilities can be calculated from historical data. We need to know:

• a prior expectation, e.g. the global probability that any user would like this movie; and
• the probability that movies that the user likes have some category (this is related to the data in your dictionary).

This can work quite well. However, Naive Bayes is naive because it does not consider correlations between classes, and will provide bad predictions for a user that likes action-comedy but really dislikes other comedy. You may therefore want to use a more sophisticated machine learning model, such as neural networks or support vector machines. There has been significant practical interest in this kind of classification because it addresses e.g. the Netflix problem (which series should be recommended to this user so that they are most satisfied) and the targeted ad problem (which ad should we show this type of user so that they are most likely to interact with the ad).

• I think, in my case, I can use both SVM and ANN, because the features I use don't really have a relationship between one another (if they were related, I should've used ANN). Thank you – Marian Ene Jan 14 '19 at 17:44