Difference between fit and fit-transform

while I was doing the lab for model evaluation there were som places where the code had fit and at other fit-transform(eg. in scaling the data). I am really confused what is the difference between these two, and when to use which one

Hi @Madhur_Thakur

  • The fit() method helps in fitting the training dataset into an estimator (ML algorithms).
  • The transform() helps in transforming the data into a more suitable form for the model.
  • The fit_transform() method combines the functionalities of both fit() and transform().

The fit_transform() method is basically the combination of the fit method and the transform method, This method simultaneously performs fit and transform operations on the input data and converts the data points.Using fit and transform separately when we need them both decreases the efficiency of the model.
like this code

from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
# split training and testing data
xtrain,xtest,ytrain,ytest= train_test_split(
stand= StandardScaler()
Fit_Transform = stand.fit_transform(xtrain)

Best Regards,