Search code examples
python-3.xmachine-learningscaling

How to scale dependent variable using StandardScaler


When I trying to scale my dependent variable using sklearn StandardScaler, I'm gtting error.

My code is_

# Scale the data using sklearn StandardScaler
from sklearn.preprocessing import StandardScaler

#Creating object of StandardScaler
scale=StandardScaler()

# Scale the dependent variable data using sklearn StandardScaler
y = scale.fit_transform(y)
np.set_printoptions(threshold=np.inf)
y

Getting error like this_

ValueError: Expected 2D array, got 1D array instead:

If I reshape the array can it effect dataframe or model training....


Solution

  • if necessary, you can reshape y to be a 2d array with

    y_2d = y.reshape(-1, 1)
    y_2d = scale.fit_transform(y_2d)
    

    You might not want to scale your y values for several reasons as described here