Santander Customer Satisfaction — A Self Case Study using Python
By: Ashish Thomas Chempolil
Tags: Kaggle, Data Science, Customer Satisfaction, Machine Learning

4. Exploratory data analysis

We will first delve deep into the dataset and observe all the features through visualizations which will aid us in getting conclusions as well as ideas for feature engineering. There are 370 features in total which are all anonymized (not including the ‘TARGET’ feature). We were able to get what information an anonymized feature convey from literature review and also by observing distribution of the values.

Since there were many features, we will check for features having zero variance (does not hold any information ie only 1 unique values present) and will remove them if found.

34 features were found to have zero variance and these were all removed.

We will now check for features that were duplicated (ie they shared same values across datapoints need not be the same feature name).

12 features were found to be duplicated and of this 6 were removed.

We will now remove all sparse features (features that have little information). A condition is set such that if feature has 99 percentile value to be 0 then it is considered as a sparse feature.

No missing values were also found.

The final number of features after removing unnecessary features are 142.

Now we will explore each feature.

4.1 TARGET

We can see that the dataset is highly imbalanced with only 3.96% being of unsatisfied customers and 96.04% being satisfied customers.

4.2 var3 (Region)

From looking at other literature and also at the number of unique values present (=208) this feature may be holding the information of the region where the customer is from. There is also an outlier in this feature which is -999999 which may be missing value. The values ranged from 0 to 208 except for the outlier. The most common unique value is found to be 2 (around 97% for both train and test data). Firstly we will convert all -999999 to -1 values and explore the value counts considering only values which does not include ‘2’.

Value counts of ‘var3’ excluding most common value ‘2’

Since looking at the value counts we can see that -1 represent only a small fraction of the entire dataset (even after excluding 2). So we will replace the missing values with most frequent value for this feature which is ‘2’.

4.3 var15 (Age)

The minimum value of var15 is found to be 5 and maximum value is 105 in train data. Since the value of var15 is from 5–105, it is safe to assume that this feature implies age of the customer. This is also evidenced in literature review.

Both the train and test data had similar distribution, both consisted of younger customers the most.

The minimum age of unsatisfied customers was found to be 23. It seems that every young customer (below the age of 23) are satisfied always. So we can create a new feature during feature engineering which essentially tells whether a customer is below the age of 23 or not.

4.4 var38 (mortgage values)

From the various literature in kaggle it was inferred that var38 might be the mortgage values.

Value Counts of var38

Here we are not able to get any information as one value is having very high frequency. We will print out each percentile values.

var38 values in percentile

We can see that there is a huge difference between 0 percentile value and 10 percentile value. This is the same case for 90 percentile value and 100 percentile value. Now we will check the distribution plot of var38 for all values that are below 97.5 percentile (above 97.5 percentile value 1 value is dominating, cannot extract usable information)

We can see that the above plot is right skewed with a outlandish peak between 100,000 and 150,000. We can apply log transformation and check the resulting distribution.

After applying log transformation

We can see that it looks similar to a normal distribution. Since machine learning models work better on normal distribution, we can create new datasets with log transformation and without log transformation for this feature and compare the performances during feature engineering phase.

4.4 Features with keywords

There were several features which had specific keywords in them which were: ‘imp’, ‘ind’, ‘num’, ‘saldo’ . These keywords were found to be short-forms for some spanish words which were obtained from several literature.

‘num’ features had the highest representation in the dataset.

Now what we will do is explore each keyword feature 1 by 1 by randomly selecting 2 features for each keyword and we will draw conclusions.

4.4.1 ‘imp’ feature

‘imp’ likey is shortened word for importe which is Spanish for amount(inferred from literature review). The total number of features with ‘imp’ keyword are 14. By looking at the value counts of the two randomly selected feature that had ‘imp’ keyword in them, we can see that the most common occurring value is 0 for both of them. 0 accounted for more than 87% for both of these features.

Frequency plot of a randomly selected ‘imp’ feature train and test data respectively

Distribution of a randomly selected ‘imp’ feature not including 0 after log transformation

Here also after log transformation, the distribution(excluding 0) becomes a lot like guassian. So we can put down a strategy for all ‘imp’ features.

Strategy for ‘imp’ features:

We can create a new dataset with log transformed (excluding 0) imp features. We can also create another dataset with no transformations applied (leaving as it is).

4.4.1 ‘saldo’ feature

The number of features with saldo keyword are 26. Now we will approach the data similar to how we approached ‘imp’ feature. By looking at the value counts for the 2 features we can see 0 is the most frequent value here also (around 95% of the entire train dataset).

Frequency plot of train and test data respectively

All ‘saldo’ features were found to be continuous.

Random ‘saldo’ faeture after log transformation(excluding zero)

Here also (as similiar to ‘imp’ feature), we can create new datasets with log transformation applied to saldo features except for 0 values which will be kept as it is.

Strategy for ‘saldo’ features:

We can create a new dataset with log transformed (excluding 0) saldo features. We can also create another dataset with no transformations applied (leaving as it is).

4.4.3 ‘num’ features

‘num’ may be short form for numerical. Exploring the value counts of all the ‘num’ features we can say that every feature with ‘num’ keyword are categorical in nature.

Some of the features with ‘num’ keyword with their corresponding number of unique values

The maximum number of unique values found for a feature with ‘num’ keyword is 172(total datapoints is around 70k) and minimum was 2. We will employ a strategy for ‘num’ feature:

Strategy for ‘num’ features

We will put a threshold on what is the maximum number of unique values that is allowed so that a feature can be defined as categorical. We will set the threshold as 10. We can create new datasets with response encoding, one hot encoding and leaving the features as it is for ‘num’ features.(This only applies to categorical features that are defined based on the rule above)

4.4.3 ‘ind’ features

‘ind’ feature may refer to indicator. After looking at the value counts all the features with ‘ind’ feature had only 2 unique values.

Strategy for ‘ind’ features

We are leaving these features as it is.