Skip to content
Advertisement

sklearn: how to get coefficients of polynomial features

I know it is possible to obtain the polynomial features as numbers by using: polynomial_features.transform(X). According to the manual, for a degree of two the features are: [1, a, b, a^2, ab, b^2]. But how do I obtain a description of the features for higher orders ? .get_params() does not show any list of features.

Advertisement

Answer

By the way, there is more appropriate function now: PolynomialFeatures.get_feature_names.

JavaScript

This will output as follows:

JavaScript

N.B. For some reason you gotta fit your PolynomialFeatures object before you will be able to use get_feature_names().

If you are Pandas-lover (as I am), you can easily form DataFrame with all new features like this:

JavaScript

Result will look like this:

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement