Dataset Exploration and Analysis
20250320 Multivariate Analysis. Assignment 2, analysis of differences between genuine and counterfeit Swiss Franc banknotes

The cover image is generated by ChatGPT, depicting data analysis. The prompt used is “A modern data analysis concept illustration featuring a futuristic workspace. The image includes multiple data charts, graphs, and dashboards displayed on transparent holographic screens. A diverse team of analysts and data scientists collaborate, analyzing trends and insights on large monitors. The scene has a sleek, high-tech atmosphere with glowing blue and purple hues, reflecting a professional and cutting-edge environment.” 。
Introduction
The dataset used in this analysis is the Swiss bank notes dataset, which is utilized by banks to distinguish between genuine and counterfeit old Swiss Francs. This study downloads the bank2.dat dataset from https://github.com/QuantLet/MVA/tree/master/QID-1530-MVAscabank56 and conducts the analysis using the R programming language.
Dataset
From the textbook, we know that the first 100 records in this dataset correspond to genuine banknotes, while the last 100 records correspond to counterfeit banknotes. The dataset consists of 200 observations and 6 variables.
Variable Description
According to Table 22.3, the dataset contains 6 variables, described as follows:
| Variable | Description |
|---|---|
| $X_1$ | Length of the bank note |
| $X_2$ | Height of the bank note, measured on the left |
| $X_3$ | Height of the bank note, measured on the right |
| $X_4$ | Distance of inner frame to the lower border |
| $X_5$ | Distance of inner frame to the upper border |
| $X_6$ | Length of the diagonal |
We read the dataset in R and create a new variable, genuine, to indicate whether the banknote is genuine (1 for genuine, 0 for counterfeit). The corresponding R code is as follows:
| |
The Dataset
A portion of the dataset is shown below.
| X1 | X2 | X3 | X4 | X5 | X6 | genuine |
|---|---|---|---|---|---|---|
| 214.8 | 131.0 | 131.1 | 9.0 | 9.7 | 141.0 | 1 |
| 214.6 | 129.7 | 129.7 | 8.1 | 9.5 | 141.7 | 1 |
| 214.8 | 129.7 | 129.7 | 8.7 | 9.6 | 142.2 | 1 |
| 214.8 | 129.7 | 129.6 | 7.5 | 10.4 | 142.0 | 1 |
| 215.0 | 129.6 | 129.7 | 10.4 | 7.7 | 141.8 | 1 |
| 215.7 | 130.8 | 130.5 | 9.0 | 10.1 | 141.4 | 1 |
| … | … | … | … | … | … | … |
Summary
We can use the following code to quickly inspect the dataset.
| |
A brief summary of the dataset is as follows.
| |
From the above response, we can see that there are no missing values in this dataset.
Correlation Coefficient
The correlation coefficient is a method used to measure the linear relationship between two variables. It is calculated as follows. $$ \rho_{X, Y} = \frac{cov(X, Y)}{\sigma_X \sigma_Y} = \frac{E \left[ (X - \mu_X )(Y - \mu_Y) \right]}{\sigma_X \sigma_Y}, $$ Where $cov(X, Y)$ is the covariance between $X$ and $Y$, $\mu_X$ and $\mu_Y$ are the population means of $X$ and $Y$, and $\sigma_X$ and $\sigma_Y$ are the population standard deviations of $X$ and $Y$.
The above is known as the population correlation coefficient. In a dataset, by estimating the sample covariance and standard deviation, we can calculate the sample correlation coefficient, which is given by the following formula. $$ r = \frac{\sum_{i=1}^n(X_i - \bar{X})(Y_i - \bar{Y})}{\sqrt{\sum_{i=1}^n(X_i - \bar{X})^2} \sqrt{\sum_{i=1}^n(Y_i - \bar{Y})^2}} = \frac{1}{n - 1}\sum_{i=1}^n \left(\frac{(X_i - \bar{X})}{\sigma_X}\right) \left(\frac{(Y_i - \bar{Y})}{\sigma_Y}\right), $$ Where $X_i$ and $Y_i$ represent the values of the $i$-th sample in the dataset, and $\bar{X}$ and $\bar{Y}$ are the sample means of $X$ and $Y$, respectively.
In R, the cor(dataset) function can be used to generate the correlation coefficients between each variable. Additionally, various packages can be used to visualize the correlation coefficients. Below, we use the ggcorrplot package to visualize the correlation matrix. The correlation coefficients are displayed, with blue representing negative correlations and red representing positive correlations. The size of the points increases with the strength of the correlation, while points with correlations close to 0 become smaller.
| |

