pca

LDA

北战南征 提交于 2019-11-30 16:17:35
    在 主成分分析(PCA)原理总结 中,我们对降维算法PCA做了总结。这里我们就对另外一种经典的降维方法线性判别分析(Linear Discriminant Analysis, 以下简称LDA)做一个总结。LDA在模式识别领域(比如人脸识别,舰艇识别等图形图像识别领域)中有非常广泛的应用,因此我们有必要了解下它的算法原理。     在学习LDA之前,有必要将其自然语言处理领域的LDA区别开来,在自然语言处理领域, LDA是隐含狄利克雷分布(Latent Dirichlet Allocation,简称LDA),他是一种处理文档的主题模型。我们本文只讨论线性判别分析,因此后面所有的LDA均指线性判别分析。 1. LDA的思想     LDA是一种监督学习的降维技术,也就是说它的数据集的每个样本是有类别输出的。这点和PCA不同。PCA是不考虑样本类别输出的无监督降维技术。LDA的思想可以用一句话概括,就是“投影后类内方差最小,类间方差最大”。什么意思呢? 我们要将数据在低维度上进行投影,投影后希望每一种类别数据的投影点尽可能的接近,而不同类别的数据的类别中心之间的距离尽可能的大。     可能还是有点抽象,我们先看看最简单的情况。假设我们有两类数据 分别为红色和蓝色,如下图所示,这些数据特征是二维的,我们希望将这些数据投影到一维的一条直线,让每一种类别数据的投影点尽可能的接近

Plotting PCA scores with color

丶灬走出姿态 提交于 2019-11-30 16:07:05
I'm doing PCA and I would like to plot first principal component vs second in R: pca<-princomp(~.,data=data, na.action=na.omit plot(pca$scores[,1],pca$scores[,2]) or maybe several principal components: pairs(pca$scores[,1:4]) however the points are black. How do I appropriately add color to the graphs? How many colors do I need? One for each principal component I am plotting? Or one for each row in my data matrix? Thanks EDIT: my data looks like this: > data[1:4,1:4] patient1 patient2 patient3 patient4 2'-PDE 0.0153750 0.4669375 -0.0295625 0.7919375 7A5 2.4105000 0.3635000 1.8550000 1.4080000

特征降维三种方式

一世执手 提交于 2019-11-30 16:01:04
降维实际上就是降低特征的个数,最终的结果就是特征和特征之间不相关。 降维:降维是指在某些限定条件下,降低随机变量(特征)个数,得到一组“不相关”主变量的过程 降维的两种方式: 1、特征选择 2、主成分分析(可以理解为一种特征提取的方式) 一、特征选择 定义:数据中包含冗余或相关变量(或称为特征、属性、指标等),旨在从原有特征中找出主要特征 特征选择的2中方法(过滤式 + 嵌入式) Filter(过滤式):主要探究特征本身特点、特征与特征和目标值之间关联。 方差选择法:低方差特征过滤.例如鸟类是否可以飞作为特征值是不合适的,此时的方差为0 相关系数:目的是去除冗余,确定特征与特征之间的相关性 Embedded(嵌入式):算法自动选择特征(特征与目标值之间的关联) 决策树:信息熵、信息增益 正则化:L1、L2 深度学习:卷积等 模块 sklearn.feature_selection 一、降维方式一:特征选择——过滤式——低方差过滤 低方差特征过滤 删除低方差的一些特征,从方差的大小来考虑方式的角度。 特征方差小:某个特征大多样本的值比较相近 特征方差大:某个特征很多样本的值有比较有差别 API sklearn.feature_selection.VarianceThreshold( threshold = 0.0 ) 删除所有低方差特征 Variance.fit_transform

【机器学习】PCA

半腔热情 提交于 2019-11-30 13:35:14
目录 PCA 1. PCA最大可分性的思想 2. 基变换(线性变换) 3. 方差 4. 协方差 5. 协方差矩阵 6. 协方差矩阵对角化 7. PCA算法流程 8. PCA算法总结 PCA PCA 就是找出数据最主要的方面,用数据里最主要的方面来代替原始数据。 PCA 是最重要的降维方法之一,在数据压缩、消除冗余和数据噪音消除等领域都有广泛的应用。 1. PCA最大可分性的思想 ​ 最大可分性: 样本点在超平面上的投影尽可能的分开 2. 基变换(线性变换) ​ 欲获得原始数据新的表示空间,最简单方法是对原始数据进行基变换(线性变换)。 3. 方差 ​ 如何选择一个方向或者基才是最优的?基于PCA最大可分思想,我们要找的方向是 降维后损失最小 ,可以理解为 投影后的数据尽可能分得开 ,而分散程度可以用数学上的方差来表示,因为 方差越大数据也就越分散 。 4. 协方差 ​ 在高维变换中,我们希望基变换后选择的各个方向(或者基)是不相关的,这样才能表示更多的信息。数学上使用协方差表示相关性: \[ Cov(a,b) = \frac{1}{m} \sum_{i=1}^{m}a_ib_i \] 如果 \(Cov(a,b)=0\) ,则表示两个字段完全独立,这也是我们的 优化目标 。 5. 协方差矩阵 ​ 我们想达到的 目标( \(Cov(a,b)=0\) ) 与 字段内方差 及 字段间协方差

