Why does the error at the bottom show up even though the correct dataset seems to be selected?
2 次查看(过去 30 天)
显示 更早的评论
It says "Unable to find suitable response variable ~"
Here is the code:
img = imread("C:\Users\xxoox\OneDrive\デスクトップ\MATLAB works\Data\MathWorks Images\ocean.jpg"); % Load the unlabeled image
load ("C:\Users\xxoox\OneDrive\デスクトップ\MATLAB works\Computer Vision for Engineering and Science\C2-MachineLearningForComputerVision\Module 2\gcClassifierSaturation.mat","gcClassifierSaturation") % Load the model trained using hand-selected features
load ("C:\Users\xxoox\OneDrive\デスクトップ\MATLAB works\Computer Vision for Engineering and Science\C2-MachineLearningForComputerVision\Module 2\gcClassifierBag.mat","gcClassifierBag") % Load the model trained using automatically generated features
load ("C:\Users\xxoox\OneDrive\デスクトップ\MATLAB works\Computer Vision for Engineering and Science\C2-MachineLearningForComputerVision\Module 2\bag.mat","bag") % Load bag of visual words object created by bagOfFeatures
% Step 1: Create a table of saturation-based predictor features
% Convert the image to HSV color space
hsvImg = rgb2hsv(img);
% Extract the saturation channel
saturation = hsvImg(:,:,2);
% Calculate the mean and standard deviation of the saturation
avgSat = mean(saturation(:));
stdSat = std(saturation(:));
% Create a table of saturation-based predictor features
gcTableSaturation = table(avgSat, stdSat);
% Step 2: Use gcClassifierSaturation.predictFcn to classify the unlabeled image
% Use the classifier to predict the label
prediction = gcClassifierSaturation.predictFcn(gcTableSaturation);
% Attach the prediction to the table
gcTableSaturation.prediction = prediction;
% Step 3: Create a table of bagOfFeatures-based predictor features
% Encode the image using the bag of features
featureVector = encode(bag, img);
% Create a table of predictor features for the unlabeled image
gcTableBag = array2table(featureVector);
gcTableBag.Properties.VariableNames = arrayfun(@(x) ['f' num2str(x)], 1:500, 'UniformOutput', false);
% Step 4: Use gcClassifierBag.predictFcn to classify the unlabeled image
% Use the classifier to predict the label
predictionBag = gcClassifierBag.predictFcn(gcTableBag);
% Attach the prediction to the table
gcTableBag.prediction = predictionBag;
0 个评论
回答(1 个)
Walter Roberson
2024-7-12
Your values in the table are scalars. You cannot create response variables from scalars.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Feature Detection and Extraction 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!