当前位置:网站首页>sklearn笔记:PCA
sklearn笔记:PCA
2022-08-05 14:17:00 【UQI-LIUWJ】
0 理论知识
1 基本使用方法
class sklearn.decomposition.PCA(
n_components=None,
*,
copy=True,
whiten=False,
svd_solver='auto',
tol=0.0,
iterated_power='auto',
n_oversamples=10,
power_iteration_normalizer='auto',
random_state=None)2 参数说明
| n_components | 降至几维【特征的数量】(如果n_components没有配置的话,保持维度) |
| whiten | 是否进行白化操作【使得特征互相独立,且在[0,1]区间内】 |
3 属性说明
| components_ | |
4 举例说明
4.1 导入库&数据集
import numpy as np
from sklearn.decomposition import PCA
X = np.array([[-1,-1,1,1],
[-2,-1,5,6],
[-3,-2,4,6],
[1,1,9,7],
[2,1,0,1],
[3,2,9,12]])4.2 生成PCA
pca=PCA(n_components=2).fit(X)4.3 components_
PCA的几个主轴
pca.components_
'''
array([[ 0.16382179, 0.14340848, 0.66107511, 0.7180363 ],
[ 0.83556307, 0.50546848, -0.13218006, -0.16989525]])
'''4.4 explained_variance_ & explained_variance_ratio_
每个主轴方差在总体中的占比。
个人理解为,每个主轴的重要性占比。这个对判断我们n_component_比较有用。
比如我们一开始设置n_component_为3,那么:
pca=PCA(n_components=3).fit(X)
pca.explained_variance_
#array([31.51576789, 6.79717077, 1.44075915]
pca.explained_variance_ratio_
#array([0.79251721, 0.17092634, 0.03623032])可以看到第三个主轴的方差占比很低,所以我们可以只用两个主轴即可。
pca=PCA(n_components=2).fit(X)
pca.explained_variance_
#array([31.51576789, 6.79717077])
pca.explained_variance_ratio_
#array([0.79251721, 0.17092634])4.5 singular_values_
每一个主轴对应的特征值
pca.singular_values_
#array([12.55304104, 5.82973874])4.6 其他attribute
| mean_ | 就是相当于X.mean(axis=0)![]() |
| n_components_ | 主轴个数
|
| n_features_ | 特征个数
|
4.6 函数
fit,fit_transform,transform
边栏推荐
- [CUDA study notes] What is GPU computing
- Capacity upgrade helps computing power flow, the acceleration moment of China's digital economy
- 特种期货开户交易权限开通认定标准
- npm install时卡在sill idealTree buildDeps
- LeetCode每日一题(1706. Where Will the Ball Fall)
- ByteDance Flink Status Query Practice and Optimization
- 虚寒需要注意
- 使用 Redis 源码编译发布 Windows 版 Redis For Windows 发行包
- ‘proxy‘ config is set properly,see“npm help config“
- 荆棘与玫瑰:基础服务架构师的成⻓之路PPT
猜你喜欢

Subnet Mask and Subnetting

mmap内核实现及物理内存组织结构

day13·魔术方法__ call__与__del__

当天期货开户次日就可以交易
![[CUDA study notes] What is GPU computing](/img/20/6c68dbba66904b58a20c143c0f576d.png)
[CUDA study notes] What is GPU computing

vscode背景调整

c语言小项目(排雷游戏实现)

期货开户公司的选择和作用
Docker study notes - cluster deployment based on example projects (5) Docker builds MySQL cluster | PXC cluster

使用 Redis 源码编译发布 Windows 版 Redis For Windows 发行包
随机推荐
Steps to update data to database and cache
R语言ggplot2可视化:使用ggpubr包的ggsummarytable函数可视化dataframe数据的描述性统计量、ggtheme参数设置可视化图像使用的主题
PC端浏览器兼容
DSPE-PEG-Thiol,DSPE-PEG-SH(MV:2000),磷脂-聚乙二醇-巯基低温储存
【Search box】General test case
获取淘宝/天猫购买到商品的订单详情——buyer_order_detail
mmap内核实现及物理内存组织结构
day5·全局与局部变量
深度学习之 11 空洞卷积的实现
Redis5.0的安装和配置
【Endnote】插入文献时,自动弹出select matching reference
OpenHarmony Pixel Unit (eTS)
fmincon函数 源代码
IIoT系统架构
用友U8各版本操作系统是数据库支持情况
Use Redis source code to compile and release Redis For Windows distribution package for Windows
Memory Management Architecture and Virtual Address Space Layout
理财产品是只能看到本金看不到收益吗?
day8·函数封装
十分钟教会你如何使用VitePress搭建及部署个人博客站点


