Wait time

The wait time spent in the ED is yet another visit information variable that could reasonably be correlated with the target variable. Hypothetically, patients with more serious illnesses could appear to be more symptomatic to the triage nurse and therefore assigned more critical triage scores, causing them to have smaller waiting times than people with less serious illnesses.

In the documentation, it states that the WAITTIME variable may take values of -9 and -7 when blank and not applicable, respectively. Whenever a continuous variable has a placeholder value like this, we must do some sort of imputation to remove the placeholder values. Otherwise, the model will think that the patient had a wait time of -7 minutes, and the whole model will be adjusted adversely.

In this case, mean imputation is the appropriate action. Mean imputation replaces those negative values with the mean of the rest of the dataset, so that during modeling time those observations will have no effect in determining the coefficient for this variable.

To perform mean imputation, we first convert the columns to the numeric type:

X_train.loc[:,'WAITTIME'] = X_train.loc[:,'WAITTIME'].apply(pd.to_numeric)
X_test.loc[:,'WAITTIME'] = X_test.loc[:,'WAITTIME'].apply(pd.to_numeric)

Next, we write a function, called mean_impute_values(), that removes values of -7 and -9 from the column and replaces them with the mean of the column. We make the function generalizable so that it may be used later on in our preprocessing for other columns:

def mean_impute_values(data,col): 
temp_mean = data.loc[(data[col] != -7) & (data[col] != -9), col].mean()
data.loc[(data[col] == -7) | (data[col] == -9), col] = temp_mean
return data

X_train = mean_impute_values(X_train,'WAITTIME')
X_test = mean_impute_values(X_test,'WAITTIME')

We then call the function on the data, and we are finished. Following that, we will confirm that this function has been applied correctly, but first, let's go over a few more variables.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset