arezoo_moradi:

(But when I run this line of code y_test = pd.get_dummies(y_test), instead of being categorized into 5 classes, it shows me the same 22 features, while I did the same thing train data (target = pd.get_dummies(target) and correct result), it using for the test data.)


As explained, you test data frame contains more unique classes, which are not in the attack map and won’t be replaced.



 arezoo_moradi:

I replaced this line kdd_t[‘class’] = kdd[‘class’].replace(attack_map) but you said this work is incrocet.


Don’t do this, as you are reusing the training dataset and all your experiments will be invalid.
If you want to remove the additional classes from the test DataFrame, this code should work:
kdd['class'] = kdd['class'].replace(attack_map)
unique_classes = kdd['class'].unique()
kdd_t['class'] = kdd_t['class'].replace(attack_map)

# Drop unwanted classes
unique_classes_test = kdd_t['class'].unique()
drop_class_indices = (~np.in1d(unique_classes_test, unique_classes)).nonzero()[0]
for drop_class_idx in drop_class_indices:
    kdd_t = kdd_t[kdd_t['class'] != unique_classes_test[drop_class_idx]]