From the above plot, we can observe that $X_6$ has a strong positive correlation in distinguishing between genuine and counterfeit banknotes, while $X_1$ shows little to no linear correlation.
Scatter Plot
A scatter plot is one of the simplest ways to visualize data. You can easily create a scatter plot using plot(x_coordinates, y_coordinates). If there are many variables, you can use pairs to create scatter plots for every pair of variables. Here’s how to do it.
| |

From the above plot, we can observe that there seems to be a linear relationship between $X_2$, $X_3$, $X_4$, $X_5$, and $X_6$, while $X_1$ does not show a strong relationship with the other variables. Also, since genuine is a categorical variable, its interactions with other variables are always confined to 0 and 1.
2D Scatter Plot
Of course, we can also plot a scatter plot for each pair of variables individually. Below, we will plot the scatter plot for each pair of data and use the genuine variable to distinguish between genuine and counterfeit notes with different colors.
| |
We can obtain the following scatter plots.
From the above pairwise scatter plots, we can observe that some plots, such as those of $X_1$ and $X_2$, $X_1$ and $X_3$, $X_1$ and $X_5$, and $X_2$ and $X_5$, show very fuzzy boundaries and do not provide a clear distinction between genuine and counterfeit notes. On the other hand, plots such as $X_2$ and $X_6$, $X_3$ and $X_6$, $X_4$ and $X_5$, $X_4$ and $X_6$, and $X_5$ and $X_6$ demonstrate more distinct separations. Using these pairwise variables, it is easier to distinguish between genuine and counterfeit notes.
With these more distinguishable scatter plots, methods such as Decision Trees, Support Vector Machines (SVM), and K-Nearest Neighbors (KNN) can be used to classify and predict whether new banknotes (data) are genuine or counterfeit.
3D Scatter Plot
We can also create a 3D scatter plot. Here is the code to do so.
| |
From the 3D scatter plot, we can better observe the interactions between any three sets of data.
We can also use the plotly package to create an interactive 3D scatter plot.
| |
If you are unable to view the interactive 3D scatter plot or need to view it in full screen, please click here to access it.
Box Plot
A box plot, also known as a box-and-whisker plot, arranges all values in the dataset from smallest to largest and divides them into four equal parts. The values at the three dividing points are the quartiles. From a box plot, we can easily identify the extreme values and the quartiles. We can use the following code to plot a box plot.
| |


