Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/285.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/multithreading/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 从OneHotEncoder获取相应的功能_Python_Machine Learning_Feature Selection_One Hot Encoding - Fatal编程技术网

Python 从OneHotEncoder获取相应的功能

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

在使用OneHotEncoder转换功能后,我试图对数据集中的一些功能进行数据分析,结果显示功能13和功能21是最重要的功能,但我如何知道这些功能对应哪些功能

您可以使用
.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