MATLAB Answers

please help me modify my code so that i can fixt the below mentioned errors

1 view (last 30 days)
janardhana mangala
janardhana mangala on 10 Mar 2021
Answered: Aditya Patil on 29 Mar 2021
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,...

Answers (1)

Aditya Patil
Aditya Patil on 29 Mar 2021
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.

Products


Release

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by