-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathANN_breaast_cancer.R
57 lines (35 loc) · 1.06 KB
/
ANN_breaast_cancer.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
# First Name : Khasha
# Last Name : Dehnad
# Id : 12345
# purpose : running ANN on breast cancer data
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
apply(bc[,c(-1,-11)],2,mean)
### remove all the records with missing value
### see mfv and median for other strategies
?na.omit()
bc2<-na.omit(bc)
index <- seq (1,nrow(bc2),by=5)
test<-bc2[index,]
training<-bc2[-index,]
library("neuralnet")
?neuralnet()
class(training$Class)
net_bc2 <- neuralnet(Class~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)])
ANN=as.numeric(net_bc2_results$net.result)
ANN_round<-round(ANN)
ANN_cat<-ifelse(ANN<2.5,2,4)
table(Actual=test$Class,ANN_cat)
wrong<- (test$Class!=ANN_cat)
rate<-sum(wrong)/length(wrong)