As the title says, Does the linearregression() handle the dummy Variable trap by itself ? or do I need to program its solution implicitly? Also, does the dummy variable trap occurs with all datasets that include dummy variables ( for sure after encoding the categorical data in the dataset) or just in specific scenarios?


1 Answer 1


I assume you are using sklearn's LinearRegression.

The answer is no:

The idea behind the dummy trap is if one column has labels [1,2 or 3], Then you only need two columns to represent the information as [0,0] , [0,1] or [1,0]. So yes it applies to all feature columns which get one-hot encoded.

This is not true if the target column was multi-label as dropping a label here would means a low prediction probability in one class would mean a high prediction of the another class but would completely ignore prediction of the third.

If you are creating the one-hot encoding on the features you will have to manually delete one for each multi-label column you had.

Easier yet is the get_dummies method (with drop_first = True)


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.