Confusionmatrix for linear regression

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일
Can you upload the data, so that we can run your code?
Gorkem Akgul
Gorkem Akgul 2021년 4월 22일
Of course.
You can download the dataset from the following link.
the cyclist
the cyclist 2021년 4월 22일
Is importstroke() a function you wrote? I don't see it on Kaggle.
@the cyclist Yes, i just used the import data option and save it as importstroke()
function healthcaredatasetstrokedata = importfile(filename, dataLines)
%IMPORTFILE Import data from a text file
% HEALTHCAREDATASETSTROKEDATA = IMPORTFILE(FILENAME) reads data from
% text file FILENAME for the default selection. Returns the data as a
% table.
%
% HEALTHCAREDATASETSTROKEDATA = IMPORTFILE(FILE, DATALINES) reads data
% for the specified row interval(s) of text file FILENAME. Specify
% DATALINES as a positive scalar integer or a N-by-2 array of positive
% scalar integers for dis-contiguous row intervals.
%
% Example:
% healthcaredatasetstrokedata = importfile("F:\Documents\Neural Networks Matlab\Course 1\COVID-19-master\healthcare-dataset-stroke-data.csv", [2, Inf]);
%
% See also READTABLE.
%
% Auto-generated by MATLAB on 17-Apr-2021 22:47:18
%% Input handling
% If dataLines is not specified, define defaults
if nargin < 2
dataLines = [2, Inf];
end
%% Setup the Import Options and import the data
opts = delimitedTextImportOptions("NumVariables", 12);
% Specify range and delimiter
opts.DataLines = dataLines;
opts.Delimiter = ",";
% Specify column names and types
opts.VariableNames = ["id", "gender", "age", "hypertension", "heart_disease", "ever_married", "work_type", "Residence_type", "avg_glucose_level", "bmi", "smoking_status", "stroke"];
opts.VariableTypes = ["double", "categorical", "double", "double", "double", "categorical", "categorical", "categorical", "double", "double", "categorical", "double"];
% Specify file level properties
opts.ExtraColumnsRule = "ignore";
opts.EmptyLineRule = "read";
% Specify variable properties
opts = setvaropts(opts, ["gender", "ever_married", "work_type", "Residence_type", "smoking_status"], "EmptyFieldRule", "auto");
% Import the data
healthcaredatasetstrokedata = readtable(filename, opts);
end
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개)

질문:

2021년 4월 22일

댓글:

2021년 4월 23일

Community Treasure Hunt

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

Start Hunting!

Translated by