7
$\begingroup$

I am wondering if integer predictor data should be treated as categorical (thus requiring encoding) or continuous. For example, if the range of a given predictor X is all integers between 1 and 230, can I treat it as a continuous variable, or should I encode it to obtain 230 (or maybe 229) new dummy variables? The end goal of the analysis is to perform regression or classification.

$\endgroup$
  • $\begingroup$ You'll have to be a little more specific about your setting. Sometimes it's better to treat as categorical, sometimes as continuous. $\endgroup$ – Dougal Feb 12 '17 at 3:02
  • $\begingroup$ @Dougal What additional information would you need to elaborate on your answer? Suppose you're trying different models (e.g., neural networks, kernel regression, generalized boosted trees) on a mixed data set. Some predictors are "obviously" categorical (e.g., strings), while others may be naturally integer values. $\endgroup$ – Bruno Feb 12 '17 at 3:06
  • $\begingroup$ Glen is correct. But you can also transform one or more continuous variables into categorical if that makes your analysis more meaningful. $\endgroup$ – SmallChess Feb 12 '17 at 7:08
9
$\begingroup$

In general, neither is suitable. Integers are discrete, not continuous, but to treat them as nominal categories would throw out most of the information, and even treating them as ordinal could lose quite a bit.

In some situations one or the other might be okay, but it's nearly always better to treat them as what they are -- for example, if the data are counts, use an analysis suited for counts.

As an example, say you wanted to perform a regression on count data; there are a number of count-regression models, including (but not limited to) Poisson, binomial and negative binomial regression.


In the case of integer IVs (predictors) there's no more need to do anything to integers than there is to do anything to some continuous predictor -- at least not on the basis that they're integers.

In both the case of integer predictors and continuous predictors the critical thing is your understanding (whether from theory, previous studies or some other means) of how the predictor variable might relate to the response, rather than the fact that they're integers.

$\endgroup$
  • $\begingroup$ Thanks! I wasn't aware of regression for count data. I have mixed data in my problem. Some columns in the data set are obvious multi-class categories (strings), while others are integers (e.g., age, number of occurrences of a category), and some may be binary categories. But in general, there may be some continuous (real) data as well. It seems that the R package pscl has some related functions (hurdle and zeroinfl), but I'm wondering if the fact that I have mixed data would require a different approach... any comments? $\endgroup$ – Bruno Feb 12 '17 at 4:16
  • $\begingroup$ @Bruno It doesn't matter if the IV's are counts (any more than it does in ordinary regression), it's only of consequence what the DV is $\endgroup$ – Glen_b Feb 12 '17 at 4:20
  • $\begingroup$ It depends on the problem. I'm currently testing some models for binary classification and ordinary regression (different problems, of course). I'm just in doubt of how to deal with certain predictors. $\endgroup$ – Bruno Feb 12 '17 at 4:23
  • $\begingroup$ Why would you need to do anything to them? $\endgroup$ – Glen_b Feb 12 '17 at 4:27
  • $\begingroup$ That's my question! :) Before feeding the data to the model, I'm wondering what preprocessing I should do to some of the "non-obvious" predictors. As I mentioned, some may be integer numbers (and in some cases I may know their support). $\endgroup$ – Bruno Feb 12 '17 at 4:58
2
$\begingroup$

It really depends on context.

If the integer variable has some inherent ordering to it, for example it could be colours where lower numbers represent "darker shades" and higher numbers represented "lighter shades", then treating it as a continuous variable is almost certainly preferable. Not only would it make more sense, but you're eliminating some 200 variables from your model which is a huge bonus.

On the other hand if these integers have no inherent ordering, say for example they represent plots of land, then they should be treated as a categorical variable. It would make no sense to treat them as a continuous variable since its value is independent of the property of the variable you're interested in.

$\endgroup$
  • $\begingroup$ I see... is "age" typically considered continuous? Also, one of the predictors correspond to the number of occurrences of a given category as part of the support of another predictor. $\endgroup$ – Bruno Feb 12 '17 at 4:20
0
$\begingroup$

You do not need to do any of the 2 you stated. What you can do is regression. In R in glm you have option to set the family attribute in that you can set your preference. For example when you consider normal regression family = gaussian and if you want count type target variable as you explained in question then I think you need to set it as binomial(please check it once), but yes this is how your model will consider your target as count type rather then continuous or categorical.

$\endgroup$

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.