Library

library(readxl) 
library(e1071)  
## Warning: package 'e1071' was built under R version 4.4.3
library(caret) 
## Warning: package 'caret' was built under R version 4.4.3
## Loading required package: ggplot2
## Loading required package: lattice
library(class)
library(Metrics)
## Warning: package 'Metrics' was built under R version 4.4.3
## 
## Attaching package: 'Metrics'
## The following objects are masked from 'package:caret':
## 
##     precision, recall
library(MLmetrics)
## 
## Attaching package: 'MLmetrics'
## The following objects are masked from 'package:caret':
## 
##     MAE, RMSE
## The following object is masked from 'package:base':
## 
##     Recall
library(party)
## Loading required package: grid
## Loading required package: mvtnorm
## Loading required package: modeltools
## Loading required package: stats4
## Loading required package: strucchange
## Loading required package: zoo
## 
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
## 
##     as.Date, as.Date.numeric
## Loading required package: sandwich
library(neuralnet)
## Warning: package 'neuralnet' was built under R version 4.4.3
library(randomForest)
## Warning: package 'randomForest' was built under R version 4.4.3
## randomForest 4.7-1.2
## Type rfNews() to see new features/changes/bug fixes.
## 
## Attaching package: 'randomForest'
## The following object is masked from 'package:ggplot2':
## 
##     margin
library(rpart)
## Warning: package 'rpart' was built under R version 4.4.3
library(rpart.plot)
## Warning: package 'rpart.plot' was built under R version 4.4.3

Input data

#input data
data <- read_excel("hasil_prepo_bank.xlsx")
print(data)
## # A tibble: 4,521 × 17
##      Age job       marital education default balance housing loan  contact   day
##    <dbl> <chr>     <chr>   <chr>     <chr>     <dbl> <chr>   <chr> <chr>   <dbl>
##  1    30 unemploy… married primary   no         1787 no      no    cellul…    19
##  2    33 services  married secondary no         4789 yes     yes   cellul…    11
##  3    35 manageme… single  tertiary  no         1350 yes     no    cellul…    16
##  4    30 manageme… married tertiary  no         1476 yes     yes   unknown     3
##  5    59 blue-col… married secondary no            0 yes     no    unknown     5
##  6    35 manageme… single  tertiary  no          747 no      no    cellul…    23
##  7    36 self-emp… married tertiary  no          307 yes     no    cellul…    14
##  8    39 technici… married secondary no          147 yes     no    cellul…     6
##  9    41 entrepre… married tertiary  no          221 yes     no    unknown    14
## 10    43 services  married primary   no          -88 yes     yes   cellul…    17
## # ℹ 4,511 more rows
## # ℹ 7 more variables: month <chr>, duration <dbl>, campaign <dbl>, pdays <dbl>,
## #   previous <dbl>, poutcome <chr>, y <chr>

Partisi data

str(data)
## tibble [4,521 × 17] (S3: tbl_df/tbl/data.frame)
##  $ Age      : num [1:4521] 30 33 35 30 59 35 36 39 41 43 ...
##  $ job      : chr [1:4521] "unemployed" "services" "management" "management" ...
##  $ marital  : chr [1:4521] "married" "married" "single" "married" ...
##  $ education: chr [1:4521] "primary" "secondary" "tertiary" "tertiary" ...
##  $ default  : chr [1:4521] "no" "no" "no" "no" ...
##  $ balance  : num [1:4521] 1787 4789 1350 1476 0 ...
##  $ housing  : chr [1:4521] "no" "yes" "yes" "yes" ...
##  $ loan     : chr [1:4521] "no" "yes" "no" "yes" ...
##  $ contact  : chr [1:4521] "cellular" "cellular" "cellular" "unknown" ...
##  $ day      : num [1:4521] 19 11 16 3 5 23 14 6 14 17 ...
##  $ month    : chr [1:4521] "oct" "may" "apr" "jun" ...
##  $ duration : num [1:4521] 79 220 185 199 226 141 341 151 57 313 ...
##  $ campaign : num [1:4521] 1 1 1 4 1 2 1 2 2 1 ...
##  $ pdays    : num [1:4521] -1 339 330 -1 -1 176 330 -1 -1 147 ...
##  $ previous : num [1:4521] 0 4 1 0 0 3 2 0 0 2 ...
##  $ poutcome : chr [1:4521] "unknown" "failure" "failure" "unknown" ...
##  $ y        : chr [1:4521] "no" "no" "no" "no" ...
Sample <- sample(1:4521, 904)
testing <- data[Sample, ]
learning <- data[-Sample, ]

NB

#Membuat model
model <- naiveBayes(y ~ ., data = learning)

Prediksi dan evaluasi data training

prediksi <- predict(model, learning)

predicted <- prediksi
actual <- learning$y

actual <- ifelse(as.character(actual) == "yes", 0, 1)
predicted <- ifelse(as.character(predicted) == "yes", 0, 1)

# Generate confusion matrix
xtab <- table(actual, predicted)
cm <- caret::confusionMatrix(xtab)
print(cm)
## Confusion Matrix and Statistics
## 
##       predicted
## actual    0    1
##      0  199  199
##      1  282 2937
##                                           
##                Accuracy : 0.867           
##                  95% CI : (0.8555, 0.8779)
##     No Information Rate : 0.867           
##     P-Value [Acc > NIR] : 0.5121545       
##                                           
##                   Kappa : 0.3779          
##                                           
##  Mcnemar's Test P-Value : 0.0001848       
##                                           
##             Sensitivity : 0.41372         
##             Specificity : 0.93654         
##          Pos Pred Value : 0.50000         
##          Neg Pred Value : 0.91240         
##              Prevalence : 0.13298         
##          Detection Rate : 0.05502         
##    Detection Prevalence : 0.11004         
##       Balanced Accuracy : 0.67513         
##                                           
##        'Positive' Class : 0               
## 
#Menghitung akurasi
#akurasi <- mean(prediksi == learning$y)
#print(paste("Akurasi_train:", round(akurasi * 100, 2), "%"))
accuracy <- (sum(diag(cm$table)))/sum(cm$table)
print(paste("Akurasi_train:", round(accuracy * 100, 2), "%"))
## [1] "Akurasi_train: 86.7 %"
# Compute Recall (correct order: actual, predicted)
recall_score <- recall(actual, predicted)

# Compute Precision (correct order: actual, predicted)
precision_score <- precision(actual, predicted)

# Compute F1-Score (correct order: actual, predicted)
#f1_score <- f1(actual, predicted)
f1_score <- 2 * ((precision_score * recall_score) / (precision_score + recall_score))

# Print results
cat("Recall:", recall_score, "\n")
## Recall: 0.9123952
cat("Precision:", precision_score, "\n")
## Precision: 0.9365434
cat("F1-Score:", f1_score, "\n")
## F1-Score: 0.9243116

Prediksi dan evaluasi data testing

prediksi <- predict(model, testing)

predicted <- prediksi
actual <- testing$y

actual <- ifelse(as.character(actual) == "yes", 0, 1)
predicted <- ifelse(as.character(predicted) == "yes", 0, 1)

# Generate confusion matrix
xtab <- table(actual, predicted)
cm <- caret::confusionMatrix(xtab)
print(cm)
## Confusion Matrix and Statistics
## 
##       predicted
## actual   0   1
##      0  68  55
##      1  78 703
##                                           
##                Accuracy : 0.8529          
##                  95% CI : (0.8281, 0.8753)
##     No Information Rate : 0.8385          
##     P-Value [Acc > NIR] : 0.12864         
##                                           
##                   Kappa : 0.4199          
##                                           
##  Mcnemar's Test P-Value : 0.05644         
##                                           
##             Sensitivity : 0.46575         
##             Specificity : 0.92744         
##          Pos Pred Value : 0.55285         
##          Neg Pred Value : 0.90013         
##              Prevalence : 0.16150         
##          Detection Rate : 0.07522         
##    Detection Prevalence : 0.13606         
##       Balanced Accuracy : 0.69660         
##                                           
##        'Positive' Class : 0               
## 
#Menghitung akurasi
#akurasi <- mean(prediksi == learning$y)
#print(paste("Akurasi_train:", round(akurasi * 100, 2), "%"))
accuracy <- (sum(diag(cm$table)))/sum(cm$table)
print(paste("Akurasi_test:", round(accuracy * 100, 2), "%"))
## [1] "Akurasi_test: 85.29 %"
# Compute Recall (correct order: actual, predicted)
recall_score <- recall(actual, predicted)

# Compute Precision (correct order: actual, predicted)
precision_score <- precision(actual, predicted)

# Compute F1-Score (correct order: actual, predicted)
#f1_score <- f1(actual, predicted)
f1_score <- 2 * ((precision_score * recall_score) / (precision_score + recall_score))

# Print results
cat("Recall:", recall_score, "\n")
## Recall: 0.900128
cat("Precision:", precision_score, "\n")
## Precision: 0.9274406
cat("F1-Score:", f1_score, "\n")
## F1-Score: 0.9135802

Decision Tree

data <- read_excel("hasil_prepo_bank.xlsx")

# Ubah semua kolom character menjadi factor
data[] <- lapply(data, function(x) if (is.character(x)) as.factor(x) else x)

Sample <- sample(1:4521, 904)
testing <- data[Sample, ]
learning <- data[-Sample, ]

# Bangun model pohon keputusan dengan ctree
output.tree <- ctree(y ~ ., data = learning)

# Plot hasil pohon keputusan
plot(output.tree)

# Prediksi dan evaluasi data training

prediksi <- predict(output.tree, learning)

predicted <- prediksi
actual <- learning$y

actual <- ifelse(as.character(actual) == "yes", 0, 1)
predicted <- ifelse(as.character(predicted) == "yes", 0, 1)

CM <- table(learning$y, prediksi)
CM
##      prediksi
##         no  yes
##   no  2983  209
##   yes  156  269
accuracy <- (sum(diag(CM)))/sum(CM)
accuracy
## [1] 0.8990876
# Compute Recall (correct order: actual, predicted)
recall_score <- recall(actual, predicted)

# Compute Precision (correct order: actual, predicted)
precision_score <- precision(actual, predicted)

# Compute F1-Score (correct order: actual, predicted)
#f1_score <- f1(actual, predicted)
f1_score <- 2 * ((precision_score * recall_score) / (precision_score + recall_score))

# Print results
cat("Recall:", recall_score, "\n")
## Recall: 0.9345238
cat("Precision:", precision_score, "\n")
## Precision: 0.9503026
cat("F1-Score:", f1_score, "\n")
## F1-Score: 0.9423472

Prediksi dan evaluasi data testing

prediksi <- predict(output.tree, testing)

predicted <- prediksi
actual <- testing$y

actual <- ifelse(as.character(actual) == "yes", 0, 1)
predicted <- ifelse(as.character(predicted) == "yes", 0, 1)

CM <- table(testing$y, prediksi)
CM
##      prediksi
##        no yes
##   no  746  62
##   yes  34  62
accuracy <- (sum(diag(CM)))/sum(CM)
accuracy
## [1] 0.8938053
# Compute Recall (correct order: actual, predicted)
recall_score <- recall(actual, predicted)

# Compute Precision (correct order: actual, predicted)
precision_score <- precision(actual, predicted)

# Compute F1-Score (correct order: actual, predicted)
#f1_score <- f1(actual, predicted)
f1_score <- 2 * ((precision_score * recall_score) / (precision_score + recall_score))

# Print results
cat("Recall:", recall_score, "\n")
## Recall: 0.9232673
cat("Precision:", precision_score, "\n")
## Precision: 0.9564103
cat("F1-Score:", f1_score, "\n")
## F1-Score: 0.9395466

Visualisasi pohon keputusan

library(rpart.plot)
model <- rpart(y ~ ., data = learning, method = "class")
rpart.plot(model, main = "Pohon Keputusan")

KNN

data <- read_excel("hasil_prepo_bank.xlsx")

data$job <- as.factor(data$job)
data$marital <- as.factor(data$marital)
data$education <- as.factor(data$education)
data$default <- as.factor(data$default)
data$housing <- as.factor(data$housing)
data$loan <- as.factor(data$loan)
data$contact <- as.factor(data$contact)
data$month <- as.factor(data$month)
data$poutcome <- as.factor(data$poutcome)
data$y <- as.factor(data$y)

str(data)
## tibble [4,521 × 17] (S3: tbl_df/tbl/data.frame)
##  $ Age      : num [1:4521] 30 33 35 30 59 35 36 39 41 43 ...
##  $ job      : Factor w/ 12 levels "admin.","blue-collar",..: 11 8 5 5 2 5 7 10 3 8 ...
##  $ marital  : Factor w/ 3 levels "divorced","married",..: 2 2 3 2 2 3 2 2 2 2 ...
##  $ education: Factor w/ 4 levels "primary","secondary",..: 1 2 3 3 2 3 3 2 3 1 ...
##  $ default  : Factor w/ 2 levels "no","yes": 1 1 1 1 1 1 1 1 1 1 ...
##  $ balance  : num [1:4521] 1787 4789 1350 1476 0 ...
##  $ housing  : Factor w/ 2 levels "no","yes": 1 2 2 2 2 1 2 2 2 2 ...
##  $ loan     : Factor w/ 2 levels "no","yes": 1 2 1 2 1 1 1 1 1 2 ...
##  $ contact  : Factor w/ 3 levels "cellular","telephone",..: 1 1 1 3 3 1 1 1 3 1 ...
##  $ day      : num [1:4521] 19 11 16 3 5 23 14 6 14 17 ...
##  $ month    : Factor w/ 12 levels "apr","aug","dec",..: 11 9 1 7 9 4 9 9 9 1 ...
##  $ duration : num [1:4521] 79 220 185 199 226 141 341 151 57 313 ...
##  $ campaign : num [1:4521] 1 1 1 4 1 2 1 2 2 1 ...
##  $ pdays    : num [1:4521] -1 339 330 -1 -1 176 330 -1 -1 147 ...
##  $ previous : num [1:4521] 0 4 1 0 0 3 2 0 0 2 ...
##  $ poutcome : Factor w/ 4 levels "failure","other",..: 4 1 1 4 4 1 2 4 4 1 ...
##  $ y        : Factor w/ 2 levels "no","yes": 1 1 1 1 1 1 1 1 1 1 ...
fitur_numeric <- data[, sapply(data, is.numeric)]

normalize <- function(x) { (x - min(x)) / (max(x) - min(x)) }
fitur_norm <- as.data.frame(lapply(fitur_numeric, normalize))

fitur_norm <- na.omit(fitur_norm)

target <- as.factor(data$y)

fitur_norm$y <- target
fitur_norm <- na.omit(fitur_norm)
target <- fitur_norm$y
fitur_norm$y <- NULL
fitur_final <- fitur_norm

set.seed(123) 

inTrain <- createDataPartition(target, p = 0.8, list = FALSE)
trainData <- fitur_final[inTrain, ]
testData <- fitur_final[-inTrain, ]
trainLabel <- target[inTrain]
testLabel <- target[-inTrain]

trainData <- as.data.frame(lapply(trainData, as.numeric))
testData  <- as.data.frame(lapply(testData, as.numeric))

train_dummy <- trainData
test_dummy <- testData

Menetukan nilai K optimal

library(class)
# Buat vector kosong buat simpan akurasi
k_values <- 1:10
accuracy_k <- numeric(length(k_values))

# Loop buat cari akurasi tiap k
for (i in k_values) {
  pred_k <- knn(train = train_dummy, test = test_dummy, cl = trainLabel, k = i)
  acc <- confusionMatrix(pred_k, testLabel, positive = "yes")$overall['Accuracy']
  accuracy_k[i] <- acc
}

# Cari k dengan akurasi terbaik
best_k <- which.max(accuracy_k)
k <- best_k
cat("k terbaik adalah:", best_k, "dengan akurasi", round(accuracy_k[best_k] * 100, 2), "%\n")
## k terbaik adalah: 8 dengan akurasi 90.04 %
# Visualisasi akurasi k terbaik
plot(k_values, accuracy_k, type = "b", pch = 19, col = "blue",
     xlab = "Nilai k", ylab = "Akurasi", main = "Cari k Terbaik buat kNN")
abline(v = best_k, col = "red", lty = 2)

Pembuatan model KNN serta prediksi data training dan testing

pred_train <- knn(trainData, trainData, cl = trainLabel, k = k)
cm_train <- confusionMatrix(pred_train, trainLabel, positive = "no")

pred_test <- knn(trainData, testData, cl = trainLabel, k = k)
cm_test <- confusionMatrix(pred_test, testLabel, positive = "no")

Metrik Evaluasi

accuracy_knn_train <- cm_train$overall["Accuracy"]
precision_knn_train <- cm_train$byClass["Precision"]
recall_knn_train <- cm_train$byClass["Recall"]
f1_knn_train <- cm_train$byClass["F1"]

accuracy_knn_test <- cm_test$overall["Accuracy"]
precision_knn_test <- cm_test$byClass["Precision"]
recall_knn_test <- cm_test$byClass["Recall"]
f1_knn_test <- cm_test$byClass["F1"]

cat("\nConfusion Matrix data training (80:20)\n")
## 
## Confusion Matrix data training (80:20)
print(cm_train$table)
##           Reference
## Prediction   no  yes
##        no  3151  314
##        yes   49  103
cat("\nConfusion Matrix data testing (80:20)\n")
## 
## Confusion Matrix data testing (80:20)
print(cm_test$table)
##           Reference
## Prediction  no yes
##        no  787  81
##        yes  13  23
cat("=== Hasil Evaluasi k-Nearest Neighbor ===\n\n")
## === Hasil Evaluasi k-Nearest Neighbor ===
cat("Data Training:\n")
## Data Training:
cat("Akurasi  :", round(accuracy_knn_train * 100, 2), "%\n")
## Akurasi  : 89.96 %
cat("Presisi  :", round(precision_knn_train * 100, 2), "%\n")
## Presisi  : 90.94 %
cat("Recall   :", round(recall_knn_train * 100, 2), "%\n")
## Recall   : 98.47 %
cat("F1 Score :", round(f1_knn_train * 100, 2), "%\n\n")
## F1 Score : 94.55 %
cat("Data Testing:\n")
## Data Testing:
cat("Akurasi  :", round(accuracy_knn_test * 100, 2), "%\n")
## Akurasi  : 89.6 %
cat("Presisi  :", round(precision_knn_test * 100, 2), "%\n")
## Presisi  : 90.67 %
cat("Recall   :", round(recall_knn_test * 100, 2), "%\n")
## Recall   : 98.38 %
cat("F1 Score :", round(f1_knn_test * 100, 2), "%\n")
## F1 Score : 94.36 %

Random Forest

data$job <- as.factor(data$job)
data$marital <- as.factor(data$marital)
data$education <- as.factor(data$education)
data$default <- as.factor(data$default)
data$housing <- as.factor(data$housing)
data$loan <- as.factor(data$loan)
data$contact <- as.factor(data$contact)
data$month <- as.factor(data$month)
data$poutcome <- as.factor(data$poutcome)
data$y <- as.factor(data$y)

set.seed(123) 

# Bagi data 80% training, 20% testing
inTrain <- createDataPartition(data$y, p = 0.8, list = FALSE)
trainData <- data[inTrain, ]
testData  <- data[-inTrain, ]

Pembentukan Model Random Forest

model_rf <- randomForest(y ~ ., data = trainData,
                         ntree = 100,
                         mtry = 2,
                         maxnodes = 30,
                         importance = TRUE)

Metrik evaluasi

# Prediksi data training dan testing
pred_train_rf <- predict(model_rf, trainData)
pred_test_rf  <- predict(model_rf, testData)

# Confusion Matrix
conf_train_rf <- confusionMatrix(pred_train_rf, trainData$y, positive = "no")
conf_test_rf  <- confusionMatrix(pred_test_rf, testData$y, positive = "no")

# Metrik Evaluasi
accuracy_rf_train <- conf_train_rf$overall['Accuracy']
precision_rf_train <- conf_train_rf$byClass['Precision']
recall_rf_train <- conf_train_rf$byClass['Recall']
f1_rf_train <- F1_Score(y_pred = pred_train_rf, y_true = trainData$y, positive = "no")

accuracy_rf_test <- conf_test_rf$overall['Accuracy']
precision_rf_test <- conf_test_rf$byClass['Precision']
recall_rf_test <- conf_test_rf$byClass['Recall']
f1_rf_test <- F1_Score(y_pred = pred_test_rf, y_true = testData$y, positive = "no")

cat("\nConfusion Matrix data training (80:20)\n")
## 
## Confusion Matrix data training (80:20)
print(conf_train_rf$table)
##           Reference
## Prediction   no  yes
##        no  3200  371
##        yes    0   46
cat("\nConfusion Matrix data testing (80:20)\n")
## 
## Confusion Matrix data testing (80:20)
print(conf_test_rf$table)
##           Reference
## Prediction  no yes
##        no  798 100
##        yes   2   4
cat("=== Hasil Evaluasi Random Forest ===\n\n")
## === Hasil Evaluasi Random Forest ===
cat("Data Training:\n")
## Data Training:
cat("Akurasi  :", round(accuracy_rf_train * 100, 2), "%\n")
## Akurasi  : 89.74 %
cat("Presisi  :", round(precision_rf_train * 100, 2), "%\n")
## Presisi  : 89.61 %
cat("Recall   :", round(recall_rf_train * 100, 2), "%\n")
## Recall   : 100 %
cat("F1 Score :", round(f1_rf_train * 100, 2), "%\n\n")
## F1 Score : 94.52 %
cat("Data Testing:\n")
## Data Testing:
cat("Akurasi  :", round(accuracy_rf_test * 100, 2), "%\n")
## Akurasi  : 88.72 %
cat("Presisi  :", round(precision_rf_test * 100, 2), "%\n")
## Presisi  : 88.86 %
cat("Recall   :", round(recall_rf_test * 100, 2), "%\n")
## Recall   : 99.75 %
cat("F1 Score :", round(f1_rf_test * 100, 2), "%\n")
## F1 Score : 93.99 %

ANN

data <- read_excel("hasil_resampling_bank.xlsx")

data$job <- as.factor(data$job)
data$marital <- as.factor(data$marital)
data$education <- as.factor(data$education)
data$default <- as.factor(data$default)
data$housing <- as.factor(data$housing)
data$loan <- as.factor(data$loan)
data$contact <- as.factor(data$contact)
data$month <- as.factor(data$month)
data$poutcome <- as.factor(data$poutcome)
data$y <- as.factor(data$y)
head(data)
str(data)
## tibble [8,000 × 17] (S3: tbl_df/tbl/data.frame)
##  $ Age      : num [1:8000] 30 33 35 30 59 35 36 39 41 43 ...
##  $ job      : Factor w/ 12 levels "admin.","blue-collar",..: 11 8 5 5 2 5 7 10 3 8 ...
##  $ marital  : Factor w/ 3 levels "divorced","married",..: 2 2 3 2 2 3 2 2 2 2 ...
##  $ education: Factor w/ 4 levels "primary","secondary",..: 1 2 3 3 2 3 3 2 3 1 ...
##  $ default  : Factor w/ 2 levels "no","yes": 1 1 1 1 1 1 1 1 1 1 ...
##  $ balance  : num [1:8000] 1787 4789 1350 1476 0 ...
##  $ housing  : Factor w/ 2 levels "no","yes": 1 2 2 2 2 1 2 2 2 2 ...
##  $ loan     : Factor w/ 2 levels "no","yes": 1 2 1 2 1 1 1 1 1 2 ...
##  $ contact  : Factor w/ 3 levels "cellular","telephone",..: 1 1 1 3 3 1 1 1 3 1 ...
##  $ day      : num [1:8000] 19 11 16 3 5 23 14 6 14 17 ...
##  $ month    : Factor w/ 12 levels "apr","aug","dec",..: 11 9 1 7 9 4 9 9 9 1 ...
##  $ duration : num [1:8000] 79 220 185 199 226 141 341 151 57 313 ...
##  $ campaign : num [1:8000] 1 1 1 4 1 2 1 2 2 1 ...
##  $ pdays    : num [1:8000] -1 339 330 -1 -1 176 330 -1 -1 147 ...
##  $ previous : num [1:8000] 0 4 1 0 0 3 2 0 0 2 ...
##  $ poutcome : Factor w/ 4 levels "failure","other",..: 4 1 1 4 4 1 2 4 4 1 ...
##  $ y        : Factor w/ 2 levels "no","yes": 1 1 1 1 1 1 1 1 1 1 ...
# Coba ANN
# OHE untuk seluruh variabel kategorik
categorical_cols <- c("job", "marital", "education", "default", "housing", "loan", "contact", "month", "poutcome")

# Gabungkan semua hasil OHE dari semua kolom
ohe_all <- do.call(cbind, lapply(categorical_cols, function(col) {
  model.matrix(~ . -1, data = data[col])
}))

data_numeric <- data[ , !(names(data) %in% categorical_cols)]
data2 <- cbind(data_numeric, ohe_all)

head(data2)
set.seed(123)

train.index <- createDataPartition(data2$y, p = 0.8, list = FALSE)
train2 <- data2[train.index, ]
test2 <- data2[-train.index, ]

# Preprocessing untuk scaling range (min-max ke 0-1)
preprocessParams <- preProcess(train2[, -8], method = c("range"))

# Transformasi data training dan testing
train_X <- as.matrix(predict(preprocessParams, train2[, -8]))
test_X <- as.matrix(predict(preprocessParams, test2[, -8]))

train_y <- as.numeric(train2[,8])-1
test_y <- as.numeric(test2[,8])-1

# Gabungkan data fitur dan target menjadi satu data frame
train_data <- data.frame(train_X)
train_data$y <- train_y

test_data <- data.frame(test_X)
test_data$y <- test_y

head(train_data)
head(test_data)
# Neural Net Model
n <- names(train_data)
f <- as.formula(paste("y ~", paste(n[!n %in% "y"], collapse = " + ")))
nn <- neuralnet(f, data=train_data, hidden=c(8,5,3), linear.output=FALSE)

Prediksi dan evaluasi data training

# hitung prediksi
pr.nn <- compute(nn, train_data)

# Klasifikasi biner (threshold 0.5)
roundedresults <- ifelse(pr.nn$net.result > 0.5, 1, 0)

# Gabungkan dengan nilai aktual
results <- data.frame(actual = train_data$y, prediction = roundedresults)

# Ubah ke factor dengan level yang sama dan urutan sama
actual <- factor(results$actual, levels = c(0, 1))
predicted <- factor(results$prediction, levels = c(0, 1))

library(caret)
library(MLmetrics)


# Confusion Matrix
conf_mat <- confusionMatrix(predicted, actual, positive = "0")
print(conf_mat)
## Confusion Matrix and Statistics
## 
##           Reference
## Prediction    0    1
##          0 3036  104
##          1  164 3096
##                                           
##                Accuracy : 0.9581          
##                  95% CI : (0.9529, 0.9629)
##     No Information Rate : 0.5             
##     P-Value [Acc > NIR] : < 2.2e-16       
##                                           
##                   Kappa : 0.9162          
##                                           
##  Mcnemar's Test P-Value : 0.0003134       
##                                           
##             Sensitivity : 0.9487          
##             Specificity : 0.9675          
##          Pos Pred Value : 0.9669          
##          Neg Pred Value : 0.9497          
##              Prevalence : 0.5000          
##          Detection Rate : 0.4744          
##    Detection Prevalence : 0.4906          
##       Balanced Accuracy : 0.9581          
##                                           
##        'Positive' Class : 0               
## 
precision <- conf_mat$byClass["Precision"]
recall <- conf_mat$byClass["Recall"]
f1 <- 2 * ((precision * recall) / (precision + recall))

cat("Precision:", round(precision, 4), "\n")
## Precision: 0.9669
cat("Recall   :", round(recall, 4), "\n")
## Recall   : 0.9488
cat("F1 Score :", round(f1, 4), "\n")
## F1 Score : 0.9577

Prediksi dan evaluasi data testing

# hitung prediksi
pr.nn <- compute(nn, test_data)

# Klasifikasi biner (threshold 0.5)
roundedresults <- ifelse(pr.nn$net.result > 0.5, 1, 0)

# Gabungkan dengan nilai aktual
results <- data.frame(actual = test_data$y, prediction = roundedresults)

# Ubah ke factor dengan level yang sama dan urutan sama
actual <- factor(results$actual, levels = c(0, 1))
predicted <- factor(results$prediction, levels = c(0, 1))

library(caret)
library(MLmetrics)


