wbcd = read.table('wdbc.txt', sep = ',', head = False)
names(wbcd) = c('id','diagnosis','radius','texture','perimeter','area','smoothness', 'compactness','concavity','concave points','symmetry','fractal dimension', 'V14', 'V15', 'V16', 'V17', 'V18', 'V19', 'V20', 'V21', 'V22', 'V23', 'V24', 'V25', 'V26', 'V27', 'V28', 'V29', 'V30', 'V31','V32', 'V33')
wbcd = wbcd[-1]
normalize = function(x) {
x1 = x-min(x)
x2 = max(x) -min(x)
return(x1/x2)
}
wbcd_n = as.data.frame(lapply(wbcd[2:31], normalize ))
wbcd_train = wbcd_n[1:469, ]
wbcd_test = wbcd_n[470:569, ]
wbcd_train_labels = wbcd[1:469, 1
r语言 knn 《机器学习与R语言》
最新推荐文章于 2024-08-13 08:40:40 发布
本文介绍了如何在R语言中运用KNN(K-最近邻)算法进行机器学习,包括KNN的基本原理、R语言中的KNN库以及实战示例。
摘要由CSDN通过智能技术生成