缺失值,分类任务
missing values,classification task
我正在使用来自 UCI 的这个数据集 breastcancer
,但它包含缺失值。任何人都可以帮我解决它吗?我是机器学习的新手,对缺失值技术知之甚少。这是数据集 cancerdata.
的 link
我在 R 上试过这段代码:
data <- read.csv('D:/cancer.csv', header=FALSE) # Reading the data
for(i in 1:ncol(data)) {
data[is.na(data[,i]), i] <- mean(data[,i], na.rm=TRUE)
}
但它给了我一个错误(抱歉,这可能是微不足道的,但我真的很新
这是
的屏幕截图
感谢您的时间和考虑
here is the output I have
试试 R 中的 missForest 包:https://cran.r-project.org/web/packages/missForest/missForest.pdf
它真的很容易使用,速度很快,并且在输入分类值和数值方面做得很好。
有关快速教程,请参见此处:https://www.analyticsvidhya.com/blog/2016/03/tutorial-powerful-packages-imputing-missing-values/
编辑:
数据中共有 16 个缺失值,全部在第 7 列 (V7
)。您可以通过
查看
data <- read.csv('D:/cancer.csv', header=FALSE) # Reading the data
sum(data == "?")
sum(data$V7 == "?")
现在,missForest 将在数据中估算所有 NA,无论它们在哪里。如果您想保留一些 NA,请先分离该数据。
估算所有 NA:
data[data == "?"] <- NA
library(missForest)
data <- missForest(data)$ximp
现在所有的 NA 都被估算并替换为一些有意义的值。要验证这一点:
sum(is.na(data))
将此数据与估算值一起使用。
我正在使用来自 UCI 的这个数据集 breastcancer
,但它包含缺失值。任何人都可以帮我解决它吗?我是机器学习的新手,对缺失值技术知之甚少。这是数据集 cancerdata.
我在 R 上试过这段代码:
data <- read.csv('D:/cancer.csv', header=FALSE) # Reading the data
for(i in 1:ncol(data)) {
data[is.na(data[,i]), i] <- mean(data[,i], na.rm=TRUE)
}
但它给了我一个错误(抱歉,这可能是微不足道的,但我真的很新 这是
的屏幕截图感谢您的时间和考虑
here is the output I have
试试 R 中的 missForest 包:https://cran.r-project.org/web/packages/missForest/missForest.pdf
它真的很容易使用,速度很快,并且在输入分类值和数值方面做得很好。
有关快速教程,请参见此处:https://www.analyticsvidhya.com/blog/2016/03/tutorial-powerful-packages-imputing-missing-values/
编辑:
数据中共有 16 个缺失值,全部在第 7 列 (V7
)。您可以通过
data <- read.csv('D:/cancer.csv', header=FALSE) # Reading the data
sum(data == "?")
sum(data$V7 == "?")
现在,missForest 将在数据中估算所有 NA,无论它们在哪里。如果您想保留一些 NA,请先分离该数据。
估算所有 NA:
data[data == "?"] <- NA
library(missForest)
data <- missForest(data)$ximp
现在所有的 NA 都被估算并替换为一些有意义的值。要验证这一点:
sum(is.na(data))
将此数据与估算值一起使用。