pca图像压缩python_python 原始相素特征和Pca压缩重建进行图像识别 识别性能可视化...

本文展示了如何使用Python进行PCA图像压缩,并通过线性SVM进行图像识别。通过PCA将数据降至20维,然后比较未压缩和压缩后的识别性能。虽然PCA压缩后识别率略有下降,但维度降低显著,达到68.75%。
摘要由CSDN通过智能技术生成

import pandas as pd

import numpy as np

digits_train = pd.read_csv('../Datasets/Breast-Cancer/optdigits.tra', header=None)

digits_test = pd.read_csv('../Datasets/Breast-Cancer/optdigits.tes', header=None)

x_digits = digits_train[np.arange(64)]

y_digits = digits_train[64]

X_train = x_digits.dropna(how='any')

y_train = y_digits.dropna(how='any')

x_digits_test = digits_test[np.arange(64)]

y_digits_test = digits_test[64]

X_test = x_digits_test.dropna(how='any')

y_test = y_digits_test.dropna(how='any')

print(X_train)

print(y_train)

from sklearn.svm import LinearSVC

svc = LinearSVC()

svc.fit(X_train,y_train)

y_predict = svc.predict(X_test)

from sklearn.decomposition import PCA

estimator = PCA(n_components=20)

pca_X_train = estimator.fit_transform(X_train)

pca_X_test = estimator.transform(X_test)

pca_svc = LinearSVC()

pca_svc.fit(pca_X_train,y_train)

pca_y_predict = pca_svc.predict(pca_X_test)

target_namearray = []

from sklearn.metrics import classification_report

print('The accuracy of linesvm is',svc.score(X_test,y_test))

print(classification_report(y_test,y_predict,target_names = np.arange(10).astype(str)))

from matplotlib import pyplot as plt

def show_values(pc, fmt="%.2f", **kw):

'''

Heatmap with text in e

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值