pca

机器学习:数据清洗和特征选择

孤街醉人 提交于 2019-12-06 07:01:23
数据清洗和特征选择 数据清洗 清洗过程 数据预处理: 选择数据处理工具:数据库、Python相应的包; 查看数据的元数据及数据特征; 清理异常样本数据: 处理格式或者内容错误的数据; 处理逻辑错误数据:数据去重,去除/替换不合理的值,去除/重构不可靠的字段值; 处理不需要的数据:在进行该过程时,要注意备份原始数据; 处理关联性验证错误的数据:常应用于多数据源合并的过程中。 采样: 数据不均衡处理:上采样、下采样、SMOTE算法 样本的权重问题 数据不平衡 在实际应用中,数据的分布往往是不均匀的,会出现"长尾现象",即绝大多数的数据在一个范围/属于一个类别,而在另外一个范围或者类别中,只有很少一部分数据。此时直接采用机器学习效果不会很好,因此需要对数据进行转换操作。 长尾效应: 解决方案01 设置损失函数的权重, 使得少数类别数据判断错误的损失大于多数类别数据判断错误的损失 ,即:当我们的少数类别数据预测错误的时候,会产生一个比较大的损失值,从而导致模型参数往让少数类别数据预测准确的方向偏。 可通过设置sklearn中的class_weight参数来设置权重。 解决方案02 下采样/欠采样(under sampling): 从多数类中随机抽取样本从而减少多数类别样本数据 ,使数据达到平衡的方式。 集成下采样/欠采样:采用普通的下采样方式会导致信息丢失

[转载]什么是白化(whitening)?

送分小仙女□ 提交于 2019-12-06 05:24:49
[转载]什么是白化(whitening)? 来源: https://blog.csdn.net/hjimce/article/details/50864602 白化whitening 原文地址: http://blog.csdn.net/hjimce/article/details/50864602 作者:hjimce 一、相关理论 白化这个词,可能在深度学习领域比较常遇到,挺起来就是高大上的名词,然而其实白化是一个比PCA稍微高级一点的算法而已,所以如果熟悉PCA,那么其实会发现这是一个非常简单的算法。 白化的目的是去除输入数据的冗余信息。假设训练数据是图像,由于图像中相邻像素之间具有很强的相关性,所以用于训练时输入是冗余的;白化的目的就是降低输入的冗余性。 输入数据集X,经过白化处理后,新的数据X'满足两个性质: (1)特征之间相关性较低; (2)所有特征具有相同的方差。 其实我们之前学的PCA算法中,可能PCA给我们的印象是一般用于降维操作。然而其实PCA如果不降维,而是仅仅使用PCA求出特征向量,然后把数据X映射到新的特征空间,这样的一个映射过程,其实就是满足了我们白化的第一个性质:除去特征之间的相关性。因此白化算法的实现过程,第一步操作就是PCA,求出新特征空间中X的新坐标,然后再对新的坐标进行方差归一化操作。 二、算法概述 白化分为PCA白化、ZCA白化

PCA(主成分分析)方法浅析

自闭症网瘾萝莉.ら 提交于 2019-12-06 05:23:45
PCA(主成分分析)方法浅析 降维、数据压缩 找到数据中最重要的方向:方差最大的方向,也就是样本间差距最显著的方向 在与第一个正交的超平面上找最合适的第二个方向 PCA算法流程 上图第一步描述不正确,应该是去中心化,而不是中心化 具体来说,投影这一环节就是:将与特征值对应的k个特征向量分别作为行向量组成特征向量矩阵P 直接乘以特征变量就好。原来是二维数据,降维之后只有一维。 我们想保留几个维度的特征,就留下几个特征值和对应的特征向量。 来源: https://www.cnblogs.com/jiading/p/11963861.html

Principal Component Analysis on Weka

笑着哭i 提交于 2019-12-06 04:55:36
问题 I have just computed PCA on a training set and Weka returned me the new attributes with the way in which they were selected and computed. Now, I want to build a model using these data and then use the model on a test set. Do you know if there is a way to automatically modify the test set according to the new type of attributes? 回答1: Do you need the principal components for analysis or just to feed into the classifier? If not just use the Meta->FilteredClassifier classifier. Set the filter to

How to programmatically determine the column indices of principal components using FactoMineR package?

ぃ、小莉子 提交于 2019-12-06 03:40:17
问题 Given a data frame containing mixed variables (i.e. both categorical and continuous) like, digits = 0:9 # set seed for reproducibility set.seed(17) # function to create random string createRandString <- function(n = 5000) { a <- do.call(paste0, replicate(5, sample(LETTERS, n, TRUE), FALSE)) paste0(a, sprintf("%04d", sample(9999, n, TRUE)), sample(LETTERS, n, TRUE)) } df <- data.frame(ID=c(1:10), name=sample(letters[1:10]), studLoc=sample(createRandString(10)), finalmark=sample(c(0:100),10),

Using PCA on linear regression

怎甘沉沦 提交于 2019-12-05 23:36:31
I want to use principal component analysis to reduce some noise before applying linear regression. I have 1000 samples and 200 features import numpy as np from sklearn.linear_model import LinearRegression from sklearn.decomposition import PCA X = np.random.rand(1000,200) y = np.random.rand(1000,1) With this data I can train my model: model.fit(X,y) But if I try the same after applying PCA pca = PCA(n_components=8) pca.fit(X) PCA(copy=True, iterated_power='auto', n_components=3, random_state=None, svd_solver='auto', tol=0.0, whiten=False) principal_components = pca.components_ model.fit

How to calculate the volume of the intersection of ellipses in r

送分小仙女□ 提交于 2019-12-05 22:03:34
I was wondering how to calculate the intersection between two ellipses e.g. the volume of the intersection between versicolor and virginca as illustrated in this graph: which is plotted using the following mwe based on this tutorial : data(iris) log.ir <- log(iris[, 1:4]) ir.species <- iris[, 5] ir.pca <- prcomp(log.ir, center = TRUE, scale. = TRUE) library(ggbiplot) g <- ggbiplot(ir.pca, obs.scale = 1, var.scale = 1, groups = ir.species, ellipse = TRUE, circle = TRUE) g <- g + scale_color_discrete(name = '') g <- g + theme(legend.direction = 'horizontal', legend.position = 'top') print(g) I

《机学三》特征工程3 —— 特征选择:特征选择、数据降维

此生再无相见时 提交于 2019-12-05 19:07:13
一、概述 1.1【降维】 【维降】:把三维降成二维,本质就是减少特征数量; 1.2【特征选择】 什么是特征选择: 特征选择就是单纯地从提取到的所有特征中选择部分特征作为训练集特征,特征在选择前和选择后可以改变值、也不改变值,但是选择后的特征维数肯定比选择前小,毕竟我们只选择了其中的一部分特征。 为什么要进行特征选择: 冗余:部分特征的相关度高,容易消耗计算性能 噪声:部分特征对预测结果有负影响 相同的特征值:比如亚洲人肤色都是黄色,这就没意义。 冗余的特征 没用的特征 主要方法(三大武器):前2种主要方式 *Filter(过滤式):VarianceThreshold(方差阈值),计算特征值方差,得出其值[是否一样]或[差距大小] 【方差公式】 :一组数据中的各个数减这组数据的平均数的平方和的平均数,公式为(mean即平均数): \[var=\frac{(x1- mean)^{2}+(x2- mean)^{2}+...}{n(每个特征的样本数)}\] 【简单说】,方差(每一列每个数-这列的平均数)^2/这列数的个数 【目的】删除低方差的特征列 *Embedded(嵌入式):正则化、决策树 Wrapper(包裹式) 其它方法:神经网络(以后介绍) 二、特征选择实战之:方差阈值VarianceThreshold 2.1 方差阈值sklearnAPI:VarianceThreshold

Face recognition - Python

為{幸葍}努か 提交于 2019-12-05 18:20:43
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 in filenames] images = np.asarray([np.array(im).flatten() for im in img]) #Step 2: find the mean image

PCA

梦想与她 提交于 2019-12-05 16:16:04
对影像进行主成分分析,只有第一主成分被分离出来了,后面的主成分好像都相同 均值: 标准差: 方差: 描述数据之间关系的统计量 标准差和方差一般是用来描述一维数据的,但现实生活我们常常遇到含有多维数据的数据集。 面对这样的数据集,我们当然可以按照每一维独立的计算其方差,但是通常我们还想了解这几科成绩之间的关系,这时,我们就要用协方差,协方差就是一种用来度量两个随机变量关系的统计量 1.正向主成分(PC)旋转 正向PC旋转用一个线性变换使数据方差达到最大。当使用正向PC旋转时,ENVI允许计算新的统计值,或根据已经存在的统计值进行旋转。输出值可以存为字节型、浮点型、整型、长整型或双精度型。也可以基于特征值来提取PC旋转的输出内容,生成只包含所需的PC波段的输出。 计算新的统计值和旋转 使用Compute New Statistics and Rotate选项可以计算数据特征值、协方差或相关系数矩阵以及PC正向旋转。 选择Transforms > Principal Components > Forward PC Rotation > Compute New Statistics and Rotate。 当出现Principal Components Input File对话框时,选择输入文件或用标准ENVI选择程序选取子集。将会出现Forward PC Rotation