关键词:
【中文标题】R Caret包中的逻辑回归调整参数网格?【英文标题】:Logistic Regression Tuning Parameter Grid in R Caret Package? 【发布时间】:2018-05-29 02:15:47 【问题描述】:我正在尝试使用caret package
在 R 中拟合逻辑回归模型。我做了以下事情:
model <- train(dec_var ~., data=vars, method="glm", family="binomial",
trControl = ctrl, tuneGrid=expand.grid(C=c(0.001, 0.01, 0.1, 1,10,100, 1000)))
但是,我不确定该模型的调整参数应该是什么,而且我很难找到它。我假设它是 C,因为 C 是 sklearn
中使用的参数。目前,我收到以下错误 -
错误:调整参数网格应该有列参数
您对如何解决此问题有任何建议吗?
【问题讨论】:
试试modelLookup("glm")
,见这里:***.com/questions/43970831/…
从指定tuneLength
开始并观察参数caret
决定改变,而不是陷入网格规范也是一个好主意。
glm
方法没有调优参数topepo.github.io/caret/train-models-by-tag.html,里面有一个哑调参数,它什么都不做。
【参考方案1】:
Per Max Kuhn 的网络书-search for method = 'glm'
here,caret
中没有调整参数glm
。
我们可以通过测试几个基本的train
调用来轻松验证这种情况。首先,让我们从一个方法 (rpart
) 开始,该方法在网络手册中确实有一个调整参数 (cp
)。
library(caret)
data(GermanCredit)
# Check tuning parameter via `modelLookup` (matches up with the web book)
modelLookup('rpart')
# model parameter label forReg forClass probModel
#1 rpart cp Complexity Parameter TRUE TRUE TRUE
# Observe that the `cp` parameter is tuned
set.seed(1)
model_rpart <- train(Class ~., data=GermanCredit, method='rpart')
model_rpart
#CART
#1000 samples
# 61 predictor
# 2 classes: 'Bad', 'Good'
#No pre-processing
#Resampling: Bootstrapped (25 reps)
#Summary of sample sizes: 1000, 1000, 1000, 1000, 1000, 1000, ...
#Resampling results across tuning parameters:
# cp Accuracy Kappa
# 0.01555556 0.7091276 0.2398993
# 0.03000000 0.7025574 0.1950021
# 0.04444444 0.6991700 0.1316720
#Accuracy was used to select the optimal model using the largest value.
#The final value used for the model was cp = 0.01555556.
我们看到cp
参数已调整。现在让我们试试glm
。
# Check tuning parameter via `modelLookup` (shows a parameter called 'parameter')
modelLookup('glm')
# model parameter label forReg forClass probModel
#1 glm parameter parameter TRUE TRUE TRUE
# Try out the train function to see if 'parameter' gets tuned
set.seed(1)
model_glm <- train(Class ~., data=GermanCredit, method='glm')
model_glm
#Generalized Linear Model
#1000 samples
# 61 predictor
# 2 classes: 'Bad', 'Good'
#No pre-processing
#Resampling: Bootstrapped (25 reps)
#Summary of sample sizes: 1000, 1000, 1000, 1000, 1000, 1000, ...
#Resampling results:
# Accuracy Kappa
# 0.7386384 0.3478527
在上述glm
的情况下,没有执行参数调整。根据我的经验,名为parameter
的parameter
似乎只是一个占位符,而不是真正的调整参数。如以下代码所示,即使我们尝试强制它调整 parameter
,它基本上也只会执行一个值。
set.seed(1)
model_glm2 <- train(Class ~., data=GermanCredit, method='glm',
tuneGrid=expand.grid(parameter=c(0.001, 0.01, 0.1, 1,10,100, 1000)))
model_glm2
#Generalized Linear Model
#1000 samples
# 61 predictor
# 2 classes: 'Bad', 'Good'
#No pre-processing
#Resampling: Bootstrapped (25 reps)
#Summary of sample sizes: 1000, 1000, 1000, 1000, 1000, 1000, ...
#Resampling results across tuning parameters:
# Accuracy Kappa parameter
# 0.7386384 0.3478527 0.001
# 0.7386384 0.3478527 0.001
# 0.7386384 0.3478527 0.001
# 0.7386384 0.3478527 0.001
# 0.7386384 0.3478527 0.001
# 0.7386384 0.3478527 0.001
# 0.7386384 0.3478527 0.001
#Accuracy was used to select the optimal model using the largest value.
#The final value used for the model was parameter = 0.001.
【讨论】:
使用 Caret 对神经网络进行参数调整
...间】:2018-03-2903:44:36【问题描述】:我似乎找不到使用R中的Caret包对神经网络进行参数调整以解决分类问题的示例。似乎method="neuralnet"只支持回归问题。有人能解决我的问题吗?【问题讨论】:也许您可以更清楚地了解您自己尝... 查看详情
r语言使用caret包对gbm模型自定义参数调优:自定义参数优化网格
R语言使用caret包对GBM模型自定义参数调优:自定义参数优化网格目录R语言使用caret包对GBM模型自定义参数调优:自定义优化参数网格 查看详情
在 R 代码中使用“caret”包中的 preProcess 的目的是啥?
】在R代码中使用“caret”包中的preProcess的目的是啥?【英文标题】:WhicharethepurposesofusingpreProcessfrom"caret"packageinRcode?在R代码中使用“caret”包中的preProcess的目的是什么?【发布时间】:2020-07-0903:06:21【问题描述】:“大... 查看详情
r语言:利用caret包中的dummyvars函数进行虚拟变量处理
dummyVars函数:dummyVarscreatesafullsetofdummyvariables(i.e.lessthanfullrankparameterization----建立一套完整的虚拟变量先举一个简单的例子:survey<-data.frame(service=c("veryunhappy","unhappy","neutral","happy","veryhappy") 查看详情
“xgboost”官方包与 R 中“caret”包中的 xgboost 的不同结果
】“xgboost”官方包与R中“caret”包中的xgboost的不同结果【英文标题】:Differentresultswith“xgboost”officialpackagevs.xgboostfrom"caret"packageinR【发布时间】:2016-11-2020:47:30【问题描述】:我是R编程语言的新手,我需要运行“xgboost... 查看详情
如何在 R 中重新调整序数逻辑回归模型中的因子?
】如何在R中重新调整序数逻辑回归模型中的因子?【英文标题】:Howtore-levelfactorinordinallogisticregressionmodelinR?【发布时间】:2017-12-1605:39:27【问题描述】:我目前正在研究带有R的序数逻辑回归模型。输出系数使用相同的参考水平... 查看详情
R:调整 SVM 参数 - e1071 包中的 class.weights
】R:调整SVM参数-e1071包中的class.weights【英文标题】:R:TuningSVMparameter-class.weightsine1071packageR:调整SVM参数-e1071包中的class.weights【发布时间】:2015-06-2016:46:45【问题描述】:我想用包e1071训练一个支持向量机分类器。我意识到class.... 查看详情
r3.4.1的caret包中没有traincontrol函数,怎么回事
R语言实际上是函数的集合,用户可以使用base,stats等包中的基本函数,也可以自己编写函数完成一定的功能。但是初学者往往认为编写R函数十分困难,或者难以理解。这里对如何编写R函数进行简要的介绍。函数是对一些程序语... 查看详情
r语言使用caret包中的createresample函数进行机器学习数据集采样数据集有放回的采样(bootstrapping)
R语言使用caret包中的createResample函数进行机器学习数据集采样、数据集有放回的采样(bootstrapping)目录 查看详情
R caret train glmnet 最终模型 lambda 值与指定不符
...我正在使用caret包来调整glmnet逻辑回归模型。虽然besttune中的lambda值是我在tuneGrid中指定的值之一,但最终模型的lambda值完全不同:require(car 查看详情
r语言使用caret包的modellookup函数查看模型算法的细节信息模型是否可用于分类回归超参数信息是否是概率模型
R语言使用caret包的modelLookup函数查看模型算法的细节信息、模型是否可用于分类、回归、超参数信息、是否是概率模型目录 查看详情
r语言使用caret包的getmodelinfo函数获取caret包中提供的模型算法列表
R语言使用caret包的getModelInfo函数获取caret包中提供的模型算法列表目录R语言使用caret包的getModelInfo函数获取caret包中提供的模型算法列表 查看详情
r语言使用caret包中的createdatapartition函数进行机器学习数据集划分划分训练集和测试集并指定训练测试比例
R语言使用caret包中的createDataPartition函数进行机器学习数据集划分、划分训练集和测试集并指定训练测试比例目录 查看详情
r语言使用caret包构建随机森林模型(randomforest)构建回归模型通过method参数指定算法名称通过ntree参数指定随机森林中树的个数
R语言使用caret包构建随机森林模型(randomforest)构建回归模型、通过method参数指定算法名称、通过ntree参数指定随机森林中树的个数目录 查看详情
r语言使用caret包的train函数构建多元自适应回归样条(mars)模型查看模型输出结构最优超参数及对应模型评估指标
R语言使用caret包的train函数构建多元自适应回归样条(MARS)模型、查看模型输出结构、最优超参数及对应模型评估指标目录 查看详情
r语言使用caret包对gbm模型自定义参数调优:自定义优化参数网格可视化核心参数与评估指标关系accuracy与树的深度个数的关系kappa与树的深度个数的关系
R语言使用caret包对GBM模型自定义参数调优:自定义优化参数网格、可视化核心参数与评估指标关系、Accuracy与树的深度、个数的关系、Kappa与树的深度、个数的关系目录R语言使用caret包对GBM模型自定义参数调优:自定义优化参数... 查看详情
r语言使用caret包中的createmultifolds函数对机器学习数据集进行交叉验证抽样返回的样本列表长度为k×times个times为组内抽样次数
R语言使用caret包中的createMultiFolds函数对机器学习数据集进行交叉验证抽样、返回的样本列表长度为k×times个、times为组内抽样次数目录 查看详情
Logistic 回归中的微调参数
】Logistic回归中的微调参数【英文标题】:Fine-tuningparametersinLogisticRegression【发布时间】:2014-03-1523:56:12【问题描述】:我正在运行逻辑回归,并在文本列上运行tf-idf。这是我在逻辑回归中使用的唯一列。我怎样才能确保尽可能... 查看详情