please help me modify my code so that i can fixt the below mentioned errors
1 次查看(过去 30 天)
显示 更早的评论
clear; clc; close all;
%% prepare dataset
filename = 'P1';
Spi = xlsread(filename,'B4:B769');
%% Normalization of data
N = size(Spi)
for i = 1 : size(Spi,1)
Spi_N(i) = ((Spi(i) - min(Spi))/(max(Spi) - min(Spi)));
end
X = [Spi_N']
%% 70:30 training and testing
rng default
rand_num = randperm(766);
x_train = X(rand_num(1:536),:);
x_test = X(rand_num(536:end),:);
%% best hyperparameters
rng default
Mdl = fitrsvm(x_train, 'KernelFunction', 'rbf', 'KernelScale','auto','Standardize',true,...
'OptimizeHyperparameters', 'auto', 'HyperparameterOptimizationOptions',struct('AcquisitionFunctionName',...
'expected-improvement-plus','ShowPlots',true));
%% Testing
x_predicted_test = predict(Mdl, x_test);
error_test = (x_test - x_predicted_test);
mean_absolute_error_test = mae(error_test)
root_mean_square_error_test = rms(error_test)
r_test = corrcoef(x_test,x_predicted_test)
%% Training
x_predicted_train = predict(Mdl, x_train);
error_train = (x_train - x_predicted_train);
mean_absolute_error_train = mae(error_train)
root_mean_square_error_train = rms(error_train)
r_train = corrcoef(x_train,x_predicted_train)
%% ALL data testing
x_predicted_all = predict(Mdl, X);
error_all = (X - x_predicted_all);
mean_absolute_error_all = mae(error_all)
root_mean_square_error_all = rms(error_all)
r_all = corrcoef(X ,x_predicted_all)
%%
save svm8.mat;
----------------------------------------------------------------------------- end of code -------------------------
errors:
Error using internal.stats.parseArgs (line 42)
Wrong number of arguments.
Error in classreg.learning.paramoptim.parseOptimizationArgs (line 10)
[OptimizeHyperparameters,HyperparameterOptimizationOptions,~,RemainingArgs] = internal.stats.parseArgs(...
Error in fitrsvm (line 277)
[IsOptimizing, RemainingArgs] = classreg.learning.paramoptim.parseOptimizationArgs(varargin);
Error in svm8original (line 20)
Mdl = fitrsvm(x_train, 'KernelFunction', 'rbf', 'KernelScale','auto','Standardize',true,...
0 个评论
回答(1 个)
Aditya Patil
2021-3-29
There are two issues in the code.
First, your normalization code creates a one column vector. You can replace the normalization code with,
X = normalize(Spi);
Second, you also need to pass the Y variable to the fitrsvm function. Y should have one columns, and same number of rows as X.
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!