text: import numpy as np
  
  feature_num=784 # 总特征数
  learning_num = 60000  # 学习样本数
  testing_num = 10 # 测试样本数
  K = 10 # 总类别数
  N = 60000  # 总样本数
  pca_num = 3 # 压缩特征维度
  data = np.load("mnist.npz")
  x_train = data['x_train']  # 学习集集图像
  y_train = data['y_train']  # 学习集标签
  x_test = data['x_test']  # 测试集图像
  y_test = data['y_test']  # 测试集标签
  
  # 读入训练集与测试集样本
  x=np.zeros((learning_num,feature_num)) # 学习样本
  for i in range(learning_num):
      for j in range(feature_num):
          x[i][j]=x_train[i][j//28][j%28] # 样本向量化
  y=np.zeros((testing_num,feature_num)) # 测试样本
  for i in range(testing_num):
      for j in range(feature_num):
          y[i][j] = x_test[i][j // 28][j % 28]  # 样本向量化
  
  # 初始化先验概率
  import matplotlib.pyplot as plt
  total=np.zeros((256,1)) # 每种标签数量
  for i in range(learning_num):
      label=y_train[i]
      if label==4:
          total[int(x[i][425])]+=1
  for i in range(0,255):
      plt.scatter(i,total[i],s=10,color="green")
  plt.show()