Python 编码分类数据-有更好的方法吗?

Python 编码分类数据-有更好的方法吗?,python,machine-learning,encoding,Python,Machine Learning,Encoding,我一直在学习一门机器学习课程,当然,通过使用不同版本的Python和它要求我使用的不同版本的库,我使它变得更加复杂 我的课程说使用LabelEncoder和OneHotEncoder来创建虚拟变量 from sklearn.preprocessing import LabelEncoder, OneHotEncoder labelencoder_X = LabelEncoder() X[:, 0] = labelencoder_X.fit_transform(X[:, 0]) onehotenc

我一直在学习一门机器学习课程,当然,通过使用不同版本的Python和它要求我使用的不同版本的库,我使它变得更加复杂

我的课程说使用LabelEncoder和OneHotEncoder来创建虚拟变量

from sklearn.preprocessing import LabelEncoder, OneHotEncoder
labelencoder_X = LabelEncoder()
X[:, 0] = labelencoder_X.fit_transform(X[:, 0])
onehotencoder = OneHotEncoder(categorical_features = [0])
X = onehotencoder.fit_transform(X).toarray()
我的控制台声明分类_特性将在不久的将来被删除,我应该部署ColumnTransformer

在谷歌上呆了一段时间后,我想出了这个代码

from sklearn.preprocessing import OneHotEncoder
from sklearn.compose import ColumnTransformer
encod = ColumnTransformer([('encoder', OneHotEncoder(), [3])], remainder='passthrough')
x = np.array(encod.fit_transform(x))
x = x.astype(float)

这段代码似乎为我提供了我认为需要的浮点数组(很抱歉,如果我使用了不正确的术语。我对这一切都很陌生),但我想知道我是否可以使用相同的工具集做得更好,或者我将来是否会遇到问题。

您能进一步解释您的问题吗?性能更好?在使用方面?还是别的?你能解释一下你的问题吗?性能更好?在使用方面?否则呢?