library(C50)
library (datasets)

BreastCancer <- read.csv(file='breast.data.csv')
BreastCancer <- BreastCancer[-1] # drop sample column

## Split in train + test set
indexes <- sample(1:nrow(BreastCancer),as.integer(0.7*nrow(BreastCancer)))

trainData <- BreastCancer[indexes,]
testData <- BreastCancer[-indexes,]

treeFit <- C5.0(x=trainData[,-10], y=as.factor(trainData[,10]))
pred <- predict(treeFit, testData)

confusionmatrix = as.matrix(table(Actual = testData[,10], Predicted = pred))
accuracy = sum(diag(confusionmatrix))/length(testData[,10])

print('Confusion Matrix')
print(confusionmatrix)
print('Accuracy')
print(accuracy)
