python - Preprocessing in scikit learn - single sample - Depreciation warning -


on fresh installation of anaconda under ubuntu... preprocessing data in various ways prior classification task using scikit-learn.

from sklearn import preprocessing  scaler = preprocessing.minmaxscaler().fit(train) train = scaler.transform(train)     test = scaler.transform(test) 

this works fine if have new sample (temp below) want classify (and want preprocess in same way get

temp = [1,2,3,4,5,5,6,....................,7] temp = scaler.transform(temp) 

then deprecation warning...

deprecationwarning: passing 1d arrays data deprecated in 0.17  , raise valueerror in 0.19. reshape data either using  x.reshape(-1, 1) if data has single feature or x.reshape(1, -1) if contains single sample.  

so question how should rescaling single sample this?

i suppose alternative (not one) be...

temp = [temp, temp] temp = scaler.transform(temp) temp = temp[0] 

but i'm sure there better ways.

just listen warning telling you:

reshape data either x.reshape(-1, 1) if data has single feature or x.reshape(1, -1) if contains single sample.

for example type(if have more 1 feature):

temp = temp.reshape(1,-1)  

for 1 feature:

temp = temp.reshape(-1,1) 

Comments