In each of the plots, the dashed line represents the mean of the data, while the solid line represents the second quartile (median, Q2). The upper and lower limits of the box represent the third quartile (Q3) and the first quartile (Q1), respectively. The upper and lower boundaries show the maximum and minimum values, excluding extreme values (outliers). The interquartile range (IQR) is the difference between Q3 and Q1. If a data point is greater or less than 1.5 times the IQR from the box, it is considered an outlier.
Upon observing the box plots, we can see that for $X_1$, $X_2$, $X_3$, and $X_5$, the box plots for genuine and counterfeit notes do not show significant differences, making these variables less suitable for standalone analysis. Although the box plot for $X_4$ indicates a larger difference in mean and median between the two categories, there is still a substantial overlap in the box plot for genuine notes, which makes it less suitable for standalone analysis as well. However, for $X_6$, the box plot clearly shows a distinct difference between genuine and counterfeit notes, with almost no overlap in the data range, making it suitable for analysis and differentiation between genuine and counterfeit notes.
Histogram
A histogram is a two-dimensional statistical chart that groups data into intervals and represents the number of data points within each interval with the height of bars. It provides an intuitive way to observe the distribution of data. In R, we can use the hist() function to plot histograms. Below, we plot histograms for each variable and distinguish between genuine and counterfeit notes using blue and red colors.
| |
From the histograms, we can observe that in the variable $X_6$, the overlapping part is the smallest, accounting for only about 2% of the total. In contrast, the overlapping part in $X_1$ is the largest, accounting for approximately 73% of the total. This indicates that, compared to $X_1$, using $X_6$ or $X_4$ for classification could provide higher discriminative power. The overlap in $X_6$ is only 2%, and in $X_4$, it is only 15%, meaning these variables can more effectively distinguish between genuine and counterfeit notes. On the other hand, the overlap in $X_1$ reaches 76%, suggesting that $X_1$ performs weaker in differentiating between the two categories. Therefore, choosing $X_6$ may lead to better recognition of genuine and counterfeit notes.
Kernel Density Estimation (KDE)
Kernel density estimation is a method used to estimate the probability density function (PDF) of a random variable. For each data point in a dataset, KDE draws a local distribution based on a kernel function, and then sums these local distributions to form the overall estimated density function. Compared to histograms, kernel density estimation provides a smoother and continuous distribution curve.
Assuming $x_1, x_2, \cdots, x_n$ are independent and identically distributed (i.i.d.) samples, we can estimate the kernel density using the following formula:
$$ \hat{f}_h (x) = \frac{1}{n} \sum_{i=1}^{n} K_h (x - x_i) = \frac{1}{nh} \sum_{i=1}^{n} K \left( \frac{x - x_i}{h} \right), $$
Here, $K$ is a non-negative kernel function, and $h > 0$ is the smoothing parameter (bandwidth).
In this case, we use the Biweight kernel function, which is given by the following formula: $$ K(u) = \begin{cases} \frac{16}{15} (1 - u^2)^2, & \text{for } |u| \leq 1; \\ 0, & \text{for } |u| > 1. \end{cases} $$
We can use the following code to plot the estimated probability density function.
| |
Compared to histograms, kernel density estimation can approximate the probability density function in a smoother, continuous way. It is important to note that for both kernel density estimation and histograms, choosing an appropriate bandwidth is a crucial factor that affects the graphical result. Too much or too little bandwidth can lead to overly fragmented or coarse graphs, making it harder to discern the overall trend.
The kernel density estimation plots created using $X_1$ to $X_6$ show that the degree of overlap between the blue and red curves reflects the variable’s ability to discriminate between classes. The more clearly the curves separate, the better the variable is at distinguishing between true and counterfeit notes. From the plots, we can draw the following conclusions:
- $X_1$: The peak is slightly skewed, but the two curves almost overlap, with a large overlapping range, indicating weak discriminative ability.
- $X_2$: The peak is slightly skewed, with a wide overlapping range. The main peaks differ but the difference is limited, suggesting weak discriminative ability.
- $X_3$: There is a noticeable difference in the distribution curves for true and counterfeit notes, with distinct peaks, indicating moderate discriminative ability.
- $X_4$: The distribution ranges for true and counterfeit notes are separate with minimal overlap, indicating excellent discriminative ability.
- $X_5$: The distribution shapes and ranges for true and counterfeit notes are similar, but with different peaks, indicating moderate discriminative ability.
- $X_6$: The distribution ranges for true and counterfeit notes are separate with very little overlap, indicating excellent discriminative ability.
Andrews’ Curves
Andrews’ Curves utilize the expansion form of the Fourier series for visualizing multidimensional data, transforming each data point into a continuous curve. This allows for an intuitive representation of similarities and differences between samples in a two-dimensional coordinate system.
Each multivariate observation $X_i = \begin{pmatrix} X_{i,1} & X_{i,2} & \cdots & X_{i,p} \end{pmatrix}$ can be converted into a parameterized curve $f_i(t)$. Depending on whether the dimensionality $p$ is odd or even, its expansion form is given by: $$ f_i(t) = \begin{cases} \frac{X_{i,1}}{\sqrt{2}} + X_{i,2} \sin(t) + X_{i,3} \cos(t) + \cdots + X_{i,p-1} \sin \left( \frac{p-1}{2} t \right) + X_{i,p} \cos \left( \frac{p-1}{2} t \right), & \text{for } p \text{ odd}; \\ \frac{X_{i,1}}{\sqrt{2}} + X_{i,2} \sin(t) + X_{i,3} \cos(t) + \cdots + X_{i,p} \sin \left( \frac{p}{2} t \right), & \text{for } p \text{ even}. \end{cases} $$
We can construct the following code to plot Andrews’ Curves.
| |

