r - 如何在 R 中编写函数来自动选择重要特征?
问题描述
如何编写一个函数来自动化这些过程:
- 针对 0.05 阈值选择重要特征
- 选择三个最重要的功能
到目前为止,我的就是这个,但它不起作用。我可以列出功能,但不能编写一个功能来做这两个!
lm.fit <- glm(formula = Salary ~., data=train, family = binomial)
glm.coef.sig <- data.frame(summary(glm.fit)$coef[summary(glm.fit)$coef[,4] < .05, 4])
glm.coef.sig
解决方案
这是一个示例工作流程:
features <- "."
repeat{
lm(formula=paste0("wt ~ ", paste0(features, collapse="+")), mtcars) -> lm.fit
# get the coefficients that are significant
summary(lm.fit)$coef[-1, 4] <.05 -> summ
# check if the selected features are the features we already had if so break
# if not change feature to selected features
if(identical(features, names(summ)[summ])){
break
} else features = names(summ)[summ]
}
推荐阅读
- javascript - Javascript循环通过一个json对象
- python - 有没有办法让 PDFQuery.load 更高效(并且仍然可靠)
- reactjs - Nav.navbar 自动完成在 React 中不起作用
- android - 无法解析所有文件以进行配置。我收到一个错误
- visual-studio-code - 如何将 PHAR 存档作为外部库添加到 VS 代码
- swift - UIScrollView ContentOffset.y 在 performBatch 后重置为 0
- go - 将 int 和 string 连接为常量 - Golang
- windows - 无法在 PowerShell 工作流程中打印变量
- python - 如何在 u net 的预训练编码器中对它们进行零填充后进入跳过连接层?
- css - 如何在 Flex Column 中将第三列 div 作为一行移动到底部