Diagnose dermatological diseases from clinical and histopathological features using machine learning

This example aims to identify which dermatological disease is suffering the patient.

The differential diagnosis of erythemato-squamous diseases is a real problem in dermatology. The diseases in this group are psoriasis, seboreic dermatitis, lichen planus, pityriasis rosea, cronic dermatitis, and pityriasis rubra pilaris.


  1. Application type.
  2. Data set.
  3. Neural network.
  4. Training strategy.
  5. Model selection.
  6. Testing analysis.
  7. Model deployment.

This example is solved with Neural Designer. To follow it step by step, you can use the free trial.

1. Application type

This is a classification project, since the variable to be predicted is categorical (psoriasis, seboreic dermatitis, lichen planus, pityriasis rosea, cronic dermatitis, or pityriasis rubra pilaris).

The goal here is to model the probabilities of class membership, conditioned on the input variables.

2. Data set

The file dermatology.csv contains 366 samples, each of them with 34 inputs and one of them is categorical target.

In the dataset constructed for this domain, the family history feature has the value 1 if any of these diseases has been observed in the family, and 0 otherwise. The age feature simply represents the age of the patient. Every other feature (clinical and histopathological) was given a degree in the range of 0 to 3. Here, 0 indicates that the feature was not present, 3 indicates the largest amount possible, and 1, 2 indicate the relative intermediate values.

The following list summarizes the variables information:

Regarding clinical attributes: (take values 0=low, 1=medium low, 2=medium high, 3=high, unless otherwise indicated)

As far as histopathological attributes: (take values 0, 1, 2, 3)

The target varibale represents which problem is suffering the patient such as psoriasis, seboreic dermatitis, lichen planus, pityriasis rosea, cronic dermatitis, or pityriasis rubra pilaris.

The instances are split at random into training (60%), selection (20%), and testing (20%) subsets.

Once the data set has been set, we are ready to perform a few related analytics. With that, we check the provided information and make sure that the data has good quality.

We can calculate the data statistics and draw a table with the minimums, maximums, means, and standard deviations of all variables in the data set. The next table depicts the values.

By calculating the data distribution, we can see the number of instances belonging to each class in the data set.

As we can see, the number of instances belonging to psoriasis is 30.6%, the most of the samples, and pitiriasis rubra pilaris represent 5.5% of the samples, approximately.

Finally, the inputs-targets correlations might indicate to us what factors most influence in dermatological diseases.

Here, the most correlated variables with the diagnose are follicular horn plug, follicular papules and elongation of the rete ridges.

3. Neural network

The second step is to set a neural network to represent the classification function. For this class of applications, the neural network is composed of:

The scaling layer uses the minimum and maximum scaling method.

The number of perceptron layers is 2:

The probabilistic layer uses the softmax probabilistic method.

Due to the fact that we have a huge range of inputs, an overview graphical representation of the neural network is depicted next.

4. Training strategy

The procedure used to carry out the learning process is called a training strategy. The training strategy is applied to the neural network to obtain the best possible performance. The type of training is determined by how the adjustment of the parameters in the neural network takes place.

We set the normalized squared error with L1 regularization as the loss index.

On the other hand, we use the quasi-Newton method as optimization algorithm.

The following chart shows how the training and selection errors decrease with the quasi-Newton method's epochs during the training process.

As we can see, both curves' behavior is similar along with the iterations, which means that no over-fitting has appeared. The final training and selection errors are training error = 0.0107 NSE and selection error = 0.0839 NSE. That indicates that the neural network has good generalization capabilities.

5. Model selection

The objective of model selection is to find the network architecture with the best generalization properties, that is, that which minimizes the error on the selected instances of the data set.

More specifically, we want to find a neural network with a selection error of less than 0.0839 WSE, which is the value that we have achieved so far.

Order selection algorithms train several network architectures with a different number of neurons and select that with the smallest selection error.

The incremental order method starts with a small number of neurons and increases the complexity at each iteration. The following chart shows the training error (blue) and the selection error (orange) as a function of the number of neurons.

The figure below shows the final architecture for the neural network.

It shows that neurons selection does not decrease the training error and the inputs selection can be changed to obtain a better model. The number of inputs is 16, and the number of outputs is 1. The complexity, represented by the numbers of hidden neurons, is 16: 3: 6.

6. Testing analysis

