本文主要是介绍模式识别II改进版Python,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
import matplotlib.pyplot as plt import numpy as np import pandas as pd import seaborn as sns from sklearn import datasets from sklearn import manifold from sklearn.metrics import accuracy_score# 获取数据 data = datasets.fetch_openml('mnist_784', version=1, return_X_y=True) pixel_values, targets = data targets = targets.astype(int) pixel_array = pixel_values.to_numpy() single_image = pixel_array[1, :].reshape(28, 28)# 展示图像 plt.imshow(single_image, cmap='gray') plt.show()
def visualize_tsne(X, y):plt.figure(figsize=(10, 8))sns.scatterplot(x=X[:, 0], y=X[:, 1], hue=y, palette=sns.color_palette("hls", 10), legend="full", alpha=0.8)plt.title('t-SNE visualization of MNIST data')plt.show()
# 使用 t-SNE 进行降维 tsne = manifold.TSNE(n_components=2, random_state=42, perplexity=25) transformed_data = tsne.fit_transform(pixel_array)
这篇关于模式识别II改进版Python的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!