forecasting SVM code issue
古いコメントを表示
I found an error "Index in position 1 exceeds array bounds (must not exceed 142)" while using the below code:
Facing problem to find the attached figure
% clc;clear;close all;
% data = xlsread('all_data.xls');
% N = 142;
% data_in = data(13:N,[5 6 8]);
% data_out = data(13:N,4);
% mdl = fitrsvm(data_in,data_out,'Standardize','on','KernelFunction','rbf','KernelScale','auto');
% predY = predict(mdl,data_in);
% plot(data_out)
% hold on
% plot(predY,'r')
clc;clear;close all;
addpath(genpath([pwd,'\libsvm-3.20'])); %adding svm path
A = 142;
data = xlsread('all_data.xls');
data_in = data(13:A,[5 6 8]);
data_out = data(13:A,4);
%%
n = length(data_in);
sigma_in = std(data_in);
mu_in = mean(data_in);
data_in_norm = (data_in - repmat(mu_in,n,1))./repmat(sigma_in,n,1);
sigma_out = std(data_out);
mu_out= mean (data_out);
data_out_norm = (data_out - mu_out)./sigma_out;
%%
model = svmtrain(data_out_norm, data_in_norm, '-s 3 -g 2 -t 2 -d 1 -p 0.1 -c 1');
y_pred_norm = svmpredict(data_out_norm, data_in_norm, model);
y_pred = y_pred_norm*sigma_out+mu_out;
%%
for i = 143:154
x = [data(i,9) data(i,6) data(i-12,4)];
x_norm = (x - mu_in)./sigma_in;
y_pred_norm(i-12) = svmpredict(0, x_norm, model);
y_pred(i-12) = y_pred_norm(i-12)*sigma_out+mu_out;
end
[~,ix]= sort(y_pred(end-11:end));
y_pred(end-11:end)=y_pred(end-11:end).*(0.6+((ix-1)/11));
for i = 155:168
x = [data(i,9) data(i,6) y_pred(i-13)];
x_norm = (x - mu_in)./sigma_in;
y_pred_norm(i-12) = svmpredict(0, x_norm, model);
y_pred(i-12) = y_pred_norm(i-12)*sigma_out+mu_out;
end
plot(data_out)
hold on
plot(y_pred,'*-r')

5 件のコメント
Walter Roberson
2021 年 12 月 28 日
Which line is the problem occuring on? What are the size of all of the variables mentioned in the line, and the value of any index mentioned in the line?
Note: libsvm is third-party code; it is no longer common that people have it readily available.
suleman sarwar
2021 年 12 月 28 日
Walter Roberson
2021 年 12 月 28 日
You say the data length is 142, but your second for loop starts trying to access from data(i,9) where i is 155.
Just before the first of those loops, please put in
whos data y_pred_norm y_pred
and show us the result.
suleman sarwar
2021 年 12 月 28 日
Walter Roberson
2021 年 12 月 28 日
if data has 142 rows and your loop starts at 143 then data(i, 9) is out of range.
If you want to use the last 12 for forecasting then index data(i-12,:)
But you would have the same problem with the second loop.
回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Statistics and Machine Learning Toolbox についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
