pca

How to create a biplot with FactoMineR?

假装没事ソ 提交于 2019-12-11 02:15:04
问题 The Question is easy. I'd like to biplot the results of PCA(mydata), which I did with FactoMineR. As it seems I can only display ether the variables or the individuals with the built in ploting device: plot.PCA(pca1, choix="ind/var"). I know it can be easily done with the result of princomp(), but I really like how FactoMineR handles the NA's and it seems easier to me in many ways. Is there a way? I saw it somehow done with ggplot2 but again only with the result of princomp(), and I have no

Why Sklearn PCA needs more samples than new features(n_components)?

淺唱寂寞╮ 提交于 2019-12-10 21:07:59
问题 When using Sklearn PCA algorithm like this x_orig = np.random.choice([0,1],(4,25),replace = True) pca = PCA(n_components=15) pca.fit_transform(x_orig).shape I get output (4, 4) I expected(want) it to be: (4,15) I get why its happening. In the documentation of sklearn (here) it says(assuming their '==' is assignment operator): n_components == min(n_samples, n_features) But why are they doing this? Also, how can I convert an input with shape [1,25] to [1,10] directly (without stacking dummy

Principal Component Analysis with Caret

放肆的年华 提交于 2019-12-10 19:54:02
问题 I'm using Caret's PCI preprocessing. multinomFit <- train(LoanStatus~., train, method = "multinom", std=TRUE, family=binomial, metric = "ROC", thresh = 0.85, verbose = TRUE, pcaComp=7, preProcess=c("center", "scale", "pca"), trControl = ctrl) I specified, the number of PCA Components to be 7. Why does the summary show the fit using 68 components? summary(multinomFit) Call: multinom(formula = .outcome ~ ., data = dat, decay = param$decay, std = TRUE, family = ..2, thresh = 0.85, verbose = TRUE

Dimensionality reduction in HOG feature vector

蓝咒 提交于 2019-12-10 10:54:25
问题 I found out the HOG feature vector of the following image in MATLAB. Input Image I used the following code. I = imread('input.jpg'); I = rgb2gray(I); [features, visualization] = extractHOGFeatures(I,'CellSize',[16 16]); features comes out to be a 1x1944 vector and I need to reduce the dimensionality of this vector (say to 1x100 ), what method should I employ for the same? I thought of Principal Component Analysis and ran the following in MATLAB. prinvec = pca(features); prinvec comes out to

主成分分析(PCA)原理详解

我的未来我决定 提交于 2019-12-10 10:07:52
个人分类: 机器学习与Python 版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/zhongkelee/article/details/44064401 转载请声明出处: http://blog.csdn.net/zhongkelee/article/details/44064401 一、PCA简介 1. 相关背景 上完陈恩红老师的《机器学习与知识发现》和季海波老师的《矩阵代数》两门课之后,颇有体会。最近在做主成分分析和奇异值分解方面的项目,所以记录一下心得体会。 在许多领域的研究与应用中,往往需要对反映事物的多个变量进行大量的观测,收集大量数据以便进行分析寻找规律。多变量大样本无疑会为研究和应用提供了丰富的信息,但也在一定程度上增加了数据采集的工作量,更重要的是在多数情况下,许多变量之间可能存在相关性,从而增加了问题分析的复杂性,同时对分析带来不便。如果分别对每个指标进行分析,分析往往是孤立的,而不是综合的。盲目减少指标会损失很多信息,容易产生错误的结论。 因此需要找到一个合理的方法,在减少需要分析的指标同时,尽量减少原指标包含信息的损失,以达到对所收集数据进行全面分析的目的。由于各变量间存在一定的相关关系,因此有可能用较少的综合指标分别综合存在于各变量中的各类信息。主成分分析与因子分析就属于这类降维的方法。 2. 问题描述

机器学习(十)数据降维(PCA与LDA)

会有一股神秘感。 提交于 2019-12-10 08:29:16
机器学习(十) 数据降维(此处讲PCA与LDA) 背景: 在许多领域的研究与应用中,通常需要对含有多个变量的数据进行观测,收集大量数据后进行分析寻找规律。多变量大数据集无疑会为研究和应用提供丰富的信息,但是也在一定程度上增加了数据采集的工作量。更重要的是在很多情形下,许多变量之间可能存在相关性,从而增加了问题分析的复杂性。如果分别对每个指标进行分析,分析往往是孤立的,不能完全利用数据中的信息,因此盲目减少指标会损失很多有用的信息,从而产生错误的结论。 因此需要找到一种合理的方法,在减少需要分析的指标同时,尽量减少原指标包含信息的损失,以达到对所收集数据进行全面分析的目的。由于各变量之间存在一定的相关关系,因此可以考虑将关系紧密的变量变成尽可能少的新变量,使这些新变量是两两不相关的,那么就可以用较少的综合指标分别代表存在于各个变量中的各类信息。主成分分析与因子分析就属于这类降维算法。 简介: 降维就是一种对高维度特征数据预处理方法。降维是将高维度的数据保留下最重要的一些特征,去除噪声和不重要的特征,从而实现提升数据处理速度的目的。在实际的生产和应用中,降维在一定的信息损失范围内,可以为我们节省大量的时间和成本。降维也成为应用非常广泛的数据预处理方法。 降维具有如下一些优点: 使得数据集更易使用。 降低算法的计算开销。 去除噪声。 使得结果容易理解。 PCA PCA概念: PCA

Face recognition - Python

感情迁移 提交于 2019-12-10 06:49:39
问题 I am trying to make face recognition by Principal Component Analysis (PCA) using python. Now I am able to get the minimum euclidean distance between the training images images and the input image input_image . Here is my code: import os from PIL import Image import numpy as np import glob import numpy.linalg as linalg #Step1: put database images into a 2D array filenames = glob.glob('C:\\Users\\me\\Downloads\\/*.pgm') filenames.sort() img = [Image.open(fn).convert('L').resize((90, 90)) for fn

主成分分析(PCA)原理总结

穿精又带淫゛_ 提交于 2019-12-10 04:13:48
    主成分分析(Principal components analysis,以下简称PCA)是最重要的降维方法之一。在数据压缩消除冗余和数据噪音消除等领域都有广泛的应用。一般我们提到降维最容易想到的算法就是PCA,下面我们就对PCA的原理做一个总结。 1. PCA的思想     PCA顾名思义,就是找出数据里最主要的方面,用数据里最主要的方面来代替原始数据。具体的,假如我们的数据集是n维的,共有m个数据$(x^{(1)},x^{(2)},...,x^{(m)})$。我们希望将这m个数据的维度从n维降到n'维,希望这m个n'维的数据集尽可能的代表原始数据集。我们知道数据从n维降到n'维肯定会有损失,但是我们希望损失尽可能的小。那么如何让这n'维的数据尽可能表示原来的数据呢?     我们先看看最简单的情况,也就是n=2,n'=1,也就是将数据从二维降维到一维。数据如下图。我们希望找到某一个维度方向,它可以代表这两个维度的数据。图中列了两个向量方向,$u_1$和$u_2$,那么哪个向量可以更好的代表原始数据集呢?从直观上也可以看出,$u_1$比$u_2$好。     为什么$u_1$比$u_2$好呢?可以有两种解释,第一种解释是样本点到这个直线的距离足够近,第二种解释是样本点在这个直线上的投影能尽可能的分开。     假如我们把n'从1维推广到任意维,则我们的希望降维的标准为

Omit NA and data imputation before doing PCA analysis using R

陌路散爱 提交于 2019-12-09 20:14:36
问题 I am trying to do PCA analysis using princomp function in R. The following is the example code: mydf <- data.frame ( A = c("NA", rnorm(10, 4, 5)), B = c("NA", rnorm(9, 4, 5), "NA"), C = c("NA", "NA", rnorm(8, 4, 5), "NA") ) out <- princomp(mydf, cor = TRUE, na.action=na.exclude) Error in cov.wt(z) : 'x' must contain finite values only I tried to remove the NA from the dataset, but it does not work. ndnew <- mydf[complete.cases(mydf),] A B C 1 NA NA NA 2 1.67558617743171 1.28714736288378 NA 3

Pass PCA preprocessing arguments to train()

℡╲_俬逩灬. 提交于 2019-12-09 08:58:59
问题 I'm trying to build a predictive model in caret using PCA as pre-processing. The pre-processing would be as follows: preProc <- preProcess(IL_train[,-1], method="pca", thresh = 0.8) Is it possible to pass the thresh argument directly to caret's train() function? I've tried the following, but it doesn't work: modelFit_pp <- train(IL_train$diagnosis ~ . , preProcess="pca", thresh= 0.8, method="glm", data=IL_train) If not, how can I pass the separate preProc results to the train() function? 回答1: