机器学习课程总结,
本系列文章
以代码
和注释
为主。
理论部分搬至博客上比较耗费时间,所以缺少理论部分。但是也欢迎大家一起探讨学习。
如果需要理论部分的讲义,可私信(个人觉的讲的很好很全)。
问题需求
从UCI手写体数字集中随机挑选3类,分别使用PCA和LDA降维到二维平面,每类随机挑选20个样本进行可视化,可视化时不同类别使用不同颜色进行区分,并使用图例进行类别说明。
代码
- 对于LDA降维效果很差,没有找到合理的解释,欢迎补充
# -*- coding: utf-8 -*-#
# Author: xhc
# Date: 2021-06-18 22:04
# project: 0618
# Name: LDA_PCA比较.py
from sklearn.decomposition import PCA
from read_data import read_from_txt
import random
import matplotlib.pyplot as plt
from sklearn.discriminant_analysis import LinearDiscriminantAnalysis
filename = ('./data/UCI_digits.train')
X,_,Y = read_from_txt(filename,Dim1 = 1024,Dim2 = 64)
model_pca = PCA(n_components=2) # n_components维度
x_pca = model_pca