I am currently working on a classification problem and the code are shown bellow.I have the following errors when I run the codes
Invalid training data. X and Y must have the same number of observations.
clear;close all;clc;filename = "energydata.xls";data = readtable(filename,'TextType','string');head(data)%Remove the rows of the table with empty reports.
%idxEmpty = strlength(data.Appliances) == 0;
%data(idxEmpty,:) = [];
%The goal of this example is to classify events by the label in the event_type column. To divide the data into classes, convert these labels to categorical.
YTrain = categorical(data.lights);data = xlsread('energydata.xls');XTrain=data(1:19735,1:1);%input data set
%expectedOutput=data(1:19735,28); %target data set
rng('default');%XTrain =XTrain';
numObservations = numel(XTrain);for i=1:numObservations sequence = XTrain (i); sequenceLengths(i) = size(sequence,2);end%Sort the data by sequence length.
[sequenceLengths,idx] = sort(sequenceLengths);XTrain = XTrain(idx);YTrain = YTrain(idx);XTrain = con2seq(XTrain );%View the sorted sequence lengths in a bar chart.
figurebar(sequenceLengths)ylim([0 30])xlabel("Sequence")ylabel("Length")title("Sorted Data")inputSize = 19735;numHiddenUnits = 100;numClasses = 8;layers = [ ... sequenceInputLayer(inputSize) lstmLayer(numHiddenUnits,'OutputMode','last') fullyConnectedLayer(numClasses) softmaxLayer classificationLayer];maxEpochs = 100;miniBatchSize = 27;option = trainingOptions('sgdm','MaxEpochs',100); net = trainNetwork(XTrain,YTrain,layers,option);
Best Answer