25 lines
673 B
Python
25 lines
673 B
Python
|
|
"""
|
|||
|
|
-*- coding: utf-8 -*-
|
|||
|
|
@Time :2022/04/12 17:10
|
|||
|
|
@Author : Pengyou FU
|
|||
|
|
@blogs : https://blog.csdn.net/Echo_Code?spm=1000.2115.3001.5343
|
|||
|
|
@github : https://github.com/FuSiry/OpenSA
|
|||
|
|
@WeChat : Fu_siry
|
|||
|
|
@License:Apache-2.0 license
|
|||
|
|
|
|||
|
|
"""
|
|||
|
|
|
|||
|
|
from sklearn.decomposition import PCA
|
|||
|
|
|
|||
|
|
def Pca(X, nums=20):
|
|||
|
|
"""
|
|||
|
|
:param X: raw spectrum data, shape (n_samples, n_features)
|
|||
|
|
:param nums: Number of principal components retained
|
|||
|
|
:return: X_reduction:Spectral data after dimensionality reduction
|
|||
|
|
"""
|
|||
|
|
pca = PCA(n_components=nums) # 保留的特征数码
|
|||
|
|
pca.fit(X)
|
|||
|
|
X_reduction = pca.transform(X)
|
|||
|
|
|
|||
|
|
return X_reduction
|