Dollar logo

Blood donation campaign

By Roberto Lopez, Artelnics.

The aim of this study is to predict if a person is going to donate blood by using a recency, frequency, monetary and time (RFMT) marketing model.

In this tutorial a classification application in marketing is solved by means of a neural network. The data for this problem has been taken from the UCI Machine Learning Repository.

Dollar logo
Blood donation.

The database used for this study was taken from the donor database of Blood Transfusion Service Center in Hsin-Chu City in Taiwan.

Contents:

  1. Data set
  2. Neural network
  3. Loss index
  4. Training strategy
  5. Testing analysis
  6. Model deployment

1. Data set

The data set, obtained form the data file blooddonation.dat, contains the information used to create the model. It consists of 748 rows and 5 columns. The columns represent the variables and the rows represent the instances. The values in the rows are separated by commas. The following listing is a preview of the data file.

Blood donation dataset picture
Blood donation dataset.

The task "Report data set" shows a table with the name, units, description and use of all the variables in the data set.

Variables table
Variables table.

The "Calculate target class distribution" task plots a pie chart with the percentage of instances for each class. In this data set, the number of negative responses is much greater than the number of postive responses.

Target class distribution table
Target class distribution.

In order to have a better predictive model, it is necessary that the targets distribution be more uniform. The task "Balance targets distribution" balances the targets distribution by unusing those instances whose variables belong to the most populated bins. After performing this task, the distribution will be more uniform and, in consequence, the model will be of better quality. There are 392 instances set as unused, 214 instances for training, 71 instances for selection and 71 instances for testing.

Instances pie chart
Instances uses.

2. Neural network

The second step is to configure the model stuff. For classification problems, it is composed by:

  • Inputs.
  • Scaling layer.
  • Learning layers.
  • Probabilistic layer.
  • Outputs.

The following figure shows the neural network page in Neural Designer.

Neural network page screenshot
Neural network page.

The number of inputs, in this case, is 4 and the number of outputs is 1. The number of hidden perceptrons or complexity is 3, so this neural network can be denoted as 4:3:1.

The next figure is a graphical representation of the neural network used for this problem.

Neural network graph
Neural network graph.

3. Loss index

The third step is to configure the loss index, which is composed of two terms:

  1. An error term.
  2. A regularization term.

The following figure shows the loss index tab in Neural Designer.

Loss index page screenshot
Loss index page.

The objective term is to be the normalized squared error. It divides the squared error between the outputs from the neural network and the targets in the data set by a normalization coefficient. If the normalized squared error has a value of unity then the neural network is predicting the data 'in the mean', while a value of zero means perfect prediction of the data.

4. Training strategy

The fourth step is to set the training strategy. This learning process is applied to the neural network in order to get the best performance. The training strategy is composed of two algorithms:

  1. Initialization algorithm.
  2. Main algorithm.
The next figure shows the training strategy page in Neural Designer.

Training strategy page screenshot
Training strategy page.

We will not use any initialization algorithm here.The chosen main algorithm is the quasi-Newton method and we will leave the default training parameters, stopping criteria and training history settings.

The following chart shows how the performance decreases with the iterations during the training process. The initial value is 1.3559, and the final value after 22 iterations is 0.44294.

Performance history graph
Performance history.

The next table shows the training results by the quasi-Newton method. They include some final states from the neural network. As we can see the final performance and final generalization performance are similar and the gradient norm is almost zero.

Training results table
Training results.

5. Testing analysis

The last step is to evaluate the performance of the trained neural network. The standard way to do this is to compare the outputs of the neural network against data never seen before, the training instances.

The task "Calculate binary classification tests" provides us some useful information for testing the performance of a classification problem with two classes. The next figure shows the output of this task.

Binary classification tests table
Binary classification tests.

The parameter classification accuracy takes a value of 0.861, which means that the prediction is good for most of the cases.

The task "calculate confusion" depicts a table containing the data of a confusion matrix. The element (0,0) contains the true positives, the element (0,1) contains the false positives, the element (1,0) contains the false negatives, and the element (1,1) contains the true negatives for the variable diagnose. The number of correctly classified instances is 62, and the number of misclassified instances is 10.

Confusion matrix table
Confusion matrix.

So as to improve the quality of the model, it is useful to know which of the instances are classified as negative when they are positive and which of the instances are classified as positive when the are negative. The task "Calculate misclassified instances" provides us that information.

The next table shows the instances which are positive and are predicted as negative.

Misclassified instances table
Misclassified instances.

The next table shows the instances which are negative and are predicted as positive.

Misclassified instances table
Misclassified instances.

Finally, it can be plotted a ROC chart which is a graphical illustration of how well the classifier discriminates between the two different classes by using the task "Calculate ROC curve". The output is shown in the next figure.

ROC curve graph
ROC curve.

A random classifier has an area under curve 0.5 while a perfect classifier has an area under curve 1. In practice, this measure should take a value between 0.5 and 1. The closer to 1 area under curve, the better the classifier. In this example, this parameter is 0.804 which means a good performance.

6. Model deployment

Once the generalization performance of the multilayer perceptron has been tested, the neural network can be saved for future use in the so called production mode.

We can predict wheter a client is going to buy the product by running the "Calculate outputs" tasks. For that we need to edit the input variables through the corresponding dialog.

Inputs dialog
Inputs dialog.

Then the prediction is written in the viewer.

Predictions table
Variable y prediction value.

The mathematical expression represented by the neural network is written below. It takes the inputs recency, frequency, monetary and time to produce the output prediction about donation. For classification problems, the information is propagated in a feed-forward fashion through the scaling layer, the perceptron layers and the probabilistic layer. This expression can be exported anyware.


				scaled_Recency_=2*(Recency_-0)/(74-0)-1;
				scaled_Frequency=2*(Frequency-1)/(50-1)-1;
				scaled_Monetary_=2*(Monetary_-250)/(12500-250)-1;
				scaled_Time_=2*(Time_-2)/(98-2)-1;
				y_1_1=Logistic(3.01623
				-4.95446*scaled_Recency_
				-2.95225*scaled_Frequency
				-2.22063*scaled_Monetary_
				-9.05774*scaled_Time_);
				y_1_2=Logistic(0.388528
				+3.86174*scaled_Recency_
				+0.232707*scaled_Frequency
				+0.712215*scaled_Monetary_
				+0.104895*scaled_Time_);
				y_1_3=Logistic(-4.60915
				-2.99967*scaled_Recency_
				-0.894729*scaled_Frequency
				-1.93923*scaled_Monetary_
				-0.662819*scaled_Time_);
				non_probabilistic_Donation=Logistic(0.847524
				-7.91206*y_1_1
				-7.75137*y_1_2
				+15.968*y_1_3);
				(Donation) = Probability(non_probabilistic_Donation);

				Logistic(x){
					return 1/(1+exp(-x))
				}

				Probability(x){
					if x < 0
						return 0
					else if x > 1
						return 1
					else
						return x
				}