Sklearn Transform Error: Expected 2d Array, Got 1d Array Instead
I use sklearn to transform data with this code. sc = MinMaxScaler() test= df['outcome'] y = sc.fit_transform(test) It show error like this. ValueError: Expected 2D array, got 1D
Solution 1:
If I remember correctly, MinMaxScalar
can accept a pandas dataframe
but not a series
, so just do test = df[['outcome']]
(dataframe with one column) instead of test = df['outcome']
(a series).
Solution 2:
MinMaxScaler required numpy input shape as (num_sample,1) but you are giving input as shape (num_sample,) Try this code :
sc = MinMaxScaler()
test= df['outcome'].values #convert to numpy arrayy = sc.fit_transform(test.reshape(-1,1))
Post a Comment for "Sklearn Transform Error: Expected 2d Array, Got 1d Array Instead"