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

相关推荐
吃好睡好便好16 小时前
MATLAB中图像的读取、写入和显示
开发语言·图像处理·学习·计算机视觉·matlab
2zcode19 小时前
项目文档:基于MATLAB最小二乘支持向量机的睡眠分期智能监测系统设计与实现
开发语言·支持向量机·matlab
2zcode2 天前
基于MATLAB车辆拥堵密度依赖的自适应交通信号控制系统
人工智能·计算机视觉·matlab
Jason_gao9992 天前
【无标题】
matlab·信息与通信
2zcode2 天前
基于MATLAB神经网络的心力衰竭预测与临床辅助决策系统研究
人工智能·神经网络·matlab
slandarer3 天前
MATLAB | 泰勒图绘制,支持各种角度范围
开发语言·数学建模·matlab·nature·顶刊·泰勒图
2zcode5 天前
项目文档:基于MATLAB的肺结节自动分割与评估系统的设计与实现
人工智能·计算机视觉·matlab
2zcode5 天前
基于MATLAB深度学习的乳腺钼靶影像乳腺癌智能诊断系统设计与实现
开发语言·深度学习·matlab·乳腺癌
通信仿真爱好者5 天前
第【81】期-- 基于反向散射的通信感知一体化(ISAC)的波束成形设计:检测与估计性能分析 --MATLAB完整代码
matlab·通信感知一体化·isac
2zcode6 天前
项目文档:基于MATLAB深度卷积神经网络的肺癌CT影像智能检测系统设计与实现
深度学习·matlab·cnn