我已使用以下代码对我的分类功能进行OneHotEncode。但是,在运行代码并检查形状后,它只有 2列(事实并非如此)。代码有什么问题吗?
features_cat_cols = ['loan_type', 'property_type', 'loan_purpose', 'occupancy', 'preapproval', 'msa_md', 'state_code', 'county_code',
'applicant_ethnicity', 'applicant_race', 'applicant_sex', 'lender', 'co_applicant']
def encode_string(cat_features):
## Now, apply one hot encoding
ohe = preprocessing.OneHotEncoder(categories='auto')
encoded = ohe.fit_transform(cat_features.values.reshape(-1,1)).toarray()
pdfn = ohe.get_feature_names()
print(pdfn)
return encoded
for col in features_cat_cols:
Features = encode_string(df[col])