Files
micro_plastic/classification_model/WaveSelect/Pca.py
2026-02-25 09:42:51 +08:00

25 lines
673 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""
-*- 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
@LicenseApache-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_reductionSpectral data after dimensionality reduction
"""
pca = PCA(n_components=nums) # 保留的特征数码
pca.fit(X)
X_reduction = pca.transform(X)
return X_reduction