Reputation: 29
Getting error for the below code.
I am trying to perform min-max scaling for only one feature of the dataframe:
from sklearn.preprocessing import MinMaxScaler
scaler = MinMaxScaler()
train_df['training_credits']= scaler.fit_transform(train_df['training_credits']).reshape(1,-1)
test_df['training_credits']= scaler.fit_transform(test_df['training_credits']).reshape(1,-1)
X=train_df[['department','education','Employee_Acheivement','training_credits','new_age_updated_new']]
y=train_df['is_promoted']
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X,y, test_size = 0.2)
Error:-
ValueError Traceback (most recent call last)
<ipython-input-47-01a2518dfb0a> in <module>
3 #train_df=train_df.drop(['region'], axis=1)
4 #test_df=test_df.drop(['region'], axis=1)
----> 5 train_df['training_credits']= scaler.fit_transform(train_df['training_credits']).reshape(1,-1)
6 test_df['training_credits']= scaler.fit_transform(test_df['training_credits']).reshape(1,-1)
7 X=train_df[['department','education','Employee_Acheivement' ,'training_credits','new_age_updated_new']]
'
'
'
'
ValueError: Expected 2D array, got 1D array instead:
array=[49. 60. 50. ... 79. 45. 49.].
Reshape your data either using array.reshape(-1, 1) if your data has a single feature or array.reshape(1, -1) if it contains a single sample.
Can u suggest where am I going wrong?
Upvotes: 0
Views: 80
Reputation: 71
Try this:
scaler.fit_transform(train_df[['training_credits']].values)
or
scaler.fit_transform(train_df['training_credits'].values.reshape(-1,1))
Upvotes: 4