% 加载数据集(假设数据集已经准备好)
load(‘hydro_power_dataset.mat’); % 假设数据集保存在 hydro_power_dataset.mat 文件中
% 划分训练集和测试集
trainRatio = 0.8; % 训练集所占比例
trainSamples = round(trainRatio * size(features, 1));
trainFeatures = features(1:trainSamples, 😃;
trainLabels = labels(1:trainSamples, 😃;
testFeatures = features(trainSamples+1:end, 😃;
testLabels = labels(trainSamples+1:end, 😃;
% 设置 GPR 参数
kernelType = ‘squared_exponential’; % 核函数类型
lengthScale = 1; % 核函数长度尺度
% 设置灰狼算法参数
maxIterations = 100; % 最大迭代次数
populationSize = 50; % 种群大小
% 运行灰狼算法优化
[optimalParams, ~] = GWO_GPR(trainFeatures, trainLabels, kernelType, lengthScale, maxIterations, populationSize);
% 使用最优参数构建 GPR 模型
model = GPR(trainFeatures, trainLabels, kernelType, lengthScale, optimalParams);
% 在测试集上进行预测
predictedLabels = GPR_predict(testFeatures, model);
% 评估预测性能
mse = mean((predictedLabels - testLabels).^2);
rmse = sqrt(mse);
% 显示结果
disp(['Root Mean Squared Error (RMSE): ', num2str(rmse)]);