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

相关推荐
guygg885 小时前
一级倒立摆MATLAB仿真程序
开发语言·matlab
ghie909016 小时前
基于MATLAB的演化博弈仿真实现
开发语言·matlab
listhi52016 小时前
IMM雷达多目标跟踪MATLAB实现方案
人工智能·matlab·目标跟踪
Gofarlic_OMS17 小时前
如何将MATLAB网络并发许可证闲置率降至10%以下
大数据·运维·服务器·开发语言·人工智能·matlab·制造
s090713620 小时前
【MATLAB】多子阵合成孔径声纳(SAS)成像仿真——基于时域反向投影(BP)算法
算法·matlab·bp算法·合成孔径
pythonpapaxia1 天前
基于Matlab的车牌识别完整教程:从图像预处理到字符识别实战解析
图像处理·其他·计算机视觉·matlab
kaikaile19951 天前
A星算法避开障碍物寻找最优路径(MATLAB实现)
数据结构·算法·matlab
民乐团扒谱机1 天前
【微实验】数模美赛备赛:多目标优化求解实战(MATLAB实现,以流水车间调度为例)
开发语言·数学建模·matlab·甘特图·遗传算法·多目标优化·优化模型
fie88891 天前
MATLAB有限元框架程序
python·算法·matlab
wearegogog1231 天前
基于MATLAB的IEEE 9节点系统潮流计算
开发语言·matlab