我正在尝试为多项式的幂在 2 到 10 之间的数据集找到最佳多项式回归。所以回归最多可以有一个 x 10项。数据集本身只是一组 x 和 y 对,如下所示:
1,15.3
2,66.0
3,272.5
4,814.8
据我了解,进行多项式回归的正常方法是简单地将幂变换应用于 x 向量(即,将向量中的每个元素的 6 次方),将此向量添加到数据集中,然后处理此变换向量作为另一个自变量。
但是,如果我以足够高的功率(通常为 6 及以上)尝试这种方法,我的回归库(Ruby 的 statsample)会告诉我“回归量是线性相关的”,并引发错误。我知道从技术上讲,x 向量相互依赖,因为它们是相互派生的,但它肯定不是线性依赖(其中一个与另一个相同乘以标量)。这是怎么回事?这是什么意思?
作为一个例子,这是我在 Ruby 中的代码示例(有人告诉我,这个库很像 R,但是对于所有 R 用户来说):
# Read the dataset (like an R data frame??) containing just x and y (see the example above)
ds = CSV.read(file_name)
# For each possible polynomial power between 2 and 10, add a new vector which consists
# of the x vector to that power, and then run a regression
(2..10).each do |i|
# Add a vector called x2, x3, x4 etc. and apply the power transformation
ds.add_vector("x#{i}", ds["x"].map{ |x| x**i }.to_scale)
#Run the regression
reg = lr(ds,'y')
end