1
$\begingroup$

I have a training dataframe dfTrain and the output of dfTrain.head() is shown below:

    C0 C1                              C2   C3 C4  C5               C6  
0   1  73                 Not in universe   0   0   0  Not in universe
1   2  58  Self-employed-not incorporated   4  34   0  Not in universe
2   3  18                 Not in universe   0   0   0      High school
3   4   9                 Not in universe   0   0   0  Not in universe
4   5  10                 Not in universe   0   0   0  Not in universe

There are total 38 features and they are both categorical and numerical. Ignoring C1 and scaling numerical features, I am trying to build a Logistic Regression model. Since, the dataframe has categorical features, I am creating another dataframe which has dummy variables.

X = pd.get_dummies(dfTrain)

The shape of X now has 160 features which is much more than that of dfTrain.

Then I pass X and y (where y is target variable) to Logistic Regression Classifier

modelLogistic = LogisticRegression(C=10**-2, class_weight = 'balanced')

modelLogistic.fit(X, y)

The reason to use class_weight = 'balanced' is that there are 17 classes in y and highly imbalanced.

My question is: is my approach correct? Am I missing anything?

$\endgroup$
1
$\begingroup$

Yes, your approach seems to be right. The only thing that I would like to point out is that while it is desirable to convert categorical features to dummies but if you don't have enough memory then you can even consider to factorize your categorical variables. You can read about it more here. Also, just make sure that after converting to dummies, the number of features are reasonable compared to the number of training samples.

$\endgroup$
1
  • $\begingroup$ So if I do this conversation, I will still have to convert features into numerical values? $\endgroup$ – chintan s Aug 14 '16 at 18:55

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.