给我一段matlab代码,可以基于神经网络实现变压器故障检测
时间: 2024-05-25 14:15:49 浏览: 117
以下是一个简单的基于神经网络实现变压器故障检测的MATLAB代码:
% 读取数据
load('transformer_data.mat');
x = data(:,1:9); % 输入特征
y = data(:,10); % 输出标签
% 分割数据集
[trainInd,valInd,testInd] = dividerand(size(x,1),0.6,0.2,0.2);
x_train = x(trainInd,:);
y_train = y(trainInd,:);
x_val = x(valInd,:);
y_val = y(valInd,:);
x_test = x(testInd,:);
y_test = y(testInd,:);
% 创建神经网络
net = feedforwardnet([10,5]);
net.trainFcn = 'trainscg';
net.layers{1}.transferFcn = 'logsig';
net.layers{2}.transferFcn = 'logsig';
net.layers{3}.transferFcn = 'logsig';
% 设置训练参数
net.trainParam.epochs = 500;
net.trainParam.lr = 0.01;
net.trainParam.goal = 0.001;
% 训练神经网络
[net,tr] = train(net,x_train',y_train');
% 评估神经网络性能
y_pred = round(net(x_test')');
accuracy = sum(y_pred == y_test) / length(y_test);
% 输出结果
fprintf('Accuracy: %.2f%%\n',accuracy*100);
阅读全文