Is it good to use .fit to xtest when we use PolynomialFeatures() of sklearn?
My teacher did this in class, and I'm wondering is this ok to use .fit_transform with xtest? It shouldn't just be poly.transform(xtest)
Teacher's Code
from sklearn.preprocessing import PolynomialFeatures
poly = PolynomialFeatures(degree=3)
xtrain_poly = poly.fit_transform(xtrain)
xtest_poly = poly.fit_transform(xtest)
As I think it should be:
from sklearn.preprocessing import PolynomialFeatures
poly = PolynomialFeatures(degree=3)
xtrain_poly = poly.fit_transform(xtrain)
xtest_poly = poly.transform(xtest)
As an optional question, what does fit() and transform() do in PolynomialFeatures? transform() scales the data based on some value(s) returned by fit(), such as when using sklearn.preprocessing.StandardScaler?
Topic test training scikit-learn
Category Data Science