0% found this document useful (0 votes)
65 views10 pages

Naïve Bayes + Neural Network

This document discusses using naive Bayes classification and neural networks to classify breast cancer severity using patient data. It presents the code to build naive Bayes and neural network models to classify severity using attributes like BI-RADS score, age, tumor shape, margin, and density. It then evaluates and compares the performance of the two models based on accuracy, precision, recall, F1 score, true positive rate, true negative rate, and area under the ROC curve.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
65 views10 pages

Naïve Bayes + Neural Network

This document discusses using naive Bayes classification and neural networks to classify breast cancer severity using patient data. It presents the code to build naive Bayes and neural network models to classify severity using attributes like BI-RADS score, age, tumor shape, margin, and density. It then evaluates and compares the performance of the two models based on accuracy, precision, recall, F1 score, true positive rate, true negative rate, and area under the ROC curve.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 10

Naïve Bayes

Classification learning by Probability


Syntax
dat4<-train
View(dat4) #plot ROC
library(ROCR)
Severityf<-as.factor(dat4$Severity)
library(pROC)
dat5<-dat4[-6]
roc_nb <- roc(test$Severity, as.numeric(Prediction_Nbayes[,2]))
View(dat5)
plot(roc_nb, print.thres="best", print.thres.best.method="closest.topleft",col="blue")
dat6<-cbind(dat5,Severityf) score<- Prediction_Nbayes
View(dat6)
Confus_Matrik_NBayes <- predict(nb_dat,test)
library(naivebayes) ConMat2 <-table(test$Severity, Confus_Matrik_NBayes)

nb_dat<- print(ConMat2)
naive_bayes(Severityf~BI_RADS+Age+Shape+Margin+Density,dat
a = dat6)
akurasi2 <- (sum(diag(ConMat2)))/sum(ConMat2)
nb_dat
presisi2 <- ConMat2[1,1]/(ConMat2[1,1]+ConMat2[2,1])
recall2 <- ConMat2[1,1]/(ConMat2[1,1]+ConMat2[1,2])
library(e1071) F12 <- (2*presisi2*recall2)/(presisi2+recall2)
Nbayes <- naiveBayes(Severityf~., data=dat6) tpr2<-recall2
Prediction_Nbayes <- predict(Nbayes, test,type="raw“) tnr2<-ConMat2[2,2]/(ConMat2[2,2]+ConMat2[2,1])
Syntax (2)
Prediction <- predict(nb_dat, test)
library(ModelMetrics)
auc_c50 <- auc(test$Severity, Prediction)
#packages ModelMetrics

cat("
AKURASI =",akurasi2,
"
PRESISI =",presisi2,
"
RECALL =",recall2,
"
F1 =",F12,
"
TPR =", tpr2,
"
TNR =", tnr2,
"
AUC =", auc_c50)
Naïve Bayes

Kekuatan kanker payudara


akan berpotensi ganas
apabila :
BI RADS : 4 - 5
Age : ≥ 40 tahun
Shape : lobular dan irregular
Margin : ill-defined dan
speculated
Density : iso dan low
Validation Test
Naïve Bayes

 Akurasi : 0,8625
 Presisi : 0,87037
 Recall : 0,85975
 F1 : 0,86503
 TPR : 0,85975
 TNR : 0,86538
 AUC : 0,8529

ROC Curve
Neural Network
Classification by connecting input to output by involving hidden layer and weights
Syntax

# Encode as a one hot vector multilabel data # Set labels name


#Encode target variable colnames(comp2) <-
c("age1","age2","age3","BI_RADS2","BI_RADS3","BI_RAD
target_en <- class.ind(as.factor(comp$Severity)) S4","BI_RADS5","shape1","shape2","shape3","shape4","
age_en <- class.ind(as.factor(comp$Age)) margin1","margin2","margin3","margin4","margin5","de
nsity1","density2","density3","density4","severity0","severi
BI_RADS_en <- class.ind(as.factor(comp$BI_RADS)) ty1")
shape_en <- class.ind(as.factor(comp$Shape)) n <- names(comp2)

margin_en <- class.ind(as.factor(comp$Margin)) n


f <- as.formula(paste("severity0 + severity1 ~",
density_en <- class.ind(as.factor(comp$Density)) paste(n[!n %in% c("severity0","severity1")],collapse = "
comp2<- + ")))
cbind(age_en,BI_RADS_en,shape_en,margin_en,d nn <- neuralnet(f,data = comp2, hidden = c(4,
ensity_en,target_en) 3),act.fct = "logistic", linear.output = FALSE,lifesign =
"minimal")
comp2<- as.data.frame(comp2)
plot(nn)
View(comp2)
tnr2<-ConMat2[2,2]/(ConMat2[2,2]+ConMat2[2,1])
Prediction_NN <- predict(neural, test, type = "prob")
auc_NN <- auc(test$Severity, Prediction_NN[,2]) #packages

Syntax (2) ModelMetrics


auc_NN

cat("
library(caret) AKURASI =",akurasi3,
neural <- train(Severityf~., data=dat6, method="nnet", "
trace = FALSE, preProc = c("center","scale")) PRESISI =",presisi3,
plot(neural) "
RECALL =",recall3,
Confus_Matriks_NN <- predict(neural,test) "
ConMat3<-table(test$Severity, Confus_Matriks_NN) F1 =",F13,
"
print(ConMat3) TPR =", tpr3,
"
akurasi3 <- (sum(diag(ConMat3)))/sum(ConMat3) TNR =", tnr3,
presisi3 <- ConMat3[1,1]/(ConMat3[1,1]+ConMat3[2,1]) "
recall3 <- ConMat3[1,1]/(ConMat3[1,1]+ConMat3[1,2]) AUC =", auc_NN)
F13 <- (2*presisi3*recall3)/(presisi3+recall3)
tpr3<-recall3 #make ROC
tnr3<-ConMat3[2,2]/(ConMat3[2,2]+ConMat3[2,1]) plot(roc(test$Severity, Prediction_NN[,2]))
Neural Network

Input 2-level-hidden layer Output


Validation Test
Naïve Bayes

 Akurasi : 0,85625
 Presisi : 0,82417
 Recall : 0,91463
 F1 : 0,86705
 TPR : 0,91463
 TNR : 0,79487
 AUC : 0,93333

ROC Curve

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy