如果您在编码数据集数组时遇到困难, 可以尝试以下方法进行处理:
以下是示例代码,其中使用pandas库中的“get_dummies”函数对“categorical_feature”列进行one-hot编码:
import pandas as pd
df = pd.DataFrame({'categorical_feature': ['A', 'B', 'C', 'A']})
df_encoded = pd.get_dummies(df, columns=['categorical_feature'])
print(df_encoded)
输出:
categorical_feature_A categorical_feature_B categorical_feature_C
0 1 0 0
1 0 1 0
2 0 0 1
3 1 0 0