Fitrnet having assignment size errors
5 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
I am trying to create a neural network using fitrnet and a dataset that is 1000x24. I am trying to use cvpartition to split the dataset into 80% training and 20% test. However, when doing so, I regularly get an error in the "RegressionChainEnsemble.m" file on line 140 saying "Unable to perform assignment because the indices on the left side are not compatible with the size of the right side." This happens every time when using 80% on cvpartition but does not when I lower the percent down to around 50%. Does anyone know how to help with this?
Follow on question: when I have trained a model with fitrnet, how do I then pass in predictor variable values? For example, I would like to pass in a set of input data to get the 14 response variable values. Thanks!
0 Commenti
Risposta accettata
Gayathri
il 14 Mar 2025
I am not able to reproduce the issue at my end. But please refer to the sample code for creating a neural network using "fitrnet" function and with a dataset of size "1000x24". This code might help you resolve the issue faced.
% Generate a synthetic dataset
rng(0); % For reproducibility
numObservations = 1000;
numFeatures = 24;
% Create random data
X = rand(numObservations, numFeatures);
y = rand(numObservations, 1); % Random target variable
% Create a cvpartition object for an 80/20 split
cv = cvpartition(numObservations, 'HoldOut', 0.2);
% Get training and test indices
trainIdx = training(cv);
testIdx = test(cv);
% Split the data into training and test sets
XTrain = X(trainIdx, :);
yTrain = y(trainIdx);
XTest = X(testIdx, :);
yTest = y(testIdx);
% Set up and train a neural network regression model
try
% Define the neural network
model = fitrnet(XTrain, yTrain, 'LayerSizes', [10, 10], 'Activations', 'relu');
% Predict on the test set
yPred = predict(model, XTest);
% Calculate and display the RMSE
rmse = sqrt(mean((yTest - yPred).^2));
fprintf('RMSE: %.4f\n', rmse);
catch ME
% Display the error message if one occurs
fprintf('Error: %s\n', ME.message);
end
For more information on the "cvpartition" function, please refer to the below link.
If this does not solve your issue, please reply back with relevant files so that I can get to know the issue encountered in detail.
Thanks!
0 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Sequence and Numeric Feature Data Workflows in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!