Preprocessing in scikit learn - single sample - Depreciation warning

前端 未结 6 2056
礼貌的吻别
礼貌的吻别 2020-11-27 05:01

On a fresh installation of Anaconda under Ubuntu... I am preprocessing my data in various ways prior to a classification task using Scikit-Learn.

from sklear         


        
相关标签:
6条回答
  • 2020-11-27 05:38

    This might help

    temp = ([[1,2,3,4,5,6,.....,7]])
    
    0 讨论(0)
  • 2020-11-27 05:38

    .values.reshape(-1,1) will be accepted without alerts/warnings

    .reshape(-1,1) will be accepted, but with deprecation war

    0 讨论(0)
  • 2020-11-27 06:00

    Well, it actually looks like the warning is telling you what to do.

    As part of sklearn.pipeline stages' uniform interfaces, as a rule of thumb:

    • when you see X, it should be an np.array with two dimensions

    • when you see y, it should be an np.array with a single dimension.

    Here, therefore, you should consider the following:

    temp = [1,2,3,4,5,5,6,....................,7]
    # This makes it into a 2d array
    temp = np.array(temp).reshape((len(temp), 1))
    temp = scaler.transform(temp)
    
    0 讨论(0)
  • 2020-11-27 06:01

    I faced the same issue and got the same deprecation warning. I was using a numpy array of [23, 276] when I got the message. I tried reshaping it as per the warning and end up in nowhere. Then I select each row from the numpy array (as I was iterating over it anyway) and assigned it to a list variable. It worked then without any warning.

    array = []
    array.append(temp[0])
    

    Then you can use the python list object (here 'array') as an input to sk-learn functions. Not the most efficient solution, but worked for me.

    0 讨论(0)
  • 2020-11-27 06:01

    You can always, reshape like:

    temp = [1,2,3,4,5,5,6,7]
    
    temp = temp.reshape(len(temp), 1)
    

    Because, the major issue is when your, temp.shape is: (8,)

    and you need (8,1)

    0 讨论(0)
  • 2020-11-27 06:02

    Just listen to what the warning is telling you:

    Reshape your data either X.reshape(-1, 1) if your data has a single feature/column and X.reshape(1, -1) if it contains a single sample.

    For your example type(if you have more than one feature/column):

    temp = temp.reshape(1,-1) 
    

    For one feature/column:

    temp = temp.reshape(-1,1)
    
    0 讨论(0)
提交回复
热议问题