It is quite hard to name the title properly as I just started to learn ML, will try to explain here. I want to practice ML by creating Movie suggestion algorithm. I came up with the following list of dimensions/features:

  • Rating
  • Number of votes
  • Genre
  • Actors
  • Directors
  • Writers
  • Year
  • Combination of Actors/Directors/Writers working in the team
  • Combination of Year and Actor or Director or Writer
  • Actor or Director or Writer working in some genre

There is no problem for me for numeric fields, but in case of actors I have multiple values. How to create feature for the actors?


You could create a "flag" variable for particular actors. Each actor would have their own column in your data and the column would have a 1 if the actor was in that film and a 0 if the actor was not in that film.

Of course, this creates lots of columns and can be tedious to code, but binary indicator variables can be really useful if you want to build a predictive model - worth it in my opinion.


       actor1  actor2 actor3
movie1   1       0      0
movie2   0       1      1
movie3   0       1      0

Edit Re: Director/Actor

It is probably unrealistic to create a variable for every permutation of director/actor combinations. If you want to see how the variables interact you can code interactions into your model when you build it. If you were to do that in R it would look like this:

movie.predictor <- lm(suggestion ~ actor1 + actor2 + director1 + director2 +
                      actor1:director1 + actor2:director1 + actor1:director2 +
                      data = movies.data)

The ":" in R asks the lm(...) function to consider the interaction of those two variables in the regression problem, assuming you are doing regression. Don't worry the same ":" technique works across several model functions. Just read the documentation for your preferred language and package and look for how to code "variable interactions"

Of course, now you are typing out all of the permutations of variable interactions. You might want to also consider a clustering algorithm to group actors and directors together. I am not a movie expert but it seems like directors have favorite actors (and vice-a-versa) so I would expect there to be clusters of directors and actors with a little overlap here and there.

  • $\begingroup$ How to handle the combination of director + actor for example? Another new feature? $\endgroup$ – Dmitrij Kultasev Sep 13 '18 at 11:48
  • $\begingroup$ See edit above. $\endgroup$ – bstrain Sep 13 '18 at 12:36

As bstrain explained, you can transform that column to $n_{actor}$ binary columns. It will indeed create a lot of features, but you can do dimension reduction later.

What I want to point out is, you should take care on the Year feature as well. It is also numerical valued, but sometimes you can't just simply leave it to the model. Some tree-based models can handle it well, but more other regression models will handle it in a wrong manner. In that case, you might want to manually extract features, e.g. transform it to "new", "last decades", "very old", etc., and then one-hot encode it.

  • $\begingroup$ Can you please explain what does "wrong manner" mean talking about year? $\endgroup$ – Dmitrij Kultasev Sep 13 '18 at 15:58
  • $\begingroup$ Because this feature is not ordered. I.e., 2018 and 2010 are not always in the same side of 2000, in terms of the contribution to your output. If you left it there as a simple value, either your model need to be capable to learn the non-linear contribution to output, or it will simply fail. $\endgroup$ – plpopk Sep 14 '18 at 2:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.