# Confusion Matrix
conf_mat <- confusionMatrix(predicted, actual, positive = "0")
print(conf_mat)
## Confusion Matrix and Statistics
## 
##           Reference
## Prediction   0   1
##          0 702  94
##          1  98 706
##                                           
##                Accuracy : 0.88            
##                  95% CI : (0.8631, 0.8955)
##     No Information Rate : 0.5             
##     P-Value [Acc > NIR] : <2e-16          
##                                           
##                   Kappa : 0.76            
##                                           
##  Mcnemar's Test P-Value : 0.8286          
##                                           
##             Sensitivity : 0.8775          
##             Specificity : 0.8825          
##          Pos Pred Value : 0.8819          
##          Neg Pred Value : 0.8781          
##              Prevalence : 0.5000          
##          Detection Rate : 0.4387          
##    Detection Prevalence : 0.4975          
##       Balanced Accuracy : 0.8800          
##                                           
##        'Positive' Class : 0               
## 
precision <- conf_mat$byClass["Precision"]
recall <- conf_mat$byClass["Recall"]
f1 <- 2 * ((precision * recall) / (precision + recall))

cat("Precision:", round(precision, 4), "\n")
## Precision: 0.8819
cat("Recall   :", round(recall, 4), "\n")
## Recall   : 0.8775
cat("F1 Score :", round(f1, 4), "\n")
## F1 Score : 0.8797

Visualisasi model ANN

