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

相关推荐
Python大数据分析@1 天前
Origin、MATLAB、Python 用于科研作图,哪个最好?
开发语言·python·matlab
牛马baby1 天前
MATLAB下载安装教程(附安装包)2025最新版(MATLAB R2024b)
开发语言·matlab
Evand J1 天前
【MATLAB例程】AOA与TDOA混合定位例程,适用于三维环境、4个锚点的情况,附下载链接
开发语言·matlab
m0_555762902 天前
Matlab 频谱分析 (Spectral Analysis)
开发语言·matlab
guygg882 天前
基于matlab的FIR滤波器
开发语言·算法·matlab
我爱C编程2 天前
基于拓扑结构检测的LDPC稀疏校验矩阵高阶环检测算法matlab仿真
算法·matlab·矩阵·ldpc·环检测
hie988943 天前
MATLAB锂离子电池伪二维(P2D)模型实现
人工智能·算法·matlab
88号技师3 天前
2025年6月一区-田忌赛马优化算法Tianji’s horse racing optimization-附Matlab免费代码
开发语言·算法·matlab·优化算法
m0_555762904 天前
matlab 教程
matlab
松果集4 天前
MATLAB基础知识【8】绘图,peaks,sphere,积分
matlab