What is the difference between fit & fit_transform in sklearn?



In python sklearn models we use fit method to fit a model. What it does backstage is, it computes the mean and standard deviation to be used in future. Please note that it only does the computation, it doesn't return anything. 

Whereas the transform method does return something. It uses the previously computed mean & std to scale the data passed to it as argument. 

fit_transform() is used when we want to do both at the same time. 

When to use which one:


You will notice, fit_transform is in use in case of training data (i.e. X_train). For test data, only tranform() is used, as the computation is carried out on train data already.

fit(), transform(), fit_transform() : train data
transform() : test data