looping through rows one at a time putting each row through a set of if statements to create a table of outcomes

1 Ansicht (letzte 30 Tage)
Hey Guys. I am looking help with some code I wish to write. I have used code to write a decision tree from weka and take data from an Excel file manually by typing in each variable when prompted.
I have done this code fine but I want to make this efficient and instead take the data from the Excel file, then row by row put it through my set of if and elseif statements of the tree. The aim is to determine the outcome of the patient based on numerous variables.
column 1 is age
column 2 is gender
column 3...etc for 13 columns
There are 90 patients so 90 rows.
Here is the start
file = uigetfile ('.csv');
table = readtable(file);
t = cell2mat(table2cell(table));
Then I assume I create variables from that matrix :
age = t(:,1);
gender = t(:,2);
chest_pain_type = t(:,3);
Here is where I get stuck. Also there are two possible outcomes T or F
patient_outcome = '';
for this_row = t.' %what do i do here i tried
if (chest_pain_type>3) & (serum_cholestoral>0) & (st_depression>0.8) & (gender>0)
patient_outcome = 'T';
elseif (chest_pain_type>3) & (serum_cholestoral>0) & (st_depression>0.8) & (gender<=0) & (heart_condition>3)
patient_outcome = 'T';
elseif (chest_pain_type>3) & (serum_cholestoral>0) & (st_depression>0.8) & (gender<=0) & (heart_condition<=3) & (exercise_induced_angina>0)
patient_outcome = 'F';
end
end
Lastly then I want it to make a list of the outcomes for each patient (row) either T or F.
  4 Kommentare
Rik
Rik am 3 Dez. 2020
You can edit your question to put back the original title and content (and add the csv you attached to the comment you deleted).
Deleting things and changing the username is not generally an indication of good intentions, so go ahead and prove my cynicism wrong.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Image Analyst
Image Analyst am 1 Dez. 2020
Attach a CSV file so we can get started helping you. In the meantime, you probably want to do something like
numRows = height(t); % or size(t, 1)
patient_outcome = false(numRows, 1);
for row = 1 : numRows
if (chest_pain_type(row)>3) &&&& (serum_cholestoral(row)>0) && (st_depression(row)>0.8) && (gender(row)>0)
patient_outcome(row) = true;
elseif (chest_pain_type(row)>3) && (serum_cholestoral(row)>0) && (st_depression(row)>0.8) && (gender(row)<=0) && (heart_condition(row)>3)
patient_outcome(row) = true;
elseif (chest_pain_type(row)>3) && (serum_cholestora(row)l>0) && (st_depression(row)>0.8) && (gender(row)<=0) && (heart_condition(row)<=3) && (exercise_induced_angina(row)>0)
patient_outcome(row) = false;
end
end

Weitere Antworten (0)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by