pca

Change loadings (arrows) length in PCA plot using ggplot2/ggfortify?

心已入冬 提交于 2019-12-21 16:22:48
问题 I have been struggling with rescaling the loadings (arrows) length in a ggplot2/ggfortify PCA. I have looked around extensively for an answer to this, and the only information I have found either code new biplot functions or refer to other entirely different packages for PCA (ggbiplot, factoextra), neither of which address the question I would like to answer: Is it possible to scale/change size of PCA loadings in ggfortify? Below is the code I have to plot a PCA using stock R functions as

Sklearn PCA is pca.components_ the loadings?

拜拜、爱过 提交于 2019-12-21 04:25:21
问题 Sklearn PCA is pca.components_ the loadings? I am pretty sure it is, but I am trying to follow along a research paper and I am getting different results from their loadings. I can't find it within the sklearn documentation. 回答1: pca.components_ is the orthogonal basis of the space your projecting the data into. It has shape (n_components, n_features) . If you want to keep the only the first 3 components (for instance to do a 3D scatter plot) of a datasets with 100 samples and 50 dimensions

OpenCV中PCA实现人脸降维

北城以北 提交于 2019-12-20 20:38:37
   前言:   PCA 是大家经常用来减少数据集的维数,同时保留数据集中对方差贡献最大的特征来达到简化数据集的目的。本文通过使用 PCA 来提取人脸中的特征脸这个例子,来熟悉下在 oepncv 中怎样使用 PCA 这个类。    开发环境: ubuntu12.04+Qt4.8.2+QtCreator2.5.1+opencv2.4.2    PCA 数学理论:    关于 PCA 的理论,资料很多,公式也一大把,本人功底有限,理论方面这里就不列出了。下面主要从应用的角度大概来讲讲具体怎么实现数据集的降维。 把原始数据中每个样本用一个向量表示,然后把所有样本组合起来构成一个矩阵。当然了,为了避免样本的单位的影响,样本集需要标准化。 求该矩阵的协防差矩阵(关于协方差的介绍可以参考我的博文: 一些知识点的初步理解 _4( 协方差矩阵 ,ing...) )。 求步骤 2 中得到的协方差矩阵的特征值和特征向量。 将求出的特征向量按照特征值的大小进行组合形成一个映射矩阵,并根据指定的 PCA 保留的特征个数取出映射矩阵的前 n 行或者前 n 列作为最终的映射矩阵。 用步骤 4 的映射矩阵对原始数据进行映射,达到数据降维的目的。    实验说明:    在本次实验实现的过程中,需要用到 opencv 的这些函数,下面简单介绍下这些函数。    Mat Mat:: reshape (int cn,

Using Numpy (np.linalg.svd) for Singular Value Decomposition

孤人 提交于 2019-12-20 11:49:32
问题 Im reading Abdi & Williams (2010) "Principal Component Analysis", and I'm trying to redo the SVD to attain values for further PCA. The article states that following SVD: X = P D Q^t I load my data in a np.array X. X = np.array(data) P, D, Q = np.linalg.svd(X, full_matrices=False) D = np.diag(D) But i do not get the above equality when checking with X_a = np.dot(np.dot(P, D), Q.T) X_a and X are the same dimensions, but the values are not the same. Am I missing something, or is the

Principal component analysis (PCA) of time series data: spatial and temporal pattern

我只是一个虾纸丫 提交于 2019-12-20 09:43:52
问题 Suppose I have yearly precipitation data for 100 stations from 1951 to 1980. In some papers, I find people apply PCA to the time series and then plot the spatial loadings map (with values from -1 to 1), and also plot the time series of the PCs. For example, figure 6 in https://publicaciones.unirioja.es/ojs/index.php/cig/article/view/2931/2696 is the spatial distribution of the PCs. I am using function prcomp in R and I wonder how I can do the same thing. In other words, how can I extract the

How to use scikit-learn PCA for features reduction and know which features are discarded

安稳与你 提交于 2019-12-20 08:49:22
问题 I am trying to run a PCA on a matrix of dimensions m x n where m is the number of features and n the number of samples. Suppose I want to preserve the nf features with the maximum variance. With scikit-learn I am able to do it in this way: from sklearn.decomposition import PCA nf = 100 pca = PCA(n_components=nf) # X is the matrix transposed (n samples on the rows, m features on the columns) pca.fit(X) X_new = pca.transform(X) Now, I get a new matrix X_new that has a shape of n x nf. Is it

How to plot a circle for each point scatter plot while each has particular radius size

爱⌒轻易说出口 提交于 2019-12-20 05:55:53
问题 I have a pandas frame with distance matrix, I use PCA to do the dim reduction. The the dataframe of this distance matrix has label for each point, and size. How can I make each scattered point become a circle with a size dependent on the size from the dataframe ```` pca = PCA(n_components=2) pca.fit(dist) mds5 = pca.components_ fig = go.Figure() fig.add_scatter(x = mds5[0], y = mds5[1], mode = 'markers+text', marker= dict(size = 8, color= 'blue' ), text= dist.columns.values, textposition='top

psych::principal - explanation for the order and naming of rotated (principal) components

被刻印的时光 ゝ 提交于 2019-12-20 02:38:11
问题 Let x be a sample dataframe. set.seed(0) x <- replicate(4, rnorm(10)) A PCA using the principal function from the psych package will yield: > principal(x, nf=4, rotate="none") ... PC1 PC2 PC3 PC4 SS loadings 1.91 1.09 0.68 0.31 Proportion Var 0.48 0.27 0.17 0.08 Cumulative Var 0.48 0.75 0.92 1.00 Proportion Explained 0.48 0.27 0.17 0.08 Cumulative Proportion 0.48 0.75 0.92 1.00 Rotating te PCA solution using the varimax criterion yields new components now named RCi to indicate that the PCs

Plot a Correlation Circle in Python

百般思念 提交于 2019-12-20 01:43:33
问题 I've been doing some Geometrical Data Analysis (GDA) such as Principal Component Analysis (PCA). I'm looking to plot a Correlation Circle... these look a bit like this: Basically, it allows to measure to which extend the Eigenvalue / Eigenvector of a variable is correlated to the principal components (dimensions) of a dataset. Anyone knows if there is a python package that plots such data visualization? 回答1: I agree it's a pity not to have it in some mainstream package such as sklearn. Here

PCA图像转正C++

拜拜、爱过 提交于 2019-12-20 00:11:03
PCA图像转正C++ 文章目录 PCA图像转正C++ MaskRotation.h MaskRotation.cpp MaskRotation.h // // Created by surui on 2019/12/17. // # ifndef IDEATRAINER_MASKROTATION_H # define IDEATRAINER_MASKROTATION_H # include <opencv2/opencv.hpp> using namespace cv ; using namespace std ; # define PI acos(-1) class MaskRotation { public : /** * input mask foreground pixels' value is 255 * @param mask * @param points */ static void getAllForeGroundPoints ( Mat mask , Mat & points ) ; /** * pca fit data * @param Points * @return angle */ static float pca ( const Mat & Points ) ; /** * rotate mask to upright by pca's angle *