Once the model is trained, we perform a testing analysis to validate its prediction capacity. We use a subset of data that has not been used before, the testing instances.

The next table shows the confusion matrix for our problem. In the confusion matrix, the rows represent the real classes and the predicted classes' columns for the testing data.

Predicted seboreic_dermatitis Predicted psoriasis Predicted lichen_planus Predicted cronic_dermatitis Predicted pityriasis_rosea Predicted pityriasis_rubra_pilaris
Real seboreic_dermatitis 11 (15%) 0 0 0 0 0
Real psoriasis 0 20 (27%) 0 0 0 0
Real lichen_planus 0 0 11 (15%) 0 0 0
Real cronic_dermatitis 0 0 0 16 (21%) 0 0
Real pityriasis_rosea 3 (%4) 0 0 0 5 (6%) 0
Real pityriasis_rubra_pilaris 0 0 0 0 0 7 (9%)

As we can see, the number of instances that the model can correctly predict is 70 (95%) while it misclassifies only 3 (4%). This shows that our predictive model has a great classification accuracy.

7. Model deployment

The neural network is now ready to predict the activity of new people in the so-called model deployment phase.

The file dermatology.py implements the mathematical expression of the neural network in Python. This piece of software can be embedded in any tool to make predictions on new data.

Besides, we can use the mathematical expression of the neural network, which is listed next.

scaled_erythema = erythema*(1+1)/(3-(0))-0*(1+1)/(3-0)-1;
scaled_ definite_borders =  definite_borders*(1+1)/(3-(0))-0*(1+1)/(3-0)-1;
scaled_itching = itching*(1+1)/(3-(0))-0*(1+1)/(3-0)-1;
scaled_koebner_phenomenon = koebner_phenomenon*(1+1)/(3-(0))-0*(1+1)/(3-0)-1;
scaled_ follicular_papules =  follicular_papules*(1+1)/(3-(0))-0*(1+1)/(3-0)-1;
scaled_scalp_involvement = scalp_involvement*(1+1)/(3-(0))-0*(1+1)/(3-0)-1;
scaled_ melanin_incontinence =  melanin_incontinence*(1+1)/(3-(0))-0*(1+1)/(3-0)-1;
scaled_ eosinophils_in_th_infiltrate =  eosinophils_in_th_infiltrate*(1+1)/(2-(0))-0*(1+1)/(2-0)-1;
scaled_ fibrosis_of_the_papillary_dermis =  fibrosis_of_the_papillary_dermis*(1+1)/(3-(0))-0*(1+1)/(3-0)-1;
scaled_ parakeratosis =  parakeratosis*(1+1)/(3-(0))-0*(1+1)/(3-0)-1;
scaled_ disappearance_of_the_granular_layer =  disappearance_of_the_granular_layer*(1+1)/(3-(0))-0*(1+1)/(3-0)-1;
scaled_ spongiosis =  spongiosis*(1+1)/(3-(0))-0*(1+1)/(3-0)-1;
scaled_ saw_tooth_appearance_of_retes =  saw_tooth_appearance_of_retes*(1+1)/(3-(0))-0*(1+1)/(3-0)-1;
scaled_ perifollicular_parakeratosis =  perifollicular_parakeratosis*(1+1)/(3-(0))-0*(1+1)/(3-0)-1;
scaled_ inflammatory_monoluclear_inflitrate =  inflammatory_monoluclear_inflitrate*(1+1)/(3-(0))-0*(1+1)/(3-0)-1;
scaled_band_like_infiltrate = band_like_infiltrate*(1+1)/(3-(0))-0*(1+1)/(3-0)-1;

