Вот простой пример:
Код: Выделить всё
import numpy as np
import pandas as pd
from sklearn.preprocessing import PolynomialFeatures
# Example data:
X = np.arange(6).reshape(3, 2)
# Works fine
poly = PolynomialFeatures(2)
pd.DataFrame(poly.fit_transform(X))
0 1 2 3 4 5
0 1 0 1 0 0 1
1 1 2 3 4 6 9
2 1 4 5 16 20 25
например,
Код: Выделить всё
# Use previous dataframe
X2 = X.copy()
# Categorical feature will be handled
# by a one hot encoder in another feature generation step
X2['animal'] = ['dog', 'dog', 'cat']
# Don't try to poly transform the animal column
poly2 = PolynomialFeatures(2, cols=[1,2]) #
Подробнее здесь: [url]https://stackoverflow.com/questions/47664061/how-to-apply-polynomial-transformation-to-subset-of-features-in-scikitlearn[/url]
Мобильная версия