Search code examples
pythonscikit-learnpca

What does fit, transform, and fit_transform do in PCA available in sklearn.decomposition?


I am trying to mimic the behavior of PCA class available in sklearn.decomposition.

I have wrote a method which computes the SVD but I am not sure what does fit(), tranform(), and fit_transform() do without which I'm not able to proceed further.

I think fit() computes the svd and the singular values can be accessed using the singular_values_ attribute but I don't know about the remaining two methods.


Solution

  • In the docs you can see a general explanation of fit(), transform(), and fit_transform():

    [...] a fit method, which learns model parameters (e.g. mean and standard deviation for normalization) from a training set, and a transform method which applies this transformation model to unseen data. fit_transform may be more convenient and efficient for modelling and transforming the training data simultaneously.