perceptron_layer_0_output_0 = tanh[ 0.589574 + (scaled_erythema*-0.103196)+ (scaled_ definite_borders*-0.0216219)+ (scaled_itching*0.278016)+ (scaled_koebner_phenomenon*-0.204893)+ (scaled_ follicular_papules*-0.260485)+ (scaled_scalp_involvement*0.0202132)+ (scaled_ melanin_incontinence*0.436679)+ (scaled_ eosinophils_in_th_infiltrate*-0.299509)+ (scaled_ fibrosis_of_the_papillary_dermis*1.34959)+ (scaled_ parakeratosis*0.222804)+ (scaled_ disappearance_of_the_granular_layer*0.0852604)+ (scaled_ spongiosis*-0.976359)+ (scaled_ saw_tooth_appearance_of_retes*0.824049)+ (scaled_ perifollicular_parakeratosis*-1.1189)+ (scaled_ inflammatory_monoluclear_inflitrate*0.247217)+ (scaled_band_like_infiltrate*0.580347) ];
perceptron_layer_0_output_1 = tanh[ -0.649114 + (scaled_erythema*-0.127602)+ (scaled_ definite_borders*-0.0675696)+ (scaled_itching*-0.00189255)+ (scaled_koebner_phenomenon*0.146217)+ (scaled_ follicular_papules*-1.09322)+ (scaled_scalp_involvement*-0.880752)+ (scaled_ melanin_incontinence*0.83091)+ (scaled_ eosinophils_in_th_infiltrate*0.872873)+ (scaled_ fibrosis_of_the_papillary_dermis*-1.11174)+ (scaled_ parakeratosis*-0.394869)+ (scaled_ disappearance_of_the_granular_layer*-0.245342)+ (scaled_ spongiosis*1.37317)+ (scaled_ saw_tooth_appearance_of_retes*0.724337)+ (scaled_ perifollicular_parakeratosis*-1.11989)+ (scaled_ inflammatory_monoluclear_inflitrate*-0.423457)+ (scaled_band_like_infiltrate*0.361908) ];
perceptron_layer_0_output_2 = tanh[ 0.3929 + (scaled_erythema*-0.278656)+ (scaled_ definite_borders*0.0599345)+ (scaled_itching*-0.530159)+ (scaled_koebner_phenomenon*2.13054)+ (scaled_ follicular_papules*-0.818439)+ (scaled_scalp_involvement*0.0457531)+ (scaled_ melanin_incontinence*0.306114)+ (scaled_ eosinophils_in_th_infiltrate*-0.649537)+ (scaled_ fibrosis_of_the_papillary_dermis*-1.92075)+ (scaled_ parakeratosis*0.337462)+ (scaled_ disappearance_of_the_granular_layer*1.28542)+ (scaled_ spongiosis*-0.681489)+ (scaled_ saw_tooth_appearance_of_retes*0.768623)+ (scaled_ perifollicular_parakeratosis*-0.633759)+ (scaled_ inflammatory_monoluclear_inflitrate*0.301181)+ (scaled_band_like_infiltrate*0.0984986) ];

probabilistic_layer_combinations_0 = 0.249743 -0.793859*perceptron_layer_0_output_0 +2.18813*perceptron_layer_0_output_1 -2.20851*perceptron_layer_0_output_2 
probabilistic_layer_combinations_1 = 0.40859 +0.286713*perceptron_layer_0_output_0 -2.31238*perceptron_layer_0_output_1 +2.32732*perceptron_layer_0_output_2 
probabilistic_layer_combinations_2 = 0.00444706 +2.15703*perceptron_layer_0_output_0 +1.74745*perceptron_layer_0_output_1 +0.95324*perceptron_layer_0_output_2 
probabilistic_layer_combinations_3 = 0.154935 +2.13898*perceptron_layer_0_output_0 -1.03674*perceptron_layer_0_output_1 -1.58864*perceptron_layer_0_output_2 
probabilistic_layer_combinations_4 = -0.293141 -2.01381*perceptron_layer_0_output_0 +1.19921*perceptron_layer_0_output_1 +1.95707*perceptron_layer_0_output_2 
probabilistic_layer_combinations_5 = -0.448093 -1.69679*perceptron_layer_0_output_0 -1.63441*perceptron_layer_0_output_1 -1.30433*perceptron_layer_0_output_2 
sum_ = exp(probabilistic_layer_combinations_0 + exp(probabilistic_layer_combinations_1 + exp(probabilistic_layer_combinations_2 + exp(probabilistic_layer_combinations_3 + exp(probabilistic_layer_combinations_4 + exp(probabilistic_layer_combinations_5;

seboreic_dermatitis = exp(probabilistic_layer_combinations_0)/sum_;
psoriasis = exp(probabilistic_layer_combinations_1)/sum_;
lichen_planus = exp(probabilistic_layer_combinations_2)/sum_;
cronic_dermatitis = exp(probabilistic_layer_combinations_3)/sum_;
pityriasis_rosea = exp(probabilistic_layer_combinations_4)/sum_;
pitiriasis_rubra_pilaris = exp(probabilistic_layer_combinations_5)/sum_;


Related examples:

Related solutions: