how can I correct predict error in matlab

13 次查看(过去 30 天)
I coded a source-destination direct link and predicted the received data at the destination using Matlab.It gives an error as "Error using predict ,No valid system or dataset was specified"
1.I generated data set as below as you mentioned.
clear all;close all;clc;
bits = randi([0 1], 1000, 1); % generate random bits
bpsk = 2*bits - 1; % BPSK modulation
snr = 10; % signal-to-noise ratio in dB
noisy_bpsk = awgn(bpsk, snr); % add noise to the signal
newdata = [bpsk ,noisy_bpsk];
writematrix(newdata, 'tx_rx_data.csv'); %Writing data to .csv file
2.Training the model with the generated dataset. I used support vector machines.
%Prepare the dataset
tx_rx_data = readmatrix('tx_rx_data.csv');
%Assigning data to X and Y variables
X = tx_rx_data(:,1);
Y = tx_rx_data(:,2);
rand = randperm(10^2);%Generate random nums is equal to rows
%divide the data for traing and testing
Xtr = X(rand(1:length(rand)*0.8) ,:);% 80% for training
Ytr = Y(rand(1:length(rand)*0.8) ,:);% 80% for training
Xtest = X(rand(1:length(rand)*0.2) ,:);% 20% for testing
Ytest = Y(rand(1:length(rand)*0.2) ,:);% 20% for testing
model_tx_rx_data = fitcecoc(Xtr , Ytr); %used support vector machines
save model_tx_rx_data;%save the model
%Testing the model
result = predict(model_tx_rx_data , Xtest);
accuracy = (sum(result == Ytest)/length(Ytest))*100;
sp = sprintf("Test Accuracy = %0.2f" , accuracy);
disp(sp);
Test Accuracy = 0.00
3.Testing new data.
bits = randi([0 1], 1000, 1); % generate random bits
bpsk = 2*bits - 1; % BPSK modulation
snr = 10; % signal-to-noise ratio in dB
noisy_bpsk = awgn(bpsk, snr); % add noise to the signal
rx_symbols = noisy_bpsk;
decodedData = real(rx_symbols) ; %Decoder output
%Prepare the dataset for real data
TrainedmodelRx_data = readmatrix('tx_rx_data.csv');
%Assigning data to variable
TrainedmodelRx_data = Trainedmodel_data(:,2);
Unrecognized function or variable 'Trainedmodel_data'.
%use the trained model to predict the data at Rx
ML_predicted_receivedData = predict(TrainedmodelRx_data , decodedData);
%TrainedmodelRx_data - Output of the trained model
%decodedData - output from the decoder at Rx
When I run "Testing new data" file , there is an error "Error using predict, No valid system or dataset was specified. can you tell me the reason for it. Thank you
  4 个评论
Walter Roberson
Walter Roberson 2024-1-6
Earlier you had
model_tx_rx_data = fitcecoc(Xtr , Ytr); %used support vector machines
%...
result = predict(model_tx_rx_data , Xtest);
so predict() is being invoked on the result of fitcecoc.
Later you have
TrainedmodelRx_data = readmatrix('tx_rx_data.csv');
TrainedmodelRx_data = TrainedmodelRx_data(:,2);
ML_predicted_receivedData = predict(TrainedmodelRx_data , decodedData);
so predict() is being invoked on numeric data.
predict() is a generally a method of a class -- model_tx_rx_data is a particular class, and the predict() method of that class is being invoked.
When you try to predict() passing in numeric data, you get a completely different predict() that is useless to you.

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Classification Ensembles 的更多信息

产品


版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by