首页 > 解决方案 > R 中的 C5.0 机器学习,对测试数据具有 100% 的准确度

问题描述

我正在做一个机器学习项目,并使用 C5.0 决策树来查看乳腺癌数据,尝试预测诊断为恶性还是良性。该数据集是 UCI 机器学习数据集之一,发布在此链接:https ://archive.ics.uci.edu/ml/datasets/Breast+Cancer+Wisconsin+%28Diagnostic%29 。

我认为我的代码对于模型是正确的,但是每当我为测试数据运行它时,它对这些数据具有 100% 的准确性。我假设这意味着我做错了什么,但我不确定是什么:

#Load Library
library(C50)
library(gmodels)
library(tidyverse)
library(dplyr)

#Import Data
setwd("C:\\Users\\Grant\\Downloads")
wdbc<-read.delim("C:\\Users\\Grant\\Downloads\\wdbc.txt", header=TRUE, sep=",")

#Need to convert it to factor
wdbc2=mutate(wdbc, Diagnosis=as.factor(diagnosis))

#Randomize Sequence
set.seed(12345)
wdbc_rand<-wdbc2[order(runif(569)), ]

#Split into training vs. test data
wdbc_train<-wdbc_rand[1:512, ]
wdbc_test<-wdbc_rand[512:569, ]


#Create Model
wdbc_model<-C5.0(x=wdbc_train[-2], y=wdbc_train$Diagnosis)

#Evaluate Performance
wdbc_pred <- predict(wdbc_model, wdbc_test)
CrossTable(wdbc_test$Diagnosis, wdbc_pred, prop.chisq = FALSE,
           prop.c = FALSE, prop.r = FALSE, dnn= c('actual diagnosis', 'predicted diagnosis'))

非常感谢我在这里做错的任何帮助或潜在的事情

标签: rmachine-learningdecision-tree

解决方案


还不能输入评论(需要 50 声望点),所以我将在此处输入。代码似乎是正确的,但我认为准确度不是 100%。在 3 种情况下,预测为 B,而诊断为 M。您在训练模型时也使用 ID 作为预测器,我也会将其删除。


推荐阅读