4
$\begingroup$

I am a beginner in Machine Learning. I have been inspecting some kernels at Kaggle. Some of these answers use factors in their predictive models while others split them into dummy variables (this happens especially when the code is written in Python). I am using R. Which approach is better?

$\endgroup$
  • $\begingroup$ I think that when you use factors, then R automatically transforms these to dummies ? $\endgroup$ – user83346 May 3 '17 at 9:35
  • 1
    $\begingroup$ It depends on the model. My guess is that internally does not matter because each model converts factors to dummy variables. For example, the rpart package (decision tree model) gives you dummy variables when looking at variables importance. But Random Forest gives you factors. So I think that as long as you classify the categorical variables correctly (i.e. as factors), it does not really matter. $\endgroup$ – Antonio Serrano May 3 '17 at 10:14
1
$\begingroup$

It does not really matter. Factors are internally coded as Dummy variables in R. If you are not familiar with statistics and econometrics I suggest you to use factor variables (be sure that they are correctly coded with

factor(x, levels)

I suggest you this because you may include all dummy variables in the model and cause multicollinearity. In addition to this, you do not have to bother about creating the dummy coding, you can save up some lines of code.

If you want more information on this you can look here, here or here. In case you decide to recode it as dummy variables you can have a look here or here.

Hope this helps! Un saludo! ;)

$\endgroup$
  • 1
    $\begingroup$ Exactly. That's what I thought. But I wanted to confirm it. Many thx! Muchas gracias! $\endgroup$ – Antonio Serrano May 3 '17 at 10:15
  • $\begingroup$ @AntonioSerrano If you liked the answer don't forget to upvote it! Muchas gracias, cualquier duda me comentas! :) $\endgroup$ – adrian1121 May 4 '17 at 8:37
  • $\begingroup$ I tried that yesterday @adrian1121. But since I am new at Cross Validated, the system does not allow me to upvote yet. It says "Thanks for the feedback! Votes cast by those with less than 15 reputation are recorded, but do not change the publicly displayed post score." Can't I export my profile from Stack overflow to Cross Validated? $\endgroup$ – Antonio Serrano May 4 '17 at 9:02
  • 2
    $\begingroup$ Sure don't worry! You can export your profile but not your points and badges. Every forum is independent from each other. $\endgroup$ – adrian1121 May 4 '17 at 9:09
  • $\begingroup$ Got it. When I get the necessary points, I will upvote your answer. ¡Gracias de nuevo! $\endgroup$ – Antonio Serrano May 4 '17 at 9:11

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.