PCA: How does princomp() work and can I use it to pick up variables for ARIMA?

霸气de小男生 提交于 2019-11-30 13:06:11
问题 I'm trying to use PCA to pick good predictors to use in the xreg argument of an arima model to try to forecast the tVar variable below. I am just using the reduced dataset below with just a few variables to make the example simple. I am trying to understand how the formula argument in princomp works. For the pc object below, is it saying "use xVar1 and xVar2 to explain the variance in na.omit(dfData[,c("tVar","xVar1","xVar2")]) " ? What I ultimately would like to do is create a new variable

PCA + SVM using C++ Syntax in OpenCV 2.2

本小妞迷上赌 提交于 2019-11-30 07:17:41
问题 I'm having problems getting PCA and Eigenfaces working using the latest C++ syntax with the Mat and PCA classes. The older C syntax took an array of IplImage* as a parameter to perform its processing and the current API only takes a Mat that is formatted by Column or Row. I took the Row approach using the reshape function to fit my image's matrix to fit in a single row. I eventually want to take this data and then use the SVM algorithm to perform detection, but when I do that all my data is

PCA: How does princomp() work and can I use it to pick up variables for ARIMA?

不羁岁月 提交于 2019-11-30 05:31:52
I'm trying to use PCA to pick good predictors to use in the xreg argument of an arima model to try to forecast the tVar variable below. I am just using the reduced dataset below with just a few variables to make the example simple. I am trying to understand how the formula argument in princomp works. For the pc object below, is it saying "use xVar1 and xVar2 to explain the variance in na.omit(dfData[,c("tVar","xVar1","xVar2")]) " ? What I ultimately would like to do is create a new variable which explains most of the variance in tVar . Is that something I can do using PCA? If so, could someone

Plot PCA loadings and loading in biplot in sklearn (like R's autoplot)

霸气de小男生 提交于 2019-11-30 05:14:34
I saw this tutorial in R w/ autoplot . They plotted the loadings and loading labels: autoplot(prcomp(df), data = iris, colour = 'Species', loadings = TRUE, loadings.colour = 'blue', loadings.label = TRUE, loadings.label.size = 3) https://cran.r-project.org/web/packages/ggfortify/vignettes/plot_pca.html I prefer Python 3 w/ matplotlib, scikit-learn, and pandas for my data analysis. However, I don't know how to add these on? How can you plot these vectors w/ matplotlib ? I've been reading Recovering features names of explained_variance_ratio_ in PCA with sklearn but haven't figured it out yet

Performing PCA on large sparse matrix by using sklearn

微笑、不失礼 提交于 2019-11-30 03:40:49
I am trying to apply PCA on huge sparse matrix, in the following link it says that randomizedPCA of sklearn can handle sparse matrix of scipy sparse format. Apply PCA on very large sparse matrix However, I always get error. Can someone point out what I am doing wrong. Input matrix 'X_train' contains numbers in float64: >>>type(X_train) <class 'scipy.sparse.csr.csr_matrix'> >>>X_train.shape (2365436, 1617899) >>>X_train.ndim 2 >>>X_train[0] <1x1617899 sparse matrix of type '<type 'numpy.float64'>' with 81 stored elements in Compressed Sparse Row format> I am trying to do: >>>from sklearn

Python3入门机器学习 经典算法与应用(网盘免费分享)

瘦欲@ 提交于 2019-11-30 03:37:42
Python3入门机器学习 经典算法与应用(网盘免费分享) 部分课程学习资料截图: 免费课程资料领取目录: Python Flask构建微信小程序订餐系统 (网盘免费分享) Python分布式爬虫必学框架Scrapy打造搜索引擎(网盘免费分享) Python3实战Spark大数据分析及调度 (网盘免费分享) Python Flask高级编程之RESTFul API前后端分离精讲 (网盘免费分享) 链接:https://pan.baidu.com/s/1rB7h53iNOweyqWTZXQv4cg 提取码:o9el ps:免费分享,如若链接失效请加群( 注意是免费免费免费分享 ) 私聊管理员即可免费领取;群——517432778,点击加群,或扫描二维码 第1章 欢迎来到 Python3 玩转机器学习 欢迎大家来到《Python3玩转机器学习》的课堂。在这个课程中,我们将从0开始,一点一点进入机器学习的世界。本门课程对机器学习领域的学习,绝不不仅仅只是对算法的学习,还包括诸如算法的评价,方法的选择,模型的优化,参数的调整,数据的整理,等等一系列工作。准备好了吗?现在开始我们的机器学习之旅!... 1-1 什么是机器学习 试看 1-2 课程涵盖的内容和理念 试看 1-3 课程所使用的主要技术栈 试看 第2章 机器学习基础 机器学习到底是什么鬼?这一章将带领大家深入理解机器学习的世界