R:为什么 train() 在插入符 returns 空模型中运行(调用:NULL)?
R: Why train() function in caret returns null model (Call: NULL)?
例如,我使用 train 构建逻辑回归,如下所示:
library(caret)
n <- 1000
df <- data.frame(x1=runif(n, min=0, max=1),
x2=runif(n, min=0, max=1),
y = rep(c('N', 'Y'), n/2)[sample(n, n)])
lmFit <- train(y ~ ., data=df, method='glm', family = binomial)
summary(lmFit)
会显示
Call:
NULL
....
是否有设置使其显示正确的 glm
呼叫,而不是 NULL
?
谢谢。
我没有看到这样的设置可以提供给摘要,因为 summary.train 方法去除了调用值:
> class(lmFit)
[1] "train" "train.formula"
> getAnywhere(summary.train)
A single object matching ‘summary.train’ was found
It was found in the following places
registered S3 method for summary from namespace caret
namespace:caret
with value
function (object, ...)
summary(object$finalModel, ...)
<bytecode: 0x1bc4f820>
<environment: namespace:caret>
> names(lmFit)
[1] "method" "modelInfo" "modelType" "results" "pred" "bestTune" "call"
[8] "dots" "metric" "control" "finalModel" "preProcess" "trainingData" "resample"
[15] "resampledCM" "perfNames" "maximize" "yLimits" "times" "levels" "terms"
[22] "coefnames" "xlevels"
您可以制作该函数的变体,使用 cat
或 returns 作为 summary
对象的一部分输出调用,或两者兼而有之。或者您可以将其添加到您的脚本中:
> lmFit$call
train.formula(form = y ~ ., data = df, method = "glm", family = binomial)
例如,我使用 train 构建逻辑回归,如下所示:
library(caret)
n <- 1000
df <- data.frame(x1=runif(n, min=0, max=1),
x2=runif(n, min=0, max=1),
y = rep(c('N', 'Y'), n/2)[sample(n, n)])
lmFit <- train(y ~ ., data=df, method='glm', family = binomial)
summary(lmFit)
会显示
Call:
NULL
....
是否有设置使其显示正确的 glm
呼叫,而不是 NULL
?
谢谢。
我没有看到这样的设置可以提供给摘要,因为 summary.train 方法去除了调用值:
> class(lmFit)
[1] "train" "train.formula"
> getAnywhere(summary.train)
A single object matching ‘summary.train’ was found
It was found in the following places
registered S3 method for summary from namespace caret
namespace:caret
with value
function (object, ...)
summary(object$finalModel, ...)
<bytecode: 0x1bc4f820>
<environment: namespace:caret>
> names(lmFit)
[1] "method" "modelInfo" "modelType" "results" "pred" "bestTune" "call"
[8] "dots" "metric" "control" "finalModel" "preProcess" "trainingData" "resample"
[15] "resampledCM" "perfNames" "maximize" "yLimits" "times" "levels" "terms"
[22] "coefnames" "xlevels"
您可以制作该函数的变体,使用 cat
或 returns 作为 summary
对象的一部分输出调用,或两者兼而有之。或者您可以将其添加到您的脚本中:
> lmFit$call
train.formula(form = y ~ ., data = df, method = "glm", family = binomial)