I couldn't get a good value of R2 and MAPE for each train sets are above 1%-5% (assuming MAPE coding maybe something wrong). Any suggestions to optimise beside hidden neuron?

5 次查看(过去 30 天)
I have tried to use the default settings of transfer function (tansig, purelin) and now tried using 'radbas','tansig'.
Is there any other way I could do to obtain a really good R2 and error values? I have 996 dataset.
The following is my coding:
clc
clear all
format short
%% Import the data
data = xlsread('DATA.xlsx');
x = data(:,1:4);
y = data(:,5);
%% Normalise the data
xt = x';
yt = y';
[xt,ps] = mapminmax(xt);
[yt,ts] = mapminmax(yt);
%xt = normalize(x,'scale');
%yt = normalize(y,'scale');
%% Train an ANN
for i = 1:20; % Find the optimum hidden neuron
net = newff(xt,yt,[i],{'radbas','tansig'},'trainlm');
%Results presentation interval
net.trainParam.show = 50; %Show results for every 50 iterations
%Learning rate
net.trainParam.lr = 0.05;
%Number of iterations
net.trainParam.epochs = 1000;
%Targeted Mean Square Error
net.trainParam.goal = 1e-5;
net.divideParam.trainRatio = 70/100;
net.divideParam.valRatio = 15/100;
net.divideParam.testRatio = 15/100;
[net,tr] = train(net,xt,yt);
yn = sim(net,xt); %simulation
%Denormalisation of Predicted Target
y_pred = mapminmax('reverse',yn,ts);
%Comparison predicted output with actual value
errors = gsubtract(y_pred,y);
%MSE Performance of the ANN
perf = mse(net, y_pred, y,'regularization', 0.01);
%Performance of Train Set
yTrain = (net(xt(:,tr.trainInd)));
yPredTrain = yt(tr.trainInd);
%RSME
RSME_Training = sqrt(mean((yTrain-yPredTrain).^2));
%MSE
MSE_Training = mean((yTrain-yPredTrain).^2);
errorTrain = gsubtract(yPredTrain,yTrain);
%MAE
MAE_Training = mae(errorTrain);
MAPE_Training = mean(abs(errorTrain./yPredTrain))
%Performance of Validation Set
yVal = (net(xt(:,tr.valInd)));
yPredVal = yt(tr.valInd);
%RSME
RSME_Val = sqrt(mean((yVal-yPredVal).^2));
%MSE
MSE_Val = mean((yVal-yPredVal).^2);
errorVal = gsubtract(yPredVal,yVal);
%MAE
MAE_Val = mae(errorVal);
MAPE_Val = mean(abs(errorVal./yPredVal));
%Performance of Test Set
yTest = (net(xt(:,tr.testInd)));
yPredTest = yt(tr.testInd);
%RSME
RSME_Test = sqrt(mean((yTest-yPredTest).^2))
%MSE
MSE_Test = mean((yTest-yPredTest).^2)
errorTest = gsubtract(yPredTest,yTest);
%MAE
MAE_Test = mae(errorTest);
MAPE_Test = mean(abs(errorTest./yPredTest));
end

回答(1 个)

Shubham
Shubham 2024-5-29
Hi Angelina,
Improving the performance (R2 and error values) of an Artificial Neural Network (ANN) model involves multiple aspects, from data preprocessing, network architecture adjustments, to training process optimization. Your approach is fundamentally sound, but there are several areas where enhancements can be made:
1. Data Preprocessing
  • Feature Selection/Engineering: Analyze your input features to identify if all are relevant or if new features can be engineered for better model performance.
  • Outlier Removal: Check for outliers in your dataset that could potentially skew the training process and address them accordingly.
  • Data Augmentation: Although more common in image processing tasks, if applicable, augmenting your data or adding more diversity to the training set can help.
2. Network Architecture
  • Hidden Layers and Neurons: Experimenting with the number of hidden layers and neurons is crucial. A single hidden layer might be insufficient for complex problems, and too many neurons can lead to overfitting. Consider using techniques like cross-validation to find an optimal structure.
  • Activation Functions: While radbas and tansig are your current choices, experimenting with others like relu or leaky relu for hidden layers might yield better results. Activation functions should be chosen based on the problem nature and network architecture.
  • Regularization Techniques: To prevent overfitting, especially with a relatively small dataset, consider implementing regularization techniques such as L2 regularization, dropout, or early stopping based on validation loss.
3. Training Process
  • Learning Rate: Adjusting the learning rate and employing learning rate schedules (e.g., reducing the learning rate when a metric has stopped improving) can significantly affect convergence and performance.
  • Batch Size: Experiment with different batch sizes. Smaller batches can offer a regularizing effect and lower generalization error.
  • Optimization Algorithms: While trainlm (Levenberg-Marquardt) is a powerful algorithm, others like Adam or RMSprop might offer better performance for your specific problem.
4. Evaluation Metrics
  • R2 Score Calculation: Ensure you're calculating and monitoring the R2 score if that's your primary performance metric. Adjusting your model based on MSE alone might not always align with improvements in R2.
  • Cross-Validation: Use k-fold cross-validation to assess the model's performance more reliably, reducing the variance of the performance estimate.
5. Code Enhancements
  • Vectorization: Your error and performance metrics calculation can be vectorized further for efficiency.
  • Looping Over Architectures: Your loop over different hidden neuron counts is a good start, but consider automating the exploration of other hyperparameters as well.
Example Enhancements
  • R2 Score Calculation: After you calculate your predictions, compute the R2 score to directly assess the model's explanatory power.
  • Cross-Validation Implementation: Instead of a single train-test split, implement k-fold cross-validation to ensure the model's robustness and reliability.
Summary:
Improving an ANN's performance is an iterative and experimental process. There's no one-size-fits-all solution, and the best approach often depends on the specific characteristics of your dataset and problem domain. Keep experimenting with different configurations, and consider using automated hyperparameter tuning tools like Bayesian Optimization if available in your working environment.

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by