First of all, let's import PolynomialFeatures:
from sklearn.preprocessing import PolynomialFeatures
Then let's create an object to make a list of all the possible feature combinations/powers:
poly = PolynomialFeatures(n)
where we have already defined n as whatever max degree we want to try till.
Let's say we want to get the polynomial features for our current training data set. Assuming that we have performed the standard train-test split, and set train_x as the set of training inputs:
train_x_poly = poly.fit_transform (train_x)
That's all the training data, with polynomial/powered features, so now we can just feed that to the standard linear regression. Still, we'll do Polynomial Regression in a following Notebook.
Copyright © 2021 Code 4 Tomorrow. All rights reserved. The code in this course is licensed under the MIT License. If you would like to use content from any of our courses, you must obtain our explicit written permission and provide credit. Please contact firstname.lastname@example.org for inquiries.