def preprocess(numerical , categorical):
imputer = SimpleImputer()
x_num = imputer.fit_transform(numerical)
scaler = StandardScaler()
x_num = scaler.fit_transform(x_num)
one_hot = OneHotEncoder()
x_cat = one_hot.fit_transform(categorical)
print('X_num Shape : ' , x_num.shape)
print('X_cat Shape : ' , x_cat.shape)
return np.concatenate((x_num,x_cat),axis = 1)
[Output] X_num Shape : (889, 2)
X_cat Shape : (889, 22)
Ошибка, отображаемая в конце: ValueError: all the input arrays must have same number of dimensions, but the array at index 0 has 2 dimension(s) and the array at index 1 has 0 dimension(s)
Я хочу, чтобы результат имел форму (889,24)
последнее предложение (массив в индекс 1 имеет 0 измерений) заставляет меня думать, что проблема связана со странными numpy массивами формы (n,) и (, n), но это не должно быть проблемой, поскольку размеры, как показано, не такие но я думаю, что мне чего-то не хватает
Я также пробовал использовать много разных функций np.hstack , np.vstack , np.column_stack
, но они либо не дают желаемого результата, либо показывают это сообщение об ошибке ValueError: all the input array dimensions for the concatenation axis must match exactly, but along dimension 1, the array at index 0 has size 2 and the array at index 1 has size 1