如何处理在数据集中的多个列上应用一种热编码后产生的大量恐惧?

问题描述 投票:0回答:2

我正在从kaggle处理TMDB 5000电影数据集:

https://www.kaggle.com/tmdb/tmdb-movie-metadata

在预处理阶段,我使用MultiLabelBinarizer()以便对数据集中的列进行编码,如:

 - Genres, production_countries, production_companies, Cast

现在,我拥有大量功能。如何解决这个问题?

from sklearn.preprocessing import MultiLabelBinarizer() 
machine-learning linear-regression prediction feature-selection one-hot-encoding
2个回答
0
投票

使用一键编码之前,请遍历标称特征并仅选择足够频繁的值。您可以将其他值切换为字符串“ Other”。例如-如果您只想保留100个最频繁的值:

val_freq = df[your_column].value_counts() #finds the frequencies of the values and sorts them
good_vals = val_freq[:100].index #takes the top 100 values
df[your_column][~df['your_column'].isin(good_vals)]='Other' #replaces the values not in the top 100 by "Other"

0
投票

通常,对于具有高基数的分类特征,不建议使用OHE方法。例如,您可以使用“频率编码”(也仅保留最常用的标签,如上面建议的那样),“二进制编码”或“数字编码”。

所有这些都是好的解决方案,不会在数据库中创建不必要的许多列!

© www.soinside.com 2019 - 2024. All rights reserved.