text_plain_output_1.png
import pandas as pd

import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

training_set = pd.read_parquet('/kaggle/input/unswnb15/UNSW_NB15_training-set.parquet')
testing_set = pd.read_parquet('/kaggle/input/unswnb15/UNSW_NB15_testing-set.parquet')

training_set.dtypes

training_set.attack_cat.value_counts()

training_set.dtypes

target = 'label'
features = list(training_set.columns.difference([target]).values)

training_set.drop(columns=['attack_cat'], inplace=True)
testing_set.drop(columns=['attack_cat'], inplace=True)

training_set.isna().sum()

cat_cols = [col for col in training_set.columns if training_set[col].dtype == 'category']
cat_cols

def train_test_category_union(feature):
    tcl = len(training_set[feature].cat.categories)
    tcll = len(testing_set[feature].cat.categories)
    feature_cat_union = training_set[feature].cat.categories.union(testing_set[feature].cat.categories)
    training_set[feature] = training_set[feature].cat.set_categories(feature_cat_union)
    testing_set[feature] = testing_set[feature].cat.set_categories(feature_cat_union)

for f in cat_cols:
    train_test_category_union(f)