我正在执行PCA分析,并获得等于样本数量的组件数量,而不是特征数量。(数据没有标签)
数据在excel中以行:特征、列:样本的形式给出
我转置了数据,然后将X定义为列(特征)
在执行PCA时,我知道PC的数量等于特征的数量,但我没有得到这个。
Python非常新,请原谅我对这些基础知识的无知。
df = pd.read_excel(excel_file)
# STEP 1
# Transposing the data
data = df.T
print('\nData Shape (row, columns):', data.shape)
# STEP 2
# Data preprocessing
# Separating out the features
X = data.iloc[:, 0:4001]
print('\nX shape:', X.shape)
print('X size:', X.size)
# Standardizing the features
X_scaled = StandardScaler().fit_transform(X)
# Dimension reduction
pca = PCA()
X_pca = pca.fit_transform(X_scaled)
print('\nNumber of principal components:', pca.n_components_)
输出:
数据形状(行、列):(1204001)
X形状:(1204001)
X尺寸:480120
主要部件数量:120
谢谢你的帮助!!!