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

5 ビュー (過去 30 日間)
Richard Palmer
Richard Palmer 2017 年 2 月 23 日
編集済み: Salma Hassan 2018 年 1 月 14 日
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 Center および File ExchangeSequence 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