Polynomial features allows you to do non-linear regression/classification with a linear model.

### Caution

Polynomial Features assumes normalized inputs because x**n easily becomes INF/-INF where n is large.

# Polynomial Features

As a similar to one in Scikit-Learn, polynomial_feature(array<String> features, int degree [, boolean interactionOnly=false, boolean truncate=true]) is a function to generate polynomial and interaction features.

select polynomial_features(array("a:0.5","b:0.2"), 2);
> ["a:0.5","a^a:0.25","a^b:0.1","b:0.2","b^b:0.040000003"]

select polynomial_features(array("a:0.5","b:0.2"), 3);
> ["a:0.5","a^a:0.25","a^a^a:0.125","a^a^b:0.05","a^b:0.1","a^b^b:0.020000001","b:0.2","b^b:0.040000003","b^b^b:0.008"]

-- interaction only
select polynomial_features(array("a:0.5","b:0.2"), 3, true);
> ["a:0.5","a^b:0.1","b:0.2"]

select polynomial_features(array("a:0.5","b:0.2","c:0.3"), 3, true);
> ["a:0.5","a^b:0.1","a^b^c:0.030000001","a^c:0.15","b:0.2","b^c:0.060000002","c:0.3"]

-- interaction only + no truncate
select polynomial_features(array("a:0.5","b:1.0", "c:0.3"), 3, true, false);
> ["a:0.5","a^b:0.5","a^b^c:0.15","a^c:0.15","b:1.0","b^c:0.3","c:0.3"]

-- interaction only + truncate
select polynomial_features(array("a:0.5","b:1.0","c:0.3"), 3, true, true);
> ["a:0.5","a^c:0.15","b:1.0","c:0.3"]

-- truncate
select polynomial_features(array("a:0.5","b:1.0", "c:0.3"), 3, false, true);
> ["a:0.5","a^a:0.25","a^a^a:0.125","a^a^c:0.075","a^c:0.15","a^c^c:0.045","b:1.0","c:0.3","c^c:0.09","c^c^c:0.027000003"]

-- do not truncate
select polynomial_features(array("a:0.5","b:1.0", "c:0.3"), 3, false, false);
> ["a:0.5","a^a:0.25","a^a^a:0.125","a^a^b:0.25","a^a^c:0.075","a^b:0.5","a^b^b:0.5","a^b^c:0.15","a^c:0.15","a^c^c:0.045","b:1.0","b^b:1.0","b^b^b:1.0","b^b^c:0.3","b^c:0.3","b^c^c:0.09","c:0.3","c^c:0.09","c^c^c:0.027000003"]
>


Note: truncate is used to eliminate unnecessary combinations.

# Powered Features

The powered_features(array<String> features, int degree [, boolean truncate=true] ) is a function to generate polynomial features.

select powered_features(array("a:0.5","b:0.2"), 3);
> ["a:0.5","a^2:0.25","a^3:0.125","b:0.2","b^2:0.040000003","b^3:0.008"]