摘要:
合集:AI案例-ML-泛金融业
AI问题:聚类分析
数据集:纸币真伪辨识数据是从真实和伪造的类似钞票的标本拍摄的图像中提取的。
发布方:Lohweg, V. (2012). Banknote Authentication [Dataset]. UCI Machine Learning Repository.
数据集价值:纸币真伪辨识
解决方案:特征提取
一、问题描述
纸币真伪辨识数据是从真实和伪造的类似钞票的标本拍摄的图像中提取的。为了数字化,使用了通常用于印刷检查的工业相机。最终图像具有400×400像素。由于物镜和到被调查物体的距离,获得了分辨率约为660 dpi的灰度图片。使用小波变换工具(Wavelet Transform tool)从图像中提取特征。
小波变换是一种数学工具,用于分析信号和图像的多尺度特性。它可以将图像分解成不同频率的子带,从而提供更丰富的图像细节信息。
在图像处理领域,小波变换常用于以下几个方面:
- 图像压缩:通过去除冗余的高频信息,可以实现高效的图像压缩。
- 图像去噪:小波变换有助于识别和去除图像中的噪声。
- 特征提取:可以提取图像中的边缘、纹理等重要特征,用于后续的模式识别或分类任务。
- 图像修复:利用小波变换可以更精确地定位和修复图像中的损坏部分。
二、数据集内容
数据结构
BankNote_Authentication.csv字段信息如下:
variance/V1:小波变换图像的方差(连续值)
skewness/V2:小波变换图像的偏度(连续值)
curtosis/V3:小波变换图像的峰度(连续值)
entropy/V4:图像的熵(连续值)
class:真伪分类(整数)。0:假;1:真。
数据样例
variance | skewness | curtosis | entropy | class |
---|---|---|---|---|
3.6216 | 8.6661 | -2.8073 | -0.44699 | 0 |
4.5459 | 8.1674 | -2.4586 | -1.4621 | 0 |
3.866 | -2.6383 | 1.9242 | 0.10645 | 0 |
3.4566 | 9.5228 | -4.0112 | -3.5944 | 0 |
0.32924 | -4.4552 | 4.5718 | -0.9888 | 0 |
4.3684 | 9.6718 | -3.9606 | -3.1625 | 0 |
3.5912 | 3.0129 | 0.72888 | 0.56421 | 0 |
2.0922 | -6.81 | 8.4636 | -0.60216 | 0 |
3.2032 | 5.7588 | -0.75345 | -0.61251 | 0 |
1.5356 | 9.1772 | -2.2718 | -0.73535 | 0 |
数据集来源
Author: Volker Lohweg (University of Applied Sciences, Ostwestfalen-Lippe)
Source: [UCI](https://archive.ics.uci.edu/ml/datasets/banknote+authentication) - 2012
数据集发布时间:2012年
数据集引用要求
Lohweg, V. (2012). Banknote Authentication [Dataset]. UCI Machine Learning Repository. https://doi.org/10.24432/C55P57.
三、聚类分析
安装
安装后的开发包版本信息:
python 3.12.7 h14ffc60_0 anaconda
numpy 1.26.4 py312hfd52020_0 anaconda
scipy 1.13.1 py312hbb039d4_0 anaconda
pandas 2.2.2 py312h0158946_0 anaconda
scikit-learn 1.5.1 py312h0158946_0 anaconda
matplotlib 3.9.2 py312haa95532_0 anaconda
seaborn 0.13.2 py312haa95532_0 anaconda
statsmodels 0.14.2 py312h4b0e54e_0 anaconda
运行
Banknote_Authentication.ipynb
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 1372 entries, 0 to 1371
Data columns (total 5 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 V1 1372 non-null float64
1 V2 1372 non-null float64
2 V3 1372 non-null float64
3 V4 1372 non-null float64
4 Class 1372 non-null int64
dtypes: float64(4), int64(1)
memory usage: 53.7 KB
聚类分析:
data = np.column_stack(( df.V1, df.V2)) # we use only V1 and V2
# compute K-Means
km_res = KMeans(n_clusters = 2).fit(data)
clusters = km_res.cluster_centers_
# put the assigned labels to the original dataset
df['KMeans'] = km_res.labels_
#plot out the result
g = sb.FacetGrid(data = df, hue = 'KMeans', height = 5)
g.map(plt.scatter, 'V1', 'V2')
g.add_legend();
plt.scatter(clusters[:,0], clusters[:,1], s=500, marker='*', c='r')
计算准确率:
correct = 0
for i in range(0,1372):
if df.Class[i] == df["KMeans"][i]:
correct+=1
print(correct/1371)
# 输出:The accuracy of this K-Means Model is 65.3%
这个K-Means模型的准确率是65.3%。