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

相关推荐

  1. 神经网络】深度神经网络

    2024-06-08 15:04:05       31 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-06-08 15:04:05       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-06-08 15:04:05       100 阅读
  3. 在Django里面运行非项目文件

    2024-06-08 15:04:05       82 阅读
  4. Python语言-面向对象

    2024-06-08 15:04:05       91 阅读

热门阅读

  1. python --监听鼠标事件

    2024-06-08 15:04:05       29 阅读
  2. Vue Web前端:深入探索与实战应用

    2024-06-08 15:04:05       37 阅读
  3. 自然语言处理(NLP)技术。

    2024-06-08 15:04:05       36 阅读
  4. MacOS - Mac 电脑启动台找不到 VSCode 解决方案

    2024-06-08 15:04:05       30 阅读
  5. php设计模式之单例模式详解

    2024-06-08 15:04:05       21 阅读
  6. Tomcat 启动闪退问题解决方法

    2024-06-08 15:04:05       27 阅读
  7. python创建项目时关于new conda environment的解释

    2024-06-08 15:04:05       27 阅读
  8. 汽车线束搭铁与接地

    2024-06-08 15:04:05       27 阅读