how to turn matlab table into appropriate input for neural net package

5 次查看(过去 30 天)
I have a matlab table (T) with numeric and nominal variables. Other matlab documentation shows a "dummytable" function that turns the nominal variables in T into a table with nominal variables changed to dummy variables and leaves the numeric variables "as is". However, I cannot figure how to get this table into a form that can be accessed and read by the neural network input functions. Surely, there must be a straightforward way to do this. I just do not see it.

回答(2 个)

Faiz Gouri
Faiz Gouri 2017-3-1
You can refer the code below in order to convert table into Neural Network function input-
load('carsmall')
cars = table(MPG,Weight,Model_Year);
cars.Model_Year = categorical(cars.Model_Year);
categories(cars.Model_Year)
% now cars has Model_Year categorical(nominal) variable
% encode categorical variable
D = dummyvar(cars.Model_Year);
D = array2table(D);
D.Properties
% add new variable to cars
cars = [cars ,D];
cars.Model_Year =[];
% convert table to matrix as input to train function is R-by-Q matrix and
% U-by-Q matrix
inputs = table2array(cars(:,2:5))'; % R-by-Q
targets = cars.MPG'; % U-by-Q matrix
hiddenLayerSize = 10;
net = fitnet(hiddenLayerSize);
net.divideParam.trainRatio = 70/100;
net.divideParam.valRatio = 15/100;
net.divideParam.testRatio = 15/100;
[net,tr] = train(net,inputs,targets);

Salma Hassan
Salma Hassan 2018-1-14
编辑:Salma Hassan 2018-1-14
imds=' D:\ ';
imds=imageDatastore(imds,'IncludeSubfolders',true,'FileExtensions','.png','LabelSource','foldernames'); [trainingimages,valDigitData]=splitEachLabel(imds,0.8,'randomize');
t=table(trainingimages.Files,trainingimages.Labels);

类别

Help CenterFile Exchange 中查找有关 Sequence and Numeric Feature Data Workflows 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by