From the Andrews’ Curves shown in the figure, we can observe that the blue curve (representing genuine banknotes) primarily concentrates in the middle fluctuating region, remaining relatively stable overall. On the other hand, the red curve (representing counterfeit banknotes) exhibits higher variability in different sections, with a wider range of fluctuations. At $t \approx 2$, $t \approx 4$, and $t \approx 6$, the counterfeit curve displays more dispersion and amplitude variation in these regions, indicating that there is greater variability among the samples in this group.
Logistic Regression
For general classification problems, we can use logistic regression and random forests to build models.
Logistic regression is a binary classification model represented by the conditional probability $P(Y|X)$, which follows a parametric logistic distribution. The random variable $X$ is a real number, while $Y$ takes values of 0 or 1.
For the banknote authentication dataset, we use a logistic regression model, setting genuine as the dependent variable and $X_1, \cdots, X_6$ as the independent variables. In this implementation, 70% of the data is used for training, and 30% is used for testing. The analysis is as follows.
Data Analysis and Model Summary
A brief data analysis and model summary are as follows:
| |
| |
From the output, we can see that the model’s AIC is 14, and the coefficient descriptions are as follows:
- The coefficients for $X_1$, $X_2$, and $X_6$ are positive, indicating that higher values increase the probability of the banknote being genuine.
- The coefficients for $X_3$, $X_4$, and $X_5$ are negative, indicating that higher values decrease the probability of the banknote being genuine.
Confusion Matrix and ROC Curve
We use the following code to make predictions.
| |
| |
The confusion matrix shows that the model has a high classification accuracy for both classes. It achieves a perfect classification rate for counterfeit banknotes (Class 0) and a very low error rate for genuine banknotes (Class 1).

The ROC curve (Receiver Operating Characteristic curve) illustrates the trade-off between benefit (True Positive Rate, TPR) and cost (False Positive Rate, FPR) for the classifier. The AUC (Area Under Curve) represents the area under the ROC curve, serving as a common statistical measure of a classifier’s predictive performance.
The AUC value of 0.9886 confirms that the logistic regression model performs exceptionally well in classifying banknotes on the test set (86 observations). This aligns with the confusion matrix results, which show 98.8% accuracy, TPR = 0.977, and FPR = 0.
| Metric | Calculation | Result |
|---|---|---|
| Class 1 (Positive) Error Rate | FN / (TP + FN) | 1 / 44 ≈ 2.27% |
| Class 1 Sensitivity (Recall) | TP / (TP + FN) | 43 / 44 ≈ 97.73% |
| Class 0 Error Rate | FP / (TN + FP) | 0 / 42 = 0% |
| Class 0 Specificity | TN / (TN + FP) | 42 / 42 = 100% |
Random Forest
Random Forest is a learner composed of many different decision trees. The principle behind it is to combine multiple “weak learners” to construct a stronger model. The basic idea of a “strong learner” is to combine several CART trees and introduce randomly assigned training data to improve the computational results.
Data Analysis and Model Summary
A brief data analysis and model summary are as follows:
| |
| |
From the model’s performance, we can see that the 0.88% OOB (Out-of-Bag) error rate indicates excellent performance. On average, only 1 out of every 113 predictions is incorrect.
The confusion matrix shows that the model has highly accurate classification for both classes. It achieves a perfect classification rate for Class 0 (0% error rate) and a very low error rate for Class 1 (1.75%).
Important Variables
| |
| |

Based on feature selection, we can see that $X_6$ and $X_4$ have the greatest influence. Other features fall within the range of 0 to 10.
ROC curve
| |

The ROC curve and AUC = 1 indicate that the Random Forest model is a perfect classifier for the dataset, achieving 100% true positive rate and 0% false positive rate.
Environment
- Operating System: Windows 11 24H2
- Programming Language: R 4.4.2
Further Learning
- The R Notebook HTML file used in this article.
References
Wolfgang Karl Härdle, Léopold Simar. (2015). Applied Multivariate Statistical Analysis (4th ed.). Springer. https://link.springer.com/book/10.1007/978-3-662-45171-7
Quantnet. (2025, January 27). MVA. Github. https://github.com/QuantLet/MVA







