Python 从OneHotEncoder获取相应的功能
在使用OneHotEncoder转换功能后,我试图对数据集中的一些功能进行数据分析,结果显示功能13和功能21是最重要的功能,但我如何知道这些功能对应哪些功能 您可以使用Python 从OneHotEncoder获取相应的功能,python,machine-learning,feature-selection,one-hot-encoding,Python,Machine Learning,Feature Selection,One Hot Encoding,在使用OneHotEncoder转换功能后,我试图对数据集中的一些功能进行数据分析,结果显示功能13和功能21是最重要的功能,但我如何知道这些功能对应哪些功能 您可以使用.categories\uu属性执行此操作。这是一个普遍的例子: 将numpy导入为np 从sklearn.preprocessing导入OneHotEncoder ohe=OneHotEncoder(稀疏=False) arr=np.random.choice([‘狗’、‘猫’、‘雪貂’],10) 打印(arr) Out[1
.categories\uu
属性执行此操作。这是一个普遍的例子:
将numpy导入为np
从sklearn.preprocessing导入OneHotEncoder
ohe=OneHotEncoder(稀疏=False)
arr=np.random.choice([‘狗’、‘猫’、‘雪貂’],10)
打印(arr)
Out[100]:
数组([‘雪貂’、‘雪貂’、‘狗’、‘猫’、‘雪貂’、‘雪貂’,
“雪貂”、“狗”、“狗”],dtype='答案解决了您的问题吗?
encoded = ohe.fit_transform(arr.reshape(-1, 1))
print(encoded)
print(ohe.categories_) # this is the line you're looking for