Using Prince library for MCA and FAMD in python

Viewed 3922

How to perform Factor Analysis of Mixed Data (FAMD) on the train and test datasets?

Generally, to apply sklearn PCA the following code is used:

pca=PCA(n_components=30).fit(X_train)
PC_train=pca.transform(X_train)
PC_test=pca.transform(X_test)

However, when I use the prince package the .transform() cannot be applied to the test set. It gives value error as shown below?

from prince import FAMD
famd = FAMD().fit(X_train)
PC_train=famd.transform(X_train)
PC_test=famd.transform(X_test)

enter image description here

1 Answers

FAMD has to be fitted (using .fit()) on the data and then the famd.transform() can be applied on that same data. You should use:

famd = FAMD().fit(X_test)
PC_test=famd.transform(X_test)
Related