将多项式回归从R移植到python

时间:2016-03-05 09:34:08

标签: python r numpy

我试图将一个多项式回归从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])

我错过了什么?

1 个答案:

答案 0 :(得分:2)

仅仅为了完整性,因为@cel还没有把它作为答案。 你必须在python中编写func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([Any]?) -> Void) -> Bool { if userActivity.activityType == NSUserActivityTypeBrowsingWeb { let url = userActivity.webpageURL! let query = url.query ?? "" if query.contains("query_parmeter1") { // handle code for query_parmeter1 } else if query.contains("query_parmeter2") { // handle code for query_parmeter2 } return true } return false }