升维, 意味着要加特征, 为了简单一点, 我们可以使用sklearn中的多项式特征。
语法
Init signature:
PolynomialFeatures(
degree=2,
interaction_only=False,
include_bias=True,
order='C',
)
- degree=2 自变量最高的次数, 默认为2, 值越大, 则组合出来的特征越多。
- interaction_only=False,是否只产生交互的特征, 默认False
- include_bias=True是否产生与截距项相乘的 x 0 x_0 x0
import numpy as np
# 导入多项式特征类
from sklearn.preprocessing import PolynomialFeatures
举个例子
x = np.array([[1, 2], [4, 5]])
x
输出
poly = PolynomialFeatures(degree=2)
poly.fit_transform(x)
输出
我们就把数据从二维升到了六维。