library(caTools)

BreastCancer <- read.csv(file='breast.data.csv', stringsAsFactors=T)
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,]

model <- glm(formula = as.factor(trainData[,10])~., data=trainData[,-10], family=binomial('logit'), control = list(maxit = 100, epsilon=3))

pred <- predict(model, testData, type = 'response')
pred_num <- ifelse(pred > 0.5, 4, 2)

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

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