我想更深入地了解scikit中PolynomialFeatures类中的方法.fit_transform()输出的内容 .
我知道该方法正在做两件事:1)通过将数据拟合到回归算法来为数据生成模型,以及2)基于1中找到的模型创建新数据 .
但我不理解的是输出 . 这是我的代码:
import numpy as np
import pandas as pd
from sklearn.model_selection import train_test_split
np.random.seed(0)
n = 15
x = np.linspace(0,10,n) + np.random.randn(n)/5
y = np.sin(x)+x/6 + np.random.randn(n)/10
X_train, X_test, y_train, y_test = train_test_split(x, y, random_state=0)
X_train1 = X_train.reshape(11,1)
y_train1 = y_train.reshape(11,1)
def answer_one():
from sklearn.linear_model import LinearRegression
from sklearn.preprocessing import PolynomialFeatures
poly1 = PolynomialFeatures(degree=1)
X_poly1 = poly1.fit_transform(X_train1)
return X_poly1
answer_one()
我得到的输出是:
array([[ 1. , 10.08877265],
[ 1. , 3.23065446],
[ 1. , 1.62431903],
[ 1. , 9.31004929],
[ 1. , 7.17166586],
[ 1. , 4.96972856],
[ 1. , 8.14799756],
[ 1. , 2.59103578],
[ 1. , 0.35281047],
[ 1. , 3.375973 ],
[ 1. , 8.72363612]])
我假设每个迷你数组中的每个第二个数字是由模型计算的值,但我不明白每个1是什么?