We are building a patient outcome prediction model based on tabular data inputs. The tabular inputs indicate the patient records are represented by a row stored in a table, e.g.,
| uid | age | gender | label |
|---|---|---|---|
| 1 | 20 | female | 0 |
| 2 | 32 | male | 1 |
each row is a patient and we need to make a prediction for the targeting label taking the input feature age and gender as the input. In this project , we provide a complete pipeline for a tabular prediction problem including
- Data Preprocessing
- Feature Engineering
- Evaluation
This step is completed by data_preprocessing.py, including:
- manually check the data and assign the columns into three different types: binary, numerical, and categorical; save the results in three lists. The lists are saved in
feature_distribution.py. - fill NaN values with appropriate techniques considering the feature types.
In this step, we transforms each row of table to its corresponding textual descriptions, e.g., for the tabular data
| uid | age | gender | smoking | label |
|---|---|---|---|---|
| 1 | 20 | female | 0 | 1 |
| 2 | 32 | male | 1 | 0 |
we can obtain two sentences, one for each patient:
'age 20; gender female''age 32; gender male; smoking'
It should be noted during the processing you will need to consider the feature types. For numerical and categorical features, we need to concatenate the column names and the cell values; for binary features, we only keep the column when its value is 1.
In this step, we develop a neural network TextMLP with an embedding layer and fully-connected layers to make text classification. Consider the captioning of the raw patient record, e.g., 'age 20; gender female', we know the corresponding label is 1. This reduces to a text classification problem for prediction the patient outcome. Here we provide two versions: with pretrained or unpretrained embedding layer.
In this step, we implement the training function of the model TextMLP for binary classification in text_classification.py. run_textmlp.py and run_pretrained_textmlp.py are main scripts of running training and evalution of the two versions of TextMLP. The full training pipeline includes
-
We use the function:
sklearn.model_selection.train_test_splitto split the data, 20% for test and 80% for training. -
We use the pretrained tokenizers provided by
transformersto tokenize the input sentences to discreteindex input_idsandattention_mask. -
We provide a simple visualization function:
plot_loss( contained intext_classification.py) to analyze the training of models.