说明:这里使用的是KNN算法来降维,PCA降维同样适合其它算法
准备数据
import numpy as np
import matplotlib.pyplot as plt
from sklearn import datasets
# 准备数据
digits = datasets.load_digits()
X = digits.data
y = digits.target
# 分割数据
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=666)
# 查看数据维度
X_train.shape # (1347, 64)