coding=utf-8
“”"
author:lei 5
function: 特征选择
“”"
from sklearn.feature_selection import VarianceThreshold # 特征选择
from sklearn.decomposition import PCA
num_list = [[0, 2, 0, 3], [0, 1, 4, 3], [0, 1, 1, 3]]
def var():
“”"
特征选择-删除低方差特征
:return:
“”"
var = VarianceThreshold(threshold=1.0)
data = var.fit_transform(num_list)
print(data)
return None
def pca():
“”"
主成分分析进行特征降维
:return:
“”"
pca = PCA(n_components=0.9)
data = pca.fit_transform(num_list)
print(data)
return None
if name == ‘main’:
# var()
pca()