Problem with"Artificial Neural Network"

To build a feedforward artificial neural network model with 1 hidden layer and present the key results of the model for predicting air blast waves based on the given hypothetical data, let's first translate the variables to English:

  • Lb: Length of blasting column, m
  • Wct: Bottom charge burden, m
  • b: Distance between blastholes, m
  • Q: Maximum total explosive charge per delay, Kg
  • q: Explosive density, Kg/m3
  • D: Distance of air blast wave monitoring, m
  • AOP: Air blast wave overpressure, dB

My code:

library(readxl)
data <- read_excel("D:/data.xlsx")
View(data)
library(neuralnet)

Split the data into training and test sets (80% for training, 20% for testing)

train_data <- data[1:80, c("Lb", "Wct", "b", "Q", "q", "D")]
train_labels <- data[1:80, "AOP"]
test_data <- data[81:nrow(data), c("Lb", "Wct", "b", "Q", "q", "D")]
test_labels <- data[81:nrow(data), "AOP"]

Normalize the data (optional but recommended)

train_data_norm <- scale(train_data)
test_data_norm <- scale(test_data)

Build the neural network model

model <- neuralnet(AOP ~ Lb + Wct + b + Q + q + D, data = train_data_norm, hidden = c(10))
Error in eval(predvars, data, env) : object 'AOP' not found

Can anyone help me complete this code? THANKS!

There must be a variable by this name in train_data_norm

library(readxl)
data <- read_excel("D:/Baitap/data.xlsx")
View(data)

Load the neuralnet package

library(neuralnet)

Split the data into training and test sets (80% for training, 20% for testing)

train_data <- data[1:80, c("Lb", "Wct", "b", "Q", "q", "D", "AOP")]
train_labels <- data[1:80, "AOP"]
test_data <- data[81:100, c("Lb", "Wct", "b", "Q", "q", "D", "AOP")]
test_labels <- data[81:100, "AOP"]

Normalize the data (optional but recommended)

train_data_norm <- scale(train_data)
test_data_norm <- scale(test_data)

Build the neural network model

model <- neuralnet(AOP ~ Lb + Wct + b + Q + q + D, data = train_data_norm, hidden = c(10))

Make predictions on the test set

predictions <- compute(model, test_data_norm)$net.result

Convert test_labels to a vector

test_labels <- unlist(test_labels)

Convert predictions and test_labels to numeric

predictions <- as.numeric(predictions)
test_labels <- as.numeric(test_labels)

Calculate the mean squared error

mse <- mean((predictions - test_labels)^2, na.rm = TRUE)
#Calculate RMSE from MSE
rmse <- sqrt(mse)

Print the key results

cat("Root Mean Squared Error (RMSE):", rmse, "\n")
Root Mean Squared Error (RMSE): 110.553
predictions
[1] -0.27514569 0.60132493 0.93942980 -0.09514141 -0.57754302
[6] -0.03344658 -0.99636708 -0.53039975 0.72270901 0.69162210
[11] 0.36900769 1.66349748 -0.74943723 -0.80595008 -1.41068713
[16] -0.15363472 -1.29964997 -0.14979083 1.07483063 -0.24234422

Thank you very much, the code worked, and i hope it will be correct for the given data:

Lb Wct b Q q D AOP
2.9 1.6 3.9 83.9 0.75 535 102.5
2.8 3 3.4 75.6 0.6 397 110.4
3 3.4 3 71.8 0.66 398 110.2
2.5 2.9 2.9 66.8 0.84 346 106.8
3.5 2.1 4.1 65.1 0.79 476 91.5
3.2 1.8 3.6 76.6 0.78 296 116.8
3.3 3 3.8 66.1 0.57 533 93.5
2.2 1.9 4.2 73 0.84 393 105.4
3.1 2.2 3 71.8 0.75 346 110.1
...
1 Like

This topic was automatically closed 42 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.