1
$\begingroup$

I have a datset consisting of:

  1. float column (seems like continuous variable with some outliers in range $[1000, 20000]$. I plotted its density curve, looks like close to normal)
  2. integer column (seems like discrete variable with range in $[0, 100]$.
  3. categorical column with categories like $"x< 10", \;"10\leq x < 20", \;"20\leq x < 30", "x\geq 30"$. Note that these categories have a natural order.
  4. another categorical column with a total of 4 categories, but the categories here are simple labels, which don't have any natural order.
  5. target column is binary (0/1)

I'll try to fit KNN on this dataset but before doing that, I have the following conceptual concepts on data preprocessing:

  1. I'm definitely going to standardize the float column (subtract mean and divide by standard deviation)
  2. Should I standardize the integer column? If I do this, then it would change from integer to float column. This is where I'm struggling to understand whether or not it is justified to touch this column.
  3. How do I treat the first categorical columns where categories have natural order? How do I translate the categories $"x<10"$ or $"10 \leq x < 20$ so that I can feed it into sklearn's KNeighboursClassifier ?
  4. I'm going to do one hot encoding for the second categorical column, because I couldn't find anything better.

Note that before preprocessing my data, I'm going to train_test split it. So after training my model, how should I evaluate it on my test set. Will it be fine if I use the same mean/std obtained from train set to scale the float column of the test dataset, and treat the categorical columns of test set the same way I did for train set?

Please help me with these doubts as I'm a beginner in Machine Learning.

$\endgroup$
1
$\begingroup$

Should I standardize the integer column?

It doesn't matter whether it is integer or float, until and unless the feature is continuous, you can use standardization/normalization. While using algorithms like KNN which is primarily based on distance, it is better to standardize the numerical data

How do I treat the first categorical columns where categories have natural order?

First understand whether your categories are ordinal or nominal. If your categories are ordinal you can go with label encoding, otherwise one hot encoding.

How do I translate the categories "x<10" or "10≤x<20 so that I can feed it into sklearn's KNeighboursClassifier ?

If you have 20+ categories you can choose to bin them into different groups based on their relationship, which will get you out of curse of dimensionality problem.

$\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.