## input data
input=read.delim("clipboard", header = T)
library(neuralnet)
## Warning: package 'neuralnet' was built under R version 3.5.3
#training Sample with n observations
n <- round(nrow(input)*0.75)
set.seed(12)
random=sample(1:nrow(input),n)
## memisahkan
train = input[random,]
test = input[-random,]
# mengambil nama variabel
x <- names(input[,1:17])
x
## [1] "MDVP_Fo" "MDVP_Fhi" "MDVP_Flo"
## [4] "MDVP_Jitter_Abs" "MDVP_Jitter_Percent" "MDVP_RAP"
## [7] "MDVP_PPQ" "Jitter_DDP" "MDVP_Shimmer"
## [10] "Shimmer_APQ3" "Shimmer_APQ5" "MDVP_APQ11"
## [13] "Shimmer_DDA" "NHR" "HNR"
## [16] "RPDE" "DFA"
# Concatenate strings
f <- paste(x,collapse=' + ')
f <- paste('Status ~',f)
# Convert to formula
f <- as.formula(f);f
## Status ~ MDVP_Fo + MDVP_Fhi + MDVP_Flo + MDVP_Jitter_Abs + MDVP_Jitter_Percent +
## MDVP_RAP + MDVP_PPQ + Jitter_DDP + MDVP_Shimmer + Shimmer_APQ3 +
## Shimmer_APQ5 + MDVP_APQ11 + Shimmer_DDA + NHR + HNR + RPDE +
## DFA
## train neural net
nn.5 <- neuralnet(f,train,
hidden=c(4, 3),
linear.output=TRUE)
#threshold=ambang batas
#stepmax=langkah maksimum iterasi
#weights=nilai yg ada di setiap garis hitam
#bias=angka pada node biru (nilai weight paling atas)
nn.5$weights
## [[1]]
## [[1]][[1]]
## [,1] [,2] [,3] [,4]
## [1,] 0.99493591 -0.22170504 0.45763026 0.3489802
## [2,] 0.55429665 0.57419174 0.51369994 -1.0318327
## [3,] 0.20740054 -0.53345615 -0.32367969 -0.9481988
## [4,] 1.11836418 -0.57836429 -1.03543016 1.2860703
## [5,] -0.18662735 0.02570991 -1.01641756 2.4020324
## [6,] 0.80707943 -0.64772724 0.13908503 -1.2163536
## [7,] -1.38209541 -0.35187115 -0.98163984 -0.6386369
## [8,] 0.52333202 0.91141447 0.41169149 -0.6436162
## [9,] -1.50238204 -1.66017347 0.21826291 -2.1838385
## [10,] -0.67438309 -0.77494269 -0.92673413 1.2504748
## [11,] 0.07479813 3.02671927 -0.39374835 0.8999809
## [12,] -0.33950464 -0.70121750 -0.48053327 -1.2399370
## [13,] 0.03689017 -0.78135318 -0.04372127 0.2167333
## [14,] 1.67484350 0.94606713 0.85597950 0.4165827
## [15,] 0.37833259 0.33683703 -1.38223762 0.1994810
## [16,] -0.64414245 -1.63897963 -0.39901020 -0.8527497
## [17,] 0.69933982 -0.60684885 0.66796017 -0.8968072
## [18,] -1.09105263 -2.76419310 1.77792616 -0.1909996
##
## [[1]][[2]]
## [,1] [,2] [,3]
## [1,] -0.4924806 -0.4066742 2.2381801
## [2,] -0.7214433 0.8571373 0.4467193
## [3,] 0.8321620 1.3810208 0.7786523
## [4,] 0.7171871 0.9566912 0.3351387
## [5,] 0.8596865 0.1621435 -2.0130267
##
## [[1]][[3]]
## [,1]
## [1,] -0.5574629
## [2,] 0.6003782
## [3,] 1.7493979
## [4,] 0.1103872
summary(nn.5)
## Length Class Mode
## call 5 -none- call
## response 141 -none- numeric
## covariate 2397 -none- numeric
## model.list 2 -none- list
## err.fct 1 -none- function
## act.fct 1 -none- function
## linear.output 1 -none- logical
## data 18 data.frame list
## exclude 0 -none- NULL
## net.result 1 -none- list
## weights 1 -none- list
## generalized.weights 1 -none- list
## startweights 1 -none- list
## result.matrix 94 -none- numeric
## plot model
plot(nn.5)
#prediksi model
pred.5 <- compute(nn.5,test[1:17])
pred.5.r <- ifelse(pred.5$net.result < 0.8,1,0)
library(caret)
## Warning: package 'caret' was built under R version 3.5.3
## Loading required package: lattice
## Warning: package 'lattice' was built under R version 3.5.3
## Loading required package: ggplot2
## Warning: package 'ggplot2' was built under R version 3.5.3
conf_matrix=table(pred.5.r,test$Status)
accuracy=(conf_matrix[1,2])/sum(conf_matrix)
accuracy
## [1] 0.7659574