1
$\begingroup$

I am trying to do regression for the first time using qualitative and quantitative data using scikit learn.

I want to find correlations between user demographic features like age range, country, gender (all categorical), account age (numerical) and their overall listening time (numerical).

I am considering one-hot-encoding the categorical variables or dummy encoding them. I think one-hot-encoding makes sense for regression, but I don't have space to have that many additional columns. In this case, I prefer dummy encoding and I know how to do it. However, I don't know how to use the dummy numbers when doing linear regression using scikit learn.

$\endgroup$
4
  • 3
    $\begingroup$ I think one-hot-encoding or dummy encoding they are the synonyms. Dummy is an old established term in statistics. I suppose one-hot-encoding is coming from computer science but I'm not sure. $\endgroup$
    – ttnphns
    Commented Dec 25, 2016 at 22:43
  • 5
    $\begingroup$ dummy and one hot are not the same ! Dummy creates n-1 variables and one hot creates n. $\endgroup$
    – meh
    Commented Jun 7, 2017 at 16:33
  • 1
    $\begingroup$ @aginensky, I don't agree with your terminology. It is strange that same coding should be termed differently depending on whether there is or is not a subsequent removal of one variable from the set. $\endgroup$
    – ttnphns
    Commented Mar 17, 2019 at 2:22
  • $\begingroup$ @ttnphns It's not my terminology. Look up dummy coding for lm . The point is that if you don't remove one variable, the design matrix will be singular. Have fun using one-hot encoding on a regression model (on the theory that it's the same as one dummy encoding). $\endgroup$
    – meh
    Commented Mar 18, 2019 at 15:54

1 Answer 1

1
$\begingroup$

One hot encoding would be a preliminary step toward dummy coding or effect coding or any other parameterization of a categorical variable. I don't know anything about scikit-learn (and questions about code are off topic here) but statistical programs such as SAS, R, SPSS, etc. do this encoding for you. It simply takes a single column of labels and turns it into k columns of 0's and 1's where there are k different labels.

You then have to choose what parameterization you want and which label you would like to use as your reference category. This has been discussed here before and will also be covered in any basic regression book.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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