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

相关推荐
我爱C编程15 分钟前
基于遗传优化和GDOP评价的5G微基站部署策略matlab仿真
5g·matlab·遗传优化·gdop·5g微基站部署
m0_5474866619 小时前
《数字图像处理:使用MATLAB分析与实现》全套课件PPT
开发语言·matlab·powerpoint
hoiii1871 天前
17自由度铁道车辆横向动力学MATLAB程序
开发语言·matlab
LabVIEW开发1 天前
LabVIEW + MATLAB 混合编程:爆炸场测试数据精准采集方案
开发语言·matlab·labview
青山如墨雨如画2 天前
【北邮-无线通信中的人工智能】物理层技术中AI的应用实践:基于KNN的调制识别(1)理论基础
人工智能·python·机器学习·matlab·jupyter
机器学习之心2 天前
基于ELM-Adaboost的时间序列预测模型:MATLAB实现与应用
matlab
gihigo19982 天前
基于蒙特卡洛的异常值剔除(RANSAC + MC置信区间)—MATLAB实现
开发语言·算法·matlab
我爱C编程2 天前
基于BellHop模型的海底网络节点部署matlab模拟与仿真
matlab·bellhop·bellhop模型·海底网络节点部署
小白小宋2 天前
【PUSCH番外篇】5G NR 相位补偿与频移校正:原理、流程与工程实现
算法·5g·matlab·信息与通信·信号处理
2zcode2 天前
基于MATLAB语音信号变声算法设计与实现
算法·matlab·语音识别·变声算法