Помощь в разрешении этого сообщения в Matlab (нейронная простая сеть) - PullRequest
0 голосов
/ 18 марта 2020

Приведенный ниже код приводит к следующей ошибке:

"Неверные данные проверки. Предикторами должен быть массив последовательностей ячеек N-1, где N - число последовательностей. Все последовательности должны иметь то же измерение элемента и хотя бы один временной шаг. "

Моя проверка следующая: {{24381 × 1 ячейка} [24381 × 1 категориальная]} мои данные об обучении следующие: {{12000 × 1 ячейка } [12000 × 1 категорический]}

TestDataTrainx является двойным 21x72.

Я не вижу, чем мой пример отличается от примера Matlab здесь

<div class="CodeBlock contiguous"><div class="lineNode mwRichTextComponentLine plainTextFixedSize"><span class="textBox"><span class="textWrapper">T = readtable(</span><span class="textWrapper String">'TestFile.txt'</span><span class="textWrapper">);</span></span></div><div class="lineNode mwRichTextComponentLine plainTextFixedSize"><span class="textBox"><span class="textWrapper">X = T{:,:};</span></span></div><div class="lineNode mwRichTextComponentLine plainTextFixedSize"><span class="textBox"><span class="textWrapper">DataWindow=20;</span></span></div><div class="lineNode mwRichTextComponentLine plainTextFixedSize"><span class="textBox"><span class="textWrapper">test=0;</span></span></div><div class="lineNode mwRichTextComponentLine plainTextFixedSize"><span class="textBox"><span class="textWrapper Comment">%generate training and validation data</span></span></div><div class="lineNode mwRichTextComponentLine plainTextFixedSize"><span class="textBox"><span class="textWrapper Keyword">for </span><span class="textWrapper">i = 1:(length(X(:,1))-DataWindow)</span></span></div><div class="lineNode mwRichTextComponentLine plainTextFixedSize"><span class="textBox"><span class="textWrapper">    </span></span></div><div class="lineNode mwRichTextComponentLine plainTextFixedSize"><span class="textBox"><span class="textWrapper">    </span><span class="textWrapper Keyword">for </span><span class="textWrapper">j=(i+DataWindow+1):(length(X(:,1))-DataWindow)</span></span></div><div class="lineNode mwRichTextComponentLine plainTextFixedSize"><span class="textBox"><span class="textWrapper">        </span></span></div><div class="lineNode mwRichTextComponentLine plainTextFixedSize"><span class="textBox"><span class="textWrapper">        </span><span class="textWrapper Keyword">if </span><span class="textWrapper">X(j,2) - X(i+DataWindow,4) &gt; 250 &amp;&amp; X(i+DataWindow,4) - X(j,3) &lt; 250</span></span></div><div class="lineNode mwRichTextComponentLine plainTextFixedSize"><span class="textBox"><span class="textWrapper">            </span></span></div><div class="lineNode mwRichTextComponentLine plainTextFixedSize"><span class="textBox"><span class="textWrapper">            TestData{i,1}=X(i:i+DataWindow,:)./10000;</span></span></div><div class="lineNode mwRichTextComponentLine plainTextFixedSize"><span class="textBox"><span class="textWrapper">            Cat(i)=0;</span></span></div><div class="lineNode mwRichTextComponentLine plainTextFixedSize"><span class="textBox"><span class="textWrapper">            </span><span class="textWrapper Keyword">break</span></span></div><div class="lineNode mwRichTextComponentLine plainTextFixedSize"><span class="textBox"><span class="textWrapper">        </span><span class="textWrapper Keyword">end</span></span></div><div class="lineNode mwRichTextComponentLine plainTextFixedSize"><span class="textBox"><span class="textWrapper">        </span><span class="textWrapper Keyword">if </span><span class="textWrapper">X(i+DataWindow,4) - X(j,3) &gt;= 250</span></span></div><div class="lineNode mwRichTextComponentLine plainTextFixedSize"><span class="textBox"><span class="textWrapper">            TestData{i,1}=X(i:i+DataWindow,:)./10000;</span></span></div><div class="lineNode mwRichTextComponentLine plainTextFixedSize"><span class="textBox"><span class="textWrapper">            Cat(i)=1;</span></span></div><div class="lineNode mwRichTextComponentLine plainTextFixedSize"><span class="textBox"><span class="textWrapper">            </span><span class="textWrapper Keyword">break</span></span></div><div class="lineNode mwRichTextComponentLine plainTextFixedSize"><span class="textBox"><span class="textWrapper">        </span><span class="textWrapper Keyword">end</span></span></div><div class="lineNode mwRichTextComponentLine plainTextFixedSize"><span class="textBox"><span class="textWrapper">    </span><span class="textWrapper Keyword">end</span></span></div><div class="lineNode mwRichTextComponentLine plainTextFixedSize"><span class="textBox"><span class="textWrapper Keyword">end</span></span></div><div class="lineNode mwRichTextComponentLine plainTextFixedSize"><span class="textBox"><span class="textWrapper"></span></span></div><div class="lineNode mwRichTextComponentLine plainTextFixedSize"><span class="textBox"><span class="textWrapper Comment">%writematrix(X,'TestFile.txt');</span></span></div><div class="lineNode mwRichTextComponentLine plainTextFixedSize"><span class="textBox"><span class="textWrapper"></span></span></div><div class="lineNode mwRichTextComponentLine plainTextFixedSize"><span class="textBox"><span class="textWrapper">TestDataCat = categorical(Cat).';</span></span></div><div class="lineNode mwRichTextComponentLine plainTextFixedSize"><span class="textBox"><span class="textWrapper">TestDataTrainx = TestData(1:12000,1);</span></span></div><div class="lineNode mwRichTextComponentLine plainTextFixedSize"><span class="textBox"><span class="textWrapper">TestDataTrainy = TestDataCat(1:12000,1);</span></span></div><div class="lineNode mwRichTextComponentLine plainTextFixedSize"><span class="textBox"><span class="textWrapper">TestDataTestx = TestData(12001:end,1);</span></span></div><div class="lineNode mwRichTextComponentLine plainTextFixedSize"><span class="textBox"><span class="textWrapper">TestDataTesty = TestDataCat(12001:end,1);</span></span></div><div class="lineNode mwRichTextComponentLine plainTextFixedSize"><span class="textBox"><span class="textWrapper"></span></span></div><div class="lineNode mwRichTextComponentLine plainTextFixedSize"><span class="textBox"><span class="textWrapper">numFeatures = 21;</span></span></div><div class="lineNode mwRichTextComponentLine plainTextFixedSize"><span class="textBox"><span class="textWrapper">numHiddenUnits = 100;</span></span></div><div class="lineNode mwRichTextComponentLine plainTextFixedSize"><span class="textBox"><span class="textWrapper">numClasses = 2;</span></span></div><div class="lineNode mwRichTextComponentLine plainTextFixedSize"><span class="textBox"><span class="textWrapper"></span></span></div><div class="lineNode mwRichTextComponentLine plainTextFixedSize"><span class="textBox"><span class="textWrapper">layers = [ </span><span class="textWrapper Keyword">...</span></span></div><div class="lineNode mwRichTextComponentLine plainTextFixedSize"><span class="textBox"><span class="textWrapper">    sequenceInputLayer(numFeatures)</span></span></div><div class="lineNode mwRichTextComponentLine plainTextFixedSize"><span class="textBox"><span class="textWrapper">    lstmLayer(numHiddenUnits,</span><span class="textWrapper String">'OutputMode'</span><span class="textWrapper">,</span><span class="textWrapper String">'last'</span><span class="textWrapper">)</span></span></div><div class="lineNode mwRichTextComponentLine plainTextFixedSize"><span class="textBox"><span class="textWrapper">    fullyConnectedLayer(numClasses)</span></span></div><div class="lineNode mwRichTextComponentLine plainTextFixedSize"><span class="textBox"><span class="textWrapper">    softmaxLayer</span></span></div><div class="lineNode mwRichTextComponentLine plainTextFixedSize"><span class="textBox"><span class="textWrapper">    classificationLayer];</span></span></div><div class="lineNode mwRichTextComponentLine plainTextFixedSize"><span class="textBox"><span class="textWrapper"></span></span></div><div class="lineNode mwRichTextComponentLine plainTextFixedSize"><span class="textBox"><span class="textWrapper">miniBatchSize = 27;</span></span></div><div class="lineNode mwRichTextComponentLine plainTextFixedSize"><span class="textBox"><span class="textWrapper"></span></span></div><div class="lineNode mwRichTextComponentLine plainTextFixedSize"><span class="textBox"><span class="textWrapper">options = trainingOptions(</span><span class="textWrapper String">'adam'</span><span class="textWrapper">, </span><span class="textWrapper Keyword">...</span></span></div><div class="lineNode mwRichTextComponentLine plainTextFixedSize"><span class="textBox"><span class="textWrapper">    </span><span class="textWrapper String">'ExecutionEnvironment'</span><span class="textWrapper">,</span><span class="textWrapper String">'cpu'</span><span class="textWrapper">, </span><span class="textWrapper Keyword">...</span></span></div><div class="lineNode mwRichTextComponentLine plainTextFixedSize"><span class="textBox"><span class="textWrapper">    </span><span class="textWrapper String">'MaxEpochs'</span><span class="textWrapper">,100, </span><span class="textWrapper Keyword">...</span></span></div><div class="lineNode mwRichTextComponentLine plainTextFixedSize"><span class="textBox"><span class="textWrapper">    </span><span class="textWrapper String">'MiniBatchSize'</span><span class="textWrapper">,miniBatchSize, </span><span class="textWrapper Keyword">...</span></span></div><div class="lineNode mwRichTextComponentLine plainTextFixedSize"><span class="textBox"><span class="textWrapper">    </span><span class="textWrapper String">'ValidationData'</span><span class="textWrapper">,{TestDataTestx,TestDataTesty}, </span><span class="textWrapper Keyword">...</span></span></div><div class="lineNode mwRichTextComponentLine plainTextFixedSize"><span class="textBox"><span class="textWrapper">    </span><span class="textWrapper String">'GradientThreshold'</span><span class="textWrapper">,2, </span><span class="textWrapper Keyword">...</span></span></div><div class="lineNode mwRichTextComponentLine plainTextFixedSize"><span class="textBox"><span class="textWrapper">    </span><span class="textWrapper String">'Shuffle'</span><span class="textWrapper">,</span><span class="textWrapper String">'every-epoch'</span><span class="textWrapper">, </span><span class="textWrapper Keyword">...</span></span></div><div class="lineNode mwRichTextComponentLine plainTextFixedSize"><span class="textBox"><span class="textWrapper">    </span><span class="textWrapper String">'Verbose'</span><span class="textWrapper">,false, </span><span class="textWrapper Keyword">...</span></span></div><div class="lineNode mwRichTextComponentLine plainTextFixedSize"><span class="textBox"><span class="textWrapper">    </span><span class="textWrapper String">'Plots'</span><span class="textWrapper">,</span><span class="textWrapper String">'training-progress'</span><span class="textWrapper">);</span></span></div><div class="lineNode mwRichTextComponentLine plainTextFixedSize"><span class="textBox"><span class="textWrapper"></span></span></div><div class="lineNode mwRichTextComponentLine plainTextFixedSize"><span class="textBox"><span class="textWrapper">net = trainNetwork(TestDataTrainx,TestDataTrainy,layers,options);</span></span></div><div class="lineNode mwRichTextComponentLine plainTextFixedSize"><span class="textBox"><span class="textWrapper"></span></span></div></div>
...