gpt4 book ai didi

python - 我们可以对 spyder 中的分类数据使用不带标签编码的直接 One Hot Encoding

转载 作者:太空宇宙 更新时间:2023-11-04 01:57:27 26 4
gpt4 key购买 nike

对于spyder中的分类数据,我们可以直接使用One Hot Encoding而不使用Label Encoding吗?

最佳答案

是的,你可以。另外,它与 Spyder 无关,Spyder 只是一个 IDE。这是一个例子。

>>> X = [['India', 1], ['USA', 2], ['India', 3]]
>>> from sklearn.preprocessing import OneHotEncoder
>>> enc = OneHotEncoder()
>>> enc.fit(X)
OneHotEncoder(categorical_features=None, categories=None,
dtype=<class 'numpy.float64'>, handle_unknown='error',
n_values=None, sparse=True)
>>> enc.get_feature_names()
array(['x0_India', 'x0_USA', 'x1_1', 'x1_2', 'x1_3'], dtype=object)

关于python - 我们可以对 spyder 中的分类数据使用不带标签编码的直接 One Hot Encoding,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56481128/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com