当我使用以下代码时
df_reclamos_transf = df6
X = df_reclamos_transf.drop(['CATEGORIA'], axis=1)
y = df_reclamos_transf['CATEGORIA']
X_train, X_test, y_train, y_test = train_test_split(
X, y, test_size=0.2, random_state=0)
labels = df_reclamos_transf['CATEGORIA']
encoder = LabelEncoder()
encoder.fit(labels)
for i, item in enumerate(encoder.classes_):
print(item, '=>',i)
X_train = encoder.fit_transform(X_train)
X_test = encoder.transform(X_test)
~\AppData\Local\Continuum\anaconda3\lib\site-packages\sklearn\utils\validation.py in column_or_1d(y, warn)
795 return np.ravel(y)
796
--> 797 raise ValueError("bad input shape {0}".format(shape))
798
799
ValueError: bad input shape (126527, 5)
答案 0 :(得分:0)
encoder1 = LabelEncoder()
X_train = encoder1.fit_transform(X_train)
X_test = encoder1.transform(X_test)
尝试运行此程序。您创建了一个编码器并将其安装在labels
上。然后,您为X_train
使用了相同的编码器,但其形状不同,可能会导致此问题。创建一个新的LabelEncoder
对象并尝试。