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

相关推荐
gihigo19985 小时前
MATLAB使用遗传算法解决车间资源分配动态调度问题
算法·matlab
路长冬5 小时前
matlab与数字信号处理的不定期更新
开发语言·matlab·信号处理
机器学习之心1 天前
基于双向时序卷积网络与门控循环单元(BiTCN-GRU)混合模型的时间序列预测MATLAB代码
网络·matlab·gru·bitcn-gru
雨洛lhw2 天前
matlab设计滤波器详解
matlab·低通滤波器·滤波器设计流程
熊猫_豆豆2 天前
MATLAB水滴下落湖水面泛起涟漪仿真
开发语言·matlab·水滴仿真
MATLAB代码顾问2 天前
MATLAB实现模糊PID控制
开发语言·matlab
熊猫_豆豆3 天前
嫦娥号地月轨道、环月(一个月)MATLAB仿真
开发语言·matlab
fie88893 天前
基于MATLAB的LBFGS优化算法实现
算法·matlab
wuk9984 天前
基于有限差分法的二维平面热传导模型MATLAB实现
开发语言·matlab·平面
csdn_aspnet4 天前
分享MATLAB在数据分析与科学计算中的高效算法案例
算法·matlab·数据分析