matlab BP神经网络

clear

clc

% 准备数据

inputs = rand(10, 100); % 100组输入,每组10个特征

outputs = rand(1, 100); % 100组输出,每组1个输出值

% 将数据分成训练集和测试集

trainRatio = 0.8;

valRatio = 0.1;

testRatio = 0.1;

trainInd, valInd, testInd\] = dividerand(100, trainRatio, valRatio, testRatio); X_train = inputs(:, trainInd); y_train = outputs(:, trainInd); X_test = inputs(:, testInd); y_test = outputs(:, testInd); % 创建前馈神经网络 hiddenLayerSize = 10; net = feedforwardnet(hiddenLayerSize); % 设置训练、验证和测试数据 net.divideParam.trainRatio = 0.8; net.divideParam.valRatio = 0.1; net.divideParam.testRatio = 0.1; % 训练神经网络 \[net, tr\] = train(net, X_train, y_train); % 查看训练结果 plotperform(tr); % 进行预测 y_pred = net(X_test); % 计算误差 errors = y_pred - y_test; % 输出误差 for i = 1:length(y_test) fprintf('Test sample %d:\\n', i); fprintf('Predicted output: %.4f\\n', y_pred(i)); fprintf('Actual output: %.4f\\n', y_test(i)); fprintf('Error: %.4f\\n\\n', errors(i)); end % 计算均方误差(MSE) mse = mean(errors.\^2); fprintf('Mean Squared Error: %.4f\\n', mse);

相关推荐
胖哥真不错14 小时前
基于MATLAB的Lasso回归的数据回归预测方法应用
机器学习·matlab·项目实战·lasso回归
机器学习之心HML20 小时前
分类预测 | Matlab基于KPCA-ISSA-SVM和ISSA-SVM和SSA-SVM和SVM多模型分类预测对比
支持向量机·matlab·分类·kpca-issa-svm
2zcode1 天前
基于Matlab多特征融合的可视化指纹识别系统
人工智能·算法·matlab
蓝桉(努力版)2 天前
MATLAB可视化5:华夫图(饼图的平替可以表示种类的分布,附有完整代码详细讲解)(求个关注、点赞和收藏)(对配色不满意可以自己调节配色,附调色教程)
开发语言·数学建模·matlab·信息可视化·matlab可视化
freexyn2 天前
Matlab自学笔记六十二:求解三角函数方程的通解周期解
笔记·算法·matlab
DesolateGIS4 天前
数学建模:非线性规划:凸规划问题
数学建模·matlab
IT猿手5 天前
2025最新智能优化算法:沙狐优化(Rüppell‘s Fox Optimizer,RFO)算法求解23个经典函数测试集,完整MATLAB代码
android·算法·matlab·迁移学习·优化算法·动态多目标优化·动态多目标进化算法
rit84324995 天前
MATLAB基于voronoi生成三维圆柱形
开发语言·人工智能·matlab
微光-沫年5 天前
141-CEEMDAN-VMD-Transformer-BiLSTM-ABKDE多变量区间预测模型!
算法·matlab·回归
Akangya5 天前
Matlab-Simulink之步长
matlab