Confusionmatrix for linear regression

조회 수: 3 (최근 30일)
Gorkem Akgul
Gorkem Akgul 2021년 4월 22일
댓글: Gorkem Akgul 2021년 4월 23일
Hi,
I'm using the code below to train a logistic regression classifier. I'd like to plot a confusion matrix but even though i waited 30 minutes, it doesn't show the matrix. I just run the code and it goes on debugging but never shows the result. The predicted and response matrix consits of 5000x1 matrix that has either 0 or 1. I don't think plotting a confusion matrix for this data would take that long. Can anybody help me about the problem ?
strokedata=importstroke("healthcare-dataset-stroke-data")
inputTable=strokedata;
predictorNames={'gender','age','hypertension','heart_disease','work_type','Residence_type','avg_glucose_level','bmi','smoking_status'}
predictors = inputTable(:, predictorNames)
response=inputTable.stroke
isCategoricalPredictor=[true,false,false,false,true,true,true,false,false,true]
successClass = double(1);
failureClass = double(0);
numSuccess = sum(response == successClass);
numFailure = sum(response == failureClass);
if numSuccess > numFailure
missingClass = successClass
else
missingClass = failureClass
end
successFailureAndMissingClasses = [successClass; failureClass; missingClass];
isMissing = isnan(response)
zeroOneResponse = double(ismember(response, successClass))
zeroOneResponse(isMissing) = NaN
% Prepare input arguments to fitglm.
concatenatedPredictorsAndResponse = [predictors, table(zeroOneResponse)]
GeneralizedLinearModel = fitglm(...
concatenatedPredictorsAndResponse, ...
'Distribution', 'binomial','link','logit')
yPredicted=predict(GeneralizedLinearModel,inputTable) > 0.47
plotconfusion(response,yPredicted)
  댓글 수: 6
the cyclist
the cyclist 2021년 4월 22일
I don't have the Deep Learning Toolbox. But
confusionchart(logical(response),yPredicted) % requires Stats & Machine Learning Toolbox
returned the chart in under a second. So, I think your instinct is correct. I'm not sure what's going on in your code.
Gorkem Akgul
Gorkem Akgul 2021년 4월 23일
Thank you I solved the problem with the function you say. I think there's a problem with the plotconfusion() matrix. I asked one of my friends to try it and he said he had the same problem as well. Or perhaps, it is only suitable for deep learning models.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Get Started with Statistics and Machine Learning Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by