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

3 views (last 30 days)
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.

Answers (2)

Faiz Gouri
Faiz Gouri on 1 Mar 2017
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 on 14 Jan 2018
Edited: Salma Hassan on 14 Jan 2018
imds=' D:\ ';
imds=imageDatastore(imds,'IncludeSubfolders',true,'FileExtensions','.png','LabelSource','foldernames'); [trainingimages,valDigitData]=splitEachLabel(imds,0.8,'randomize');
t=table(trainingimages.Files,trainingimages.Labels);

Categories

Find more on Sequence and Numeric Feature Data Workflows in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!