PolynomialFeatures transform vs fit_transform

Hello -
In the /notebooks/C2W3_Lab_01_Model_Evaluation_and_Selection.ipynb

I see that both “transform” and “fit_transform” functions are used – as if they are interchangeable. This is confusing. In my mind, there is no fitting needed. And it should be just “transform”.

Please elaborate.

Instantiate the class to make polynomial features

poly = PolynomialFeatures(degree=2, include_bias=False)

Compute the number of features and transform the training set

X_train_mapped = poly.fit_transform(x_train)

Add the polynomial features to the cross validation set

X_cv_mapped = poly.transform(x_cv)

Also here:

Add polynomial features

degree = 1
poly = PolynomialFeatures(degree, include_bias=False)
X_train_mapped = poly.fit_transform(x_train)
X_cv_mapped = poly.transform(x_cv)
X_test_mapped = poly.transform(x_test)

Why do we use “fit_transform” for training set – and “transform” for cv and test?

BTW, it makes sense to use the “fit_transform” for scaling function – for the training set – and then use “transform” to scale the validation and test set. I have no confusion there.

Hello @rkranjan,

I think there is another question almost the same as yours. Please refer to my answer there about your questions. We can continue to discuss here or there if you have any follow-ups.