出于学习原因,我正在尝试使用BostonHousing
包将多项式函数拟合到mlr
数据中。
我无法弄清楚如何为使用的lm
函数提供自定义公式,尤其是我想向输入变量之一添加多项式函数(出于测试目的)。
如何最好地实现这一目标?
library(mlr)
data("BostonHousing", package = "mlbench")
regr.task <- makeRegrTask(data = BostonHousing, target = "medv")
regr.learner <- makeLearner("regr.lm")
# I would like to specify the formula used by "regr.lm" myself, how can this be achieved?
regr.train <- train(regr.learner, regr.task)
lm.results <- getLearnerModel(regr.train)
summary(lm.results)
Call:
stats::lm(formula = f, data = d)
Residuals:
Min 1Q Median 3Q Max
-15.595 -2.730 -0.518 1.777 26.199
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 3.646e+01 5.103e+00 7.144 3.28e-12 ***
crim -1.080e-01 3.286e-02 -3.287 0.001087 **
zn 4.642e-02 1.373e-02 3.382 0.000778 ***
indus 2.056e-02 6.150e-02 0.334 0.738288
chas1 2.687e+00 8.616e-01 3.118 0.001925 **
nox -1.777e+01 3.820e+00 -4.651 4.25e-06 ***
rm 3.810e+00 4.179e-01 9.116 < 2e-16 ***
age 6.922e-04 1.321e-02 0.052 0.958229
dis -1.476e+00 1.995e-01 -7.398 6.01e-13 ***
rad 3.060e-01 6.635e-02 4.613 5.07e-06 ***
tax -1.233e-02 3.760e-03 -3.280 0.001112 **
ptratio -9.527e-01 1.308e-01 -7.283 1.31e-12 ***
b 9.312e-03 2.686e-03 3.467 0.000573 ***
lstat -5.248e-01 5.072e-02 -10.347 < 2e-16 ***
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 4.745 on 492 degrees of freedom
Multiple R-squared: 0.7406, Adjusted R-squared: 0.7338
F-statistic: 108.1 on 13 and 492 DF, p-value: < 2.2e-16