-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathANN_breaast_cancer_multiple_output_class_apr12'18.R
71 lines (45 loc) · 1.78 KB
/
ANN_breaast_cancer_multiple_output_class_apr12'18.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# First Name : Khasha
# Last Name : Dehnad
# Id : 12345
# purpose :
# : Two output nodes
remove(list=ls())
bc<-
read.csv("C://AIMS/Stevens_/2018_DataMining/Raw_Data/breast-cancer-wisconsin.data.csv",
na.strings = "?")
### perform EDS
summary(bc)
mean(bc$F2)
mean(bc$F6)
apply(bc[,c(-1,-11)],2,mean)
### remove all the records with missing value
### see mfv and median for other strategies
?na.omit()
benign<-ifelse(bc$Class==2,1,0)
malignant<-ifelse(bc$Class==4,1,0)
bc2<- na.omit(data.frame(bc,benign,malignant))
index <- seq (1,nrow(bc2),by=5)
test<-bc2[index,]
training<-bc2[-index,]
library("neuralnet")
?neuralnet()
net_bc2 <- neuralnet(benign+malignant~F1+F2+F3+F4+F5+F6+F7+F8+F9
,training, hidden=5, threshold=0.01)
#Plot the neural network
plot(net_bc2)
net_bc2_results <-compute(net_bc2, test[,c(-1,-11,-12,-13)])
class(net_bc2_results$net.result)
str(net_bc2_results)
resutls<-data.frame(Actual_Benign=test$benign,
Actual_Malignant=test$malignant,
ANN_Benign=round(net_bc2_results$net.result[,1]),
ANN_Malignant=round(net_bc2_results$net.result[,2]))
resutls2<-data.frame(Actual_Benign=test$benign,
Actual_Malignant=test$malignant,
ANN_Benign=round(net_bc2_results$net.result[,1]),
ANN_Malignant=round(net_bc2_results$net.result[,2])
,Prediction=ifelse(round(net_bc2_results$net.result[,1])==1,'B','M'))
table(Actual=resutls2$Actual_Malignant,Prediction=resutls2$Prediction)
wrong<- (round(net_bc2_results$net.result[,1])!=test$benign )
error_rate<-sum(wrong)/length(wrong)
error_rate