Feature Extraction in the dataset below

In this dataset should i encode the columns which have string datatype ?

For example in car_ownership shall i replace “no” with 0 and “yes” with 1 ?

What would be an ideal approach to extract features from this dataset?

hey @samalprathamesh123 ,
yeah you can encode them in that way.

Actual there is no ideal way or perfect way to do so , it depends upon what model you are going to use further.
but some things that you can try is.

  1. Label Encode them ( the above way )
  2. One Hot encode
  3. Target Encode

and further you can go for other feature extraction techniques to generate more features.

Got the logic sir. Thank You. One more doubt was that when i am using Decision Tree Classifier it works fine but upon using Random forests the prediction contains only zero values. Is there any reason to it ?

it might be because the model is getting overfitted.
try using class weights , if its is highly unbalanced .

got it. by the could you tell me just the steps that i need to follow in order to work with this dataset. like should i take the top 5 features and make a model or something else. i am bit confused because categorical data is also present.

i tried encoding the categorical data into numerics but its lowering the accuracy.

thank you.

i have done with the encoding

Now using feature selection i have selected top 7 features out of 12 features but this error is coming when i am training the data : “ValueError: Number of features of the model must match the input. Model n_features is 7 and input n_features is 12”. I have done the feature selection process but i dont know how to train the data as the number of features in train and test is different and this error is coming

hey @samalprathamesh123 ,
its not always that you need to select a bunch of features only.
The selection and feature engineering depends highly on what model you prefer to choose .
For example if you choose linear regression , then it has an assumption that the data should be linearly independent and should mean as to be 0 and Std to be 1.

So , similarly tree models have different workings and learn in a different manner.
so you need to quite confident and good on selecting those features.

for this ,
you might have got the selected features , but you also need to select those only from the test data too , so that your model can work.

oh got it . actually i have two different files one is for training data and other is for the test data. so now while predicting i should use only those columns of test data which are present in training data /

sir is there any way i can share my notebook to you and you could just have a look whether my approach is correct or not ? I shall be grateful :slight_smile:

yeah do one thing
just upload your data and code on github and share me the link here

Sure I will do that asap

some tips:

  1. Before using SelectKBest and Chi-square , first understand how do they work. There working depends a lot on data. So , sometimes they might be good , sometimes don’t.

  2. instead of factorize , use LabelEncoder ( from sklearn.preprocessing )

  3. for testing , you have those seven_features. so just do , test_data[seven_features ] it will work.

Thank you for your tips. I have noted these. I just want to ask whether the overall approach of solving the problem (in the notebook)is somewhat excluding the points you mentioned , since i will now correct these points mentioned by you. Another doubt was that you mentioned to use test_data[seven_features] but i have already used it. can you please specify the exact line wherein i need to change this ?

no it isn’t , your approach is quite good.
Its just some improvements.

its correct.
i didn’t checked that.

got it. Thank you so much for the help. :slight_smile:

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.

Good evening sir. I have some more doubts in the same problem statement. Actually my ROC AUC score is 0.74 and I want to improve this score to 0.80+ . Can you please help me out. I am attaching the github link for the updated files.