I have a numpy array X that has 3 columns and looks like the following:
array([[ 3791, 2629, 0],
[ 1198760, 113989, 0],
[ 4120665, 0, 1],
...
The first 2 columns are continuous values and the last column is binary (0,1). I would like to apply the StandardScaler class only to the first 2 columns. I am currently doing this the following way:
scaler = StandardScaler()
X_subset = scaler.fit_transform(X[:,[0,1]])
X_last_column = X[:, 2]
X_std = np.concatenate((X_subset, X_last_column[:, np.newaxis]), axis=1)
The output of X_std is then:
array([[-0.34141308, -0.18316715, 0. ],
[-0.22171671, -0.17606473, 0. ],
[ 0.07096154, -0.18333483, 1. ],
...,
Is there a way to perform this all in one step? I would like to include this as part of a pipeline where it will scale the first 2 columns and leave the last binary column as is.