I am getting an error on the last line saying Input and target has different samples, Any suggestions?

2 vues (au cours des 30 derniers jours)
load pumpFeatures.mat
t = table2array(T(:,1:84));
Y = table2array(T(:,85));
% features (X) are stored in the first 84 columns and labels (Y) in the last column of the dataset 'data'
% Split features (X) and labels (Y)
X = table2array(T(:, 1:84));
%Y = table2array(T(:, 85));
% Define the size of the training set (e.g., 70%)
training_ratio = 0.7;
% Generate indices for the training and test sets
cv = cvpartition(size(T, 1), 'HoldOut', 1 - training_ratio);
% Split the features and labels into training and test sets
X_train = X(cv.training,:);
Y_train = Y(cv.training,:);
X_test = X(cv.test,:);
Y_test = Y(cv.test,:);
hiddenLayerSizes = [10];
net = feedforwardnet(hiddenLayerSizes);
net = configure(net, X_train, Y_train);
net.layers{end}.transferFcn = 'softmax'; % Softmax for multi-class classification
% Train the network
net = train(net,X_train,Y_train); --- Error Line Input and Target has different numbetr of samples

Réponse acceptée

Manikanta Aditya
Manikanta Aditya le 5 Mar 2024
Hey Joseph,
The error message you’re seeing typically occurs when the dimensions of the input data and target data do not match. In your case, it seems like the dimensions of 'X_train' and 'Y_train' might not be aligned.
The train function in MATLAB expects the input and target data to have the same number of columns, where each column represents a single sample. However, in your code, 'X_train' is a matrix where each row represents a sample, and 'Y_train' is a vector.
To resolve this issue, you can transpose 'X_train' and 'Y_train' before passing them to the train function. Here’s how you can do it:
% Train the network
net = train(net, X_train.', Y_train.');
This will ensure that both 'X_train' and 'Y_train' have the same number of columns, each representing a single sample. Please give this a try.
Check the following MATLAB Answers which talk about the same error:
Thanks!

Plus de réponses (0)

Catégories

En savoir plus sur Deep Learning Toolbox dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by