nn$result.matrix
##                                         [,1]
## error                           1.340071e+02
## reached.threshold               9.706640e-03
## steps                           3.613100e+04
## Intercept.to.1layhid1           1.975204e+00
## Age.to.1layhid1                 1.668632e+00
## balance.to.1layhid1            -3.040156e+01
## day.to.1layhid1                -9.076192e-01
## duration.to.1layhid1           -2.957858e+00
## campaign.to.1layhid1           -3.683431e+00
## pdays.to.1layhid1              -3.753081e+00
## previous.to.1layhid1           -5.223280e+01
## jobadmin..to.1layhid1           1.535609e+00
## jobblue.collar.to.1layhid1      2.714064e+00
## jobentrepreneur.to.1layhid1    -6.463774e+00
## jobhousemaid.to.1layhid1        4.326269e+00
## jobmanagement.to.1layhid1       4.925302e-01
## jobretired.to.1layhid1          1.301833e+00
## jobself.employed.to.1layhid1    5.464124e+00
## jobservices.to.1layhid1         4.012648e+00
## jobstudent.to.1layhid1          5.170893e+00
## jobtechnician.to.1layhid1      -3.925145e-01
## jobunemployed.to.1layhid1      -1.522507e+00
## jobunknown.to.1layhid1          8.810766e-03
## maritaldivorced.to.1layhid1     2.896108e+00
## maritalmarried.to.1layhid1     -1.914043e-01
## maritalsingle.to.1layhid1       2.031094e+00
## educationprimary.to.1layhid1    4.688999e+00
## educationsecondary.to.1layhid1 -7.208166e-01
## educationtertiary.to.1layhid1  -6.530851e-01
## educationunknown.to.1layhid1    1.027968e+01
## defaultno.to.1layhid1          -4.925499e-01
## defaultyes.to.1layhid1          7.521522e+01
## housingno.to.1layhid1           4.447278e-01
## housingyes.to.1layhid1         -5.698732e-01
## loanno.to.1layhid1             -3.513318e-01
## loanyes.to.1layhid1             1.275892e+00
## contactcellular.to.1layhid1    -1.698724e+00
## contacttelephone.to.1layhid1    4.203408e+01
## contactunknown.to.1layhid1      9.108666e+01
## monthapr.to.1layhid1           -9.285824e+00
## monthaug.to.1layhid1            8.338260e-01
## monthdec.to.1layhid1           -7.407754e+02
## monthfeb.to.1layhid1           -3.464521e+00
## monthjan.to.1layhid1           -1.046900e+00
## monthjul.to.1layhid1            1.058604e+01
## monthjun.to.1layhid1           -4.136037e+01
## monthmar.to.1layhid1            1.987118e+00
## monthmay.to.1layhid1            2.534901e+00
## monthnov.to.1layhid1            1.934157e+00
## monthoct.to.1layhid1           -8.667004e+00
## monthsep.to.1layhid1           -1.342122e+00
## poutcomefailure.to.1layhid1    -8.762008e-01
## poutcomeother.to.1layhid1      -2.474319e+01
## poutcomesuccess.to.1layhid1    -8.732492e+00
## poutcomeunknown.to.1layhid1     7.187486e-01
## Intercept.to.1layhid2           1.638201e+00
## Age.to.1layhid2                -1.083790e+01
## balance.to.1layhid2             2.854567e+00
## day.to.1layhid2                 2.518339e-01
## duration.to.1layhid2           -1.482113e+01
## campaign.to.1layhid2            6.171783e+00
## pdays.to.1layhid2              -8.574658e+01
## previous.to.1layhid2           -8.292213e+01
## jobadmin..to.1layhid2          -2.451990e+00
## jobblue.collar.to.1layhid2      8.280909e-01
## jobentrepreneur.to.1layhid2    -4.487023e+00
## jobhousemaid.to.1layhid2        2.116652e+01
## jobmanagement.to.1layhid2       2.167646e+00
## jobretired.to.1layhid2         -7.351176e+02
## jobself.employed.to.1layhid2   -7.113095e-01
## jobservices.to.1layhid2         6.003828e+01
## jobstudent.to.1layhid2          2.898153e+00
## jobtechnician.to.1layhid2      -1.296873e+00
## jobunemployed.to.1layhid2       1.994518e+01
## jobunknown.to.1layhid2          4.678846e+00
## maritaldivorced.to.1layhid2    -4.702801e-02
## maritalmarried.to.1layhid2      2.965980e-01
## maritalsingle.to.1layhid2       1.219299e+00
## educationprimary.to.1layhid2   -1.257842e+01
## educationsecondary.to.1layhid2 -1.205702e-01
## educationtertiary.to.1layhid2  -1.435531e+00
## educationunknown.to.1layhid2    1.893297e+00
## defaultno.to.1layhid2           1.822150e+00
## defaultyes.to.1layhid2          9.343637e+00
## housingno.to.1layhid2           5.748477e-01
## housingyes.to.1layhid2          2.560908e-03
## loanno.to.1layhid2             -3.708647e-01
## loanyes.to.1layhid2            -7.261535e-01
## contactcellular.to.1layhid2    -1.170709e+00
## contacttelephone.to.1layhid2   -8.285774e+00
## contactunknown.to.1layhid2      8.494272e+00
## monthapr.to.1layhid2           -2.495126e+00
## monthaug.to.1layhid2            3.968568e+00
## monthdec.to.1layhid2           -1.437963e+01
## monthfeb.to.1layhid2           -1.643491e+00
## monthjan.to.1layhid2            6.603103e+00
## monthjul.to.1layhid2            3.488060e+00
## monthjun.to.1layhid2           -4.124838e-02
## monthmar.to.1layhid2           -3.401314e+00
## monthmay.to.1layhid2            3.769992e+00
## monthnov.to.1layhid2           -6.255529e+01
## monthoct.to.1layhid2            2.354466e+00
## monthsep.to.1layhid2            4.220002e+00
## poutcomefailure.to.1layhid2    -9.954650e+00
## poutcomeother.to.1layhid2      -4.273616e+01
## poutcomesuccess.to.1layhid2     2.688975e+01
## poutcomeunknown.to.1layhid2     6.788900e-01
## Intercept.to.1layhid3          -1.211151e-01
## Age.to.1layhid3                 3.767028e+00
## balance.to.1layhid3            -5.717472e+00
## day.to.1layhid3                 1.859613e+00
## duration.to.1layhid3            7.529707e+00
## campaign.to.1layhid3           -4.909695e+00
## pdays.to.1layhid3              -3.458005e+00
## previous.to.1layhid3            3.071345e+00
## jobadmin..to.1layhid3           2.406757e+00
## jobblue.collar.to.1layhid3     -1.552772e+00
## jobentrepreneur.to.1layhid3    -3.639860e-01
## jobhousemaid.to.1layhid3        3.735712e+01
## jobmanagement.to.1layhid3       1.689742e+00
## jobretired.to.1layhid3         -2.676279e-01
## jobself.employed.to.1layhid3   -4.779314e-01
## jobservices.to.1layhid3         2.895380e+00
## jobstudent.to.1layhid3          4.317940e+00
## jobtechnician.to.1layhid3       3.785529e-01
## jobunemployed.to.1layhid3       2.182154e+00
## jobunknown.to.1layhid3          3.839135e+01
## maritaldivorced.to.1layhid3     4.478692e+00
## maritalmarried.to.1layhid3     -2.354050e-01
## maritalsingle.to.1layhid3      -1.167574e+00
## educationprimary.to.1layhid3   -2.702746e-02
## educationsecondary.to.1layhid3  1.938854e+00
## educationtertiary.to.1layhid3   1.303102e+00
## educationunknown.to.1layhid3   -1.568601e+00
## defaultno.to.1layhid3          -9.463171e-02
## defaultyes.to.1layhid3         -3.119093e+00
## housingno.to.1layhid3           1.224395e+00
## housingyes.to.1layhid3          7.633154e-01
## loanno.to.1layhid3             -4.339480e-01
## loanyes.to.1layhid3            -1.555969e+00
## contactcellular.to.1layhid3    -1.085216e+00
## contacttelephone.to.1layhid3    2.426987e+00
## contactunknown.to.1layhid3      1.264403e+00
## monthapr.to.1layhid3           -3.009921e+00
## monthaug.to.1layhid3            2.447327e+00
## monthdec.to.1layhid3           -1.532837e+00
## monthfeb.to.1layhid3           -8.133975e-01
## monthjan.to.1layhid3            5.608743e-01
## monthjul.to.1layhid3           -3.803332e-02
## monthjun.to.1layhid3           -7.907242e-01
## monthmar.to.1layhid3           -6.112525e-01
## monthmay.to.1layhid3           -6.092909e-01
## monthnov.to.1layhid3            2.299170e-01
## monthoct.to.1layhid3           -1.507089e+00
## monthsep.to.1layhid3            1.936756e+00
## poutcomefailure.to.1layhid3    -1.373468e+00
## poutcomeother.to.1layhid3      -4.362537e+00
## poutcomesuccess.to.1layhid3     2.950444e-01
## poutcomeunknown.to.1layhid3    -2.960709e-03
## Intercept.to.1layhid4          -2.013953e-02
## Age.to.1layhid4                 1.874468e+00
## balance.to.1layhid4            -1.121124e+01
## day.to.1layhid4                -8.087830e-01
## duration.to.1layhid4            2.582736e+00
## campaign.to.1layhid4           -5.269388e+00
## pdays.to.1layhid4               1.633003e+01
## previous.to.1layhid4            6.736636e+00
## jobadmin..to.1layhid4           3.082387e+00
## jobblue.collar.to.1layhid4      6.833489e-01
## jobentrepreneur.to.1layhid4     6.389576e+00
## jobhousemaid.to.1layhid4        3.090919e+00
## jobmanagement.to.1layhid4      -1.044484e+00
## jobretired.to.1layhid4          2.466396e+00
## jobself.employed.to.1layhid4    6.204782e+00
## jobservices.to.1layhid4         3.377038e-01
## jobstudent.to.1layhid4          2.059337e+00
## jobtechnician.to.1layhid4      -1.637070e+00
## jobunemployed.to.1layhid4       3.223043e-01
## jobunknown.to.1layhid4          3.387101e+00
## maritaldivorced.to.1layhid4    -2.265562e+00
## maritalmarried.to.1layhid4     -5.437309e-02
## maritalsingle.to.1layhid4       1.256398e+00
## educationprimary.to.1layhid4   -3.338930e+00
## educationsecondary.to.1layhid4  1.146023e+00
## educationtertiary.to.1layhid4  -2.094604e-01
## educationunknown.to.1layhid4   -2.572655e+00
## defaultno.to.1layhid4          -1.847496e+00
## defaultyes.to.1layhid4          3.758072e+00
## housingno.to.1layhid4           1.141656e+00
## housingyes.to.1layhid4         -1.261458e+00
## loanno.to.1layhid4             -1.128927e+00
## loanyes.to.1layhid4             3.971313e+01
## contactcellular.to.1layhid4     1.813991e+00
## contacttelephone.to.1layhid4   -3.848781e+00
## contactunknown.to.1layhid4      2.400305e-01
## monthapr.to.1layhid4            1.297694e+00
## monthaug.to.1layhid4           -3.838629e+00
## monthdec.to.1layhid4            4.462433e+01
## monthfeb.to.1layhid4            3.048197e+00
## monthjan.to.1layhid4            1.778936e+00
## monthjul.to.1layhid4            2.166718e+00
## monthjun.to.1layhid4           -1.851284e+00
## monthmar.to.1layhid4           -3.120169e-02
## monthmay.to.1layhid4            1.974647e-01
## monthnov.to.1layhid4            2.127073e-01
## monthoct.to.1layhid4            3.217641e+00
## monthsep.to.1layhid4            4.512883e+01
## poutcomefailure.to.1layhid4    -1.059641e+00
## poutcomeother.to.1layhid4      -6.085642e+00
## poutcomesuccess.to.1layhid4     1.049240e+00
## poutcomeunknown.to.1layhid4     1.150864e+00
## Intercept.to.1layhid5          -8.014707e-01
## Age.to.1layhid5                 2.118969e+00
## balance.to.1layhid5             5.886851e+00
## day.to.1layhid5                 1.367999e-01
## duration.to.1layhid5           -7.280472e+00
## campaign.to.1layhid5           -1.962592e+00
## pdays.to.1layhid5              -1.152373e+00
## previous.to.1layhid5            4.318907e+00
## jobadmin..to.1layhid5           1.095796e+00
## jobblue.collar.to.1layhid5      4.233552e-01
## jobentrepreneur.to.1layhid5     1.133980e+00
## jobhousemaid.to.1layhid5       -2.052282e+00
## jobmanagement.to.1layhid5      -2.967160e-01
## jobretired.to.1layhid5         -1.182918e-01
## jobself.employed.to.1layhid5    1.892145e+00
## jobservices.to.1layhid5         1.224944e-01
## jobstudent.to.1layhid5         -5.981062e-01
## jobtechnician.to.1layhid5      -8.793426e-02
## jobunemployed.to.1layhid5      -1.068323e+00
## jobunknown.to.1layhid5         -7.784582e-01
## maritaldivorced.to.1layhid5     8.096876e-01
## maritalmarried.to.1layhid5      9.197937e-01
## maritalsingle.to.1layhid5       5.241361e-01
## educationprimary.to.1layhid5   -6.193330e-01
## educationsecondary.to.1layhid5 -1.439214e-01
## educationtertiary.to.1layhid5  -2.263765e+00
## educationunknown.to.1layhid5   -4.674116e+00
## defaultno.to.1layhid5           1.332003e+00
## defaultyes.to.1layhid5          1.873611e-01
## housingno.to.1layhid5           7.509898e-01
## housingyes.to.1layhid5          4.656725e-01
## loanno.to.1layhid5             -4.357132e-01
## loanyes.to.1layhid5             1.704860e+00
## contactcellular.to.1layhid5    -2.179870e+00
## contacttelephone.to.1layhid5   -1.546849e+00
## contactunknown.to.1layhid5     -1.632913e+00
## monthapr.to.1layhid5            1.135625e+00
## monthaug.to.1layhid5           -4.044784e-02
## monthdec.to.1layhid5            1.142537e+00
## monthfeb.to.1layhid5           -9.246845e-01
## monthjan.to.1layhid5           -8.148539e-01
## monthjul.to.1layhid5            8.254016e-01
## monthjun.to.1layhid5            7.177342e-01
## monthmar.to.1layhid5           -9.880548e-01
## monthmay.to.1layhid5           -8.768715e-02
## monthnov.to.1layhid5            3.491425e-01
## monthoct.to.1layhid5           -9.517497e-02
## monthsep.to.1layhid5            1.727633e+00
## poutcomefailure.to.1layhid5    -8.598706e-01
## poutcomeother.to.1layhid5      -9.158963e-02
## poutcomesuccess.to.1layhid5     5.884042e-01
## poutcomeunknown.to.1layhid5    -1.176170e-01
## Intercept.to.1layhid6           3.240919e-01
## Age.to.1layhid6                 6.227236e-01
## balance.to.1layhid6            -1.366494e+00
## day.to.1layhid6                 7.583054e-01
## duration.to.1layhid6           -6.547001e+00
## campaign.to.1layhid6            7.076069e+00
## pdays.to.1layhid6              -4.169861e+00
## previous.to.1layhid6            4.116486e+00
## jobadmin..to.1layhid6          -2.605494e+00
## jobblue.collar.to.1layhid6     -1.019714e+00
## jobentrepreneur.to.1layhid6     6.581063e-01
## jobhousemaid.to.1layhid6        1.673953e+00
## jobmanagement.to.1layhid6      -8.015288e-01
## jobretired.to.1layhid6          1.431530e+00
## jobself.employed.to.1layhid6   -2.300897e+00
## jobservices.to.1layhid6        -2.908955e+00
## jobstudent.to.1layhid6         -7.834468e-01
## jobtechnician.to.1layhid6      -1.995835e+00
## jobunemployed.to.1layhid6       3.906728e-01
## jobunknown.to.1layhid6          3.993257e+00
## maritaldivorced.to.1layhid6    -4.724340e-01
## maritalmarried.to.1layhid6     -9.935489e-01
## maritalsingle.to.1layhid6      -8.932758e-01
## educationprimary.to.1layhid6    1.545002e+00
## educationsecondary.to.1layhid6  6.237506e-01
## educationtertiary.to.1layhid6   1.735870e+00
## educationunknown.to.1layhid6    9.323191e-01
## defaultno.to.1layhid6          -7.406047e-01
## defaultyes.to.1layhid6         -2.273366e+00
## housingno.to.1layhid6           5.158255e-01
## housingyes.to.1layhid6          5.485593e-01
## loanno.to.1layhid6              1.518058e+00
## loanyes.to.1layhid6             5.847989e-01
## contactcellular.to.1layhid6    -1.818752e+00
## contacttelephone.to.1layhid6   -5.547683e+00
## contactunknown.to.1layhid6     -2.218675e+00
## monthapr.to.1layhid6           -1.889535e+00
## monthaug.to.1layhid6            1.043774e-01
## monthdec.to.1layhid6           -2.948089e+00
## monthfeb.to.1layhid6            3.599427e+00
## monthjan.to.1layhid6            7.610154e-02
## monthjul.to.1layhid6           -2.843504e-02
## monthjun.to.1layhid6            8.953096e-02
## monthmar.to.1layhid6            1.038799e+00
## monthmay.to.1layhid6           -1.687799e-01
## monthnov.to.1layhid6            9.113074e-01
## monthoct.to.1layhid6            1.014731e+00
## monthsep.to.1layhid6           -2.428020e+00
## poutcomefailure.to.1layhid6     1.469164e+00
## poutcomeother.to.1layhid6      -2.192679e+00
## poutcomesuccess.to.1layhid6    -1.687175e+00
## poutcomeunknown.to.1layhid6    -4.228287e-01
## Intercept.to.1layhid7           2.026868e-03
## Age.to.1layhid7                -1.448299e-01
## balance.to.1layhid7             1.768417e+00
## day.to.1layhid7                -3.983240e-01
## duration.to.1layhid7           -6.443581e+00
## campaign.to.1layhid7            1.058362e+01
## pdays.to.1layhid7              -1.382957e+01
## previous.to.1layhid7           -2.310302e+01
## jobadmin..to.1layhid7           1.060357e+00
## jobblue.collar.to.1layhid7     -9.854690e-01
## jobentrepreneur.to.1layhid7     7.143458e-01
## jobhousemaid.to.1layhid7       -1.436132e+00
## jobmanagement.to.1layhid7      -1.423057e+00
## jobretired.to.1layhid7         -5.802621e+00
## jobself.employed.to.1layhid7   -2.194979e-01
## jobservices.to.1layhid7         7.175454e-01
## jobstudent.to.1layhid7         -2.142418e+00
## jobtechnician.to.1layhid7       8.701030e-01
## jobunemployed.to.1layhid7      -1.543054e+00
## jobunknown.to.1layhid7         -9.775145e-01
## maritaldivorced.to.1layhid7    -1.156470e+00
## maritalmarried.to.1layhid7     -6.432414e-02
## maritalsingle.to.1layhid7      -6.119126e-01
## educationprimary.to.1layhid7   -2.693771e+00
## educationsecondary.to.1layhid7  8.062236e-02
## educationtertiary.to.1layhid7   1.819977e+00
## educationunknown.to.1layhid7   -3.702648e+00
## defaultno.to.1layhid7          -8.849730e-01
## defaultyes.to.1layhid7          3.780477e+00
## housingno.to.1layhid7          -2.077743e-01
## housingyes.to.1layhid7          8.940361e-01
## loanno.to.1layhid7             -4.715617e-01
## loanyes.to.1layhid7             6.182554e+00
## contactcellular.to.1layhid7    -8.275624e-01
## contacttelephone.to.1layhid7   -1.309059e+00
## contactunknown.to.1layhid7     -5.532929e+00
## monthapr.to.1layhid7            1.227994e+00
## monthaug.to.1layhid7           -3.261886e-01
## monthdec.to.1layhid7            1.602546e+00
## monthfeb.to.1layhid7            4.205807e-01
## monthjan.to.1layhid7            7.420173e+00
## monthjul.to.1layhid7            5.846033e-02
## monthjun.to.1layhid7           -1.469159e-01
## monthmar.to.1layhid7           -7.122293e+02
## monthmay.to.1layhid7           -6.531647e-01
## monthnov.to.1layhid7            2.412804e+00
## monthoct.to.1layhid7            1.611539e+00
## monthsep.to.1layhid7           -1.024100e+01
## poutcomefailure.to.1layhid7     3.370180e+00
## poutcomeother.to.1layhid7      -7.155617e+02
## poutcomesuccess.to.1layhid7    -3.526581e-01
## poutcomeunknown.to.1layhid7     1.441394e+00
## Intercept.to.1layhid8          -1.137443e+00
## Age.to.1layhid8                -8.046675e-01
## balance.to.1layhid8             2.185474e+00
## day.to.1layhid8                -1.056169e+00
## duration.to.1layhid8           -5.607305e+00
## campaign.to.1layhid8           -1.106516e+01
## pdays.to.1layhid8               1.747275e+00
## previous.to.1layhid8           -3.256033e-01
## jobadmin..to.1layhid8          -1.368639e-01
## jobblue.collar.to.1layhid8     -1.555564e+00
## jobentrepreneur.to.1layhid8    -2.340250e+00
## jobhousemaid.to.1layhid8       -1.256247e+00
## jobmanagement.to.1layhid8      -1.013798e+00
## jobretired.to.1layhid8         -7.351182e-01
## jobself.employed.to.1layhid8   -1.516385e-01
## jobservices.to.1layhid8        -7.202693e-02
## jobstudent.to.1layhid8          1.756603e+00
## jobtechnician.to.1layhid8      -9.075744e-01
## jobunemployed.to.1layhid8       1.763425e+00
## jobunknown.to.1layhid8         -7.087506e+02
## maritaldivorced.to.1layhid8     6.280788e-01
## maritalmarried.to.1layhid8     -5.342433e-02
## maritalsingle.to.1layhid8       3.179200e-01
## educationprimary.to.1layhid8   -2.118051e+00
## educationsecondary.to.1layhid8 -8.975179e-03
## educationtertiary.to.1layhid8   5.234190e-01
## educationunknown.to.1layhid8    5.753391e+00
## defaultno.to.1layhid8          -2.182268e-01
## defaultyes.to.1layhid8          3.438158e-01
## housingno.to.1layhid8          -3.834396e-01
## housingyes.to.1layhid8          4.210381e-02
## loanno.to.1layhid8              2.263096e-01
## loanyes.to.1layhid8            -1.139635e+00
## contactcellular.to.1layhid8    -1.044397e+00
## contacttelephone.to.1layhid8    6.537770e-01
## contactunknown.to.1layhid8      1.204741e-01
## monthapr.to.1layhid8           -8.274409e-02
## monthaug.to.1layhid8           -1.102287e+00
## monthdec.to.1layhid8            4.441289e+00
## monthfeb.to.1layhid8           -1.954711e-01
## monthjan.to.1layhid8            1.403906e+00
## monthjul.to.1layhid8           -1.992369e+00
## monthjun.to.1layhid8           -2.503076e+00
## monthmar.to.1layhid8            7.776419e-02
## monthmay.to.1layhid8            1.238685e+00
## monthnov.to.1layhid8           -6.105735e-01
## monthoct.to.1layhid8           -2.279546e+00
## monthsep.to.1layhid8            2.026464e+00
## poutcomefailure.to.1layhid8     3.129039e+00
## poutcomeother.to.1layhid8       2.787396e+00
## poutcomesuccess.to.1layhid8    -3.621444e+00
## poutcomeunknown.to.1layhid8    -1.663585e-02
## Intercept.to.2layhid1          -5.858536e-01
## 1layhid1.to.2layhid1           -9.199081e-02
## 1layhid2.to.2layhid1            1.092584e+00
## 1layhid3.to.2layhid1           -1.923186e+00
## 1layhid4.to.2layhid1           -5.520406e-01
## 1layhid5.to.2layhid1            2.616454e+00
## 1layhid6.to.2layhid1            1.471471e+00
## 1layhid7.to.2layhid1            1.822767e+00
## 1layhid8.to.2layhid1            2.370176e+00
## Intercept.to.2layhid2           5.394650e-01
## 1layhid1.to.2layhid2           -4.661477e-02
## 1layhid2.to.2layhid2           -1.324330e-01
## 1layhid3.to.2layhid2           -4.041279e-01
## 1layhid4.to.2layhid2            1.306686e+00
## 1layhid5.to.2layhid2           -2.376670e+00
## 1layhid6.to.2layhid2           -2.462045e+00
## 1layhid7.to.2layhid2            1.403624e-01
## 1layhid8.to.2layhid2           -2.754111e+00
## Intercept.to.2layhid3           1.169173e-01
## 1layhid1.to.2layhid3           -7.146576e-01
## 1layhid2.to.2layhid3           -3.201807e-01
## 1layhid3.to.2layhid3            1.400138e+00
## 1layhid4.to.2layhid3            1.187377e+00
## 1layhid5.to.2layhid3           -1.752048e+00
## 1layhid6.to.2layhid3           -2.741954e+00
## 1layhid7.to.2layhid3           -1.210214e+00
## 1layhid8.to.2layhid3           -2.889511e+00
## Intercept.to.2layhid4           4.904340e-01
## 1layhid1.to.2layhid4            1.822800e+00
## 1layhid2.to.2layhid4            1.737800e+00
## 1layhid3.to.2layhid4           -2.602749e+00
## 1layhid4.to.2layhid4           -1.410385e+00
## 1layhid5.to.2layhid4            1.372051e+00
## 1layhid6.to.2layhid4            1.877793e+00
## 1layhid7.to.2layhid4            1.399991e+00
## 1layhid8.to.2layhid4            3.022029e+00
## Intercept.to.2layhid5           1.174216e+00
## 1layhid1.to.2layhid5           -1.477989e+00
## 1layhid2.to.2layhid5            5.228013e-01
## 1layhid3.to.2layhid5            1.170513e-01
## 1layhid4.to.2layhid5            1.318623e+00
## 1layhid5.to.2layhid5           -1.921424e+00
## 1layhid6.to.2layhid5           -1.153981e+00
## 1layhid7.to.2layhid5           -2.025604e+00
## 1layhid8.to.2layhid5           -2.511778e+00
## Intercept.to.3layhid1           1.405934e+00
## 2layhid1.to.3layhid1            2.361183e+00
## 2layhid2.to.3layhid1           -3.615932e-01
## 2layhid3.to.3layhid1           -7.873079e-01
## 2layhid4.to.3layhid1            1.263847e+00
## 2layhid5.to.3layhid1           -3.403719e+00
## Intercept.to.3layhid2           1.318123e+00
## 2layhid1.to.3layhid2           -2.739770e+00
## 2layhid2.to.3layhid2            5.292493e-01
## 2layhid3.to.3layhid2            6.552461e-01
## 2layhid4.to.3layhid2           -3.261291e+00
## 2layhid5.to.3layhid2            1.468879e+00
## Intercept.to.3layhid3          -1.506847e+00
## 2layhid1.to.3layhid3           -4.517012e+00
## 2layhid2.to.3layhid3            7.341205e-01
## 2layhid3.to.3layhid3            2.616834e+00
## 2layhid4.to.3layhid3           -1.235771e-01
## 2layhid5.to.3layhid3            2.275952e+00
## Intercept.to.y                 -1.026662e+00
## 3layhid1.to.y                  -2.169668e+02
## 3layhid2.to.y                   4.776645e+02
## 3layhid3.to.y                   6.787929e+01
summary(nn)
##                     Length Class      Mode    
## call                     5 -none-     call    
## response              6400 -none-     numeric 
## covariate           326400 -none-     numeric 
## model.list               2 -none-     list    
## err.fct                  1 -none-     function
## act.fct                  1 -none-     function
## linear.output            1 -none-     logical 
## data                    52 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          486 -none-     numeric
plot(nn)