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);

相关推荐
CappuccinoRose1 天前
MATLAB学习文档(二十四)
学习·数学建模·matlab·数据可视化
茜茜西西CeCe1 天前
数字图像处理-图像增强(2)
人工智能·算法·计算机视觉·matlab·数字图像处理·图像增强·陷波滤波器
Evand J2 天前
【MATLAB例程】基于USBL和DVL的线性回归误差补偿,对USBL和DVL导航数据进行相互补偿,提高定位精度,附代码下载链接
开发语言·matlab·线性回归·水下定位·usbl·dvl
mjhcsp2 天前
MATLAB 疑难问题诊疗:从常见报错到深度优化的全流程指南
开发语言·matlab
Dave.B2 天前
MatGeom——一个基于 MATLAB 的几何处理库
matlab
88号技师2 天前
2025年8月SCI-汉尼拔·巴卡优化算法Hannibal Barca optimizer-附Matlab免费代码
开发语言·人工智能·算法·数学建模·matlab·优化算法
机器学习之心HML3 天前
MATLAB基于GWO-BP神经网络对某拨叉件锻造金属流动性的参数分析
开发语言·神经网络·matlab
珞瑜·3 天前
MATLAB2025B版本新特点
matlab
信息快讯4 天前
“COMSOL+MATLAB光子学仿真:从入门到精通,掌握多物理场建模
开发语言·matlab·comsol·光学工程
北山太湖4 天前
Matlab安装硬件支持包
开发语言·matlab