I have been using an online ML course with code-along style videos. In one of the videos where it was required to implement feature scaling, the instructor said it was necessary to create 2 separate standard scaler objects - 1 for the feature (there was only 1 feature) and 1 for the label - to scale the data. However, this doesn't make sense to me because as far as my intuition goes, calling the fit_transform method a second time will completely overwrite the previous fit. I asked this question on that course's Q&A forum but the people answering questions there said if we didn't create 2 separate objects it would somehow scale the data under a combined effect of the features and the label, which, again, is something I can't wrap my head around.
I tested this and at least as far as this dataset is concerned, my intuition was correct:
from sklearn.preprocessing import StandardScaler
scaler = StandardScaler()
X_sc = scaler.fit_transform(X)
y_sc = scaler.fit_transform(y)
print(y_sc)
The output I got was:
[[-0.72004253]
[-0.70243757]
[-0.66722767]
[-0.59680786]
[-0.49117815]
[-0.35033854]
[-0.17428902]
[ 0.17781001]
[ 0.88200808]
[ 2.64250325]]
And then using 2 separate scaler objects:
scaler_x = StandardScaler()
scaler_y = StandardScaler()
X_sc2 = scaler_x.fit_transform(X)
y_sc2 = scaler_y.fit_transform(y)
print(y_sc2)
The output:
[[-0.72004253]
[-0.70243757]
[-0.66722767]
[-0.59680786]
[-0.49117815]
[-0.35033854]
[-0.17428902]
[ 0.17781001]
[ 0.88200808]
[ 2.64250325]]
The same answer. To 8 decimal places.
I still don't know if I'm correct though, because the teaching assistants on that forum seem strangely adamant on their explanation. They haven't replied since I showed them screenshots of my output. I know this is something very trivial and it might come across as immature that I'm pursuing such a small thing to such a great extent but it really gets on my nerves when people go around spreading either wrong or partially correct information. I am completely open to the idea that I could be wrong too but to arrive at that conclusion I would also want a proper explanation as to why my understanding is wrong.