我试图通过sklearn的PCA (n_components=2)
运行数据,发现最后一行的y值不同于相同输入值的其他值。值得注意的是,输入数据仅包含两个不同的条目,并且当更改条目的出现次数时,错误就会消失。
请找到下面的代码以复制错误。
import pandas as pd
from sklearn.decomposition import PCA
lst1 = [[-0.485886999,0,-0.485886999,-0.485886999,-0.485886999,0,-0.485886999,-0.485886999,-0.485886999,-0.485886999,-0.485886999,0.485886999,-0.485886999,-0.485886999,-0.485886999,-0.485886999]]*7798
lst2 = [[2.0580917,0,2.0580917,2.0580917,2.0580917,0,2.0580917,2.0580917,2.0580917,2.0580917,2.0580917,-2.0580917,2.0580917,2.0580917,2.0580917,2.0580917]]*1841
df_lst1 = pd.DataFrame(lst1)
df_lst2 = pd.DataFrame(lst2)
test = pd.concat([df_lst2, df_lst1], axis=0).reset_index(drop=True)
pca = PCA(n_components=2)
pca.fit(test)
result = pd.DataFrame(pca.transform(test), index=test.index)
print(result)
最后三行的输入(三行相同):
0 1 2 3 4 5 6 ... 9 10 11 12 13 14 15
9636 -0.485887 0 -0.485887 -0.485887 -0.485887 0 -0.485887 ... -0.485887 -0.485887 0.485887 -0.485887 -0.485887 -0.485887 -0.485887
9637 -0.485887 0 -0.485887 -0.485887 -0.485887 0 -0.485887 ... -0.485887 -0.485887 0.485887 -0.485887 -0.485887 -0.485887 -0.485887
9638 -0.485887 0 -0.485887 -0.485887 -0.485887 0 -0.485887 ... -0.485887 -0.485887 0.485887 -0.485887 -0.485887 -0.485887 -0.485887
最后三行的输出:
0 1
9636 -1.818023 1.679370e-17
9637 -1.818023 1.679370e-17
9638 -1.818023 0.000000e+00