【发布时间】:2016-03-05 09:34:08
【问题描述】:
我正在尝试将多项式回归从 R 复制到 python,但我没有得到相同的结果:
R 示例:
x = seq(1,100)
y = x^2 + 3*x + 7
fit = lm(y~poly(x,2,raw=TRUE))
> fit
Call:
lm(formula = y ~ poly(x, 2, raw = TRUE))
Coefficients:
(Intercept) poly(x, 2, raw = TRUE)1 poly(x, 2, raw = TRUE)2
7 3 1
Python 示例
>>> import numpy as np
>>> x = np.arange(1,101)
>>> y = x^2 + 3*x + 7
>>> fit = np.polyfit(x,y,2)
>>> fit
array([ 2.14390707e-02, 1.00652305e+00, 3.49914904e+01])
我错过了什么?
【问题讨论】:
-
x**2在 python 中 -
@cel 谢谢!就是这样!请将您的评论作为答案,以便我接受。