本文整理汇总了Python中sklearn.decomposition.PCA.dot方法的典型用法代码示例。如果您正苦于以下问题:Python PCA.dot方法的具体用法?Python PCA.dot怎么用?Python PCA.dot使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sklearn.decomposition.PCA
的用法示例。
在下文中一共展示了PCA.dot方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: reduit_dim
# 需要导入模块: from sklearn.decomposition import PCA [as 别名]
# 或者: from sklearn.decomposition.PCA import dot [as 别名]
def reduit_dim(X, Distances = None,nouv_dim = 2, rapport = identité, frottements = 0.95, nb_iter = 50, seuil_var = 0.05, distance_souhaitée=saut_a_4):
n,p = np.shape(X)
restant = 1 - frottements
restant /= n
if Distances == None:
Distances = X.dot(X.T)
Di = np.reshape(np.diag(Distances),(n,1))
Ai = Di.dot(np.ones((1,n)))
Distances = Ai + Ai.T - 2*Distances
Distances = np.sqrt(Distances)
# return (Distances)
X_ACP = X
# # #
# On veut ces distances :
Distances = distance_souhaitée(Distances)
# return (Distances)
# # #
while p > nouv_dim:
# Combien de dimensions va-t'on supprimer ? i+1 (de sorte qu'on supprime moins de seuil_var de l'énergie)
acp = PCA(n_components=p)
acp.fit(X)
sigmas = acp.explained_variance_ratio_[::-1]
var = sigmas[0]
i = 0
while (nouv_dim+i+1) <= p and var + sigmas[i+1] < seuil_var:
var += sigmas[i+1]
i += 1
p -= i+1
print(p)
X_ACP = PCA(n_components=p).fit_transform(X_ACP)
# acp = PCA(n_components=p).fit(X_ACP).components_
# print(X_ACP)
# Le vecteur des vitesses :
V = np.zeros((n,p))
for k in range(nb_iter):
nouv_Distances = X_ACP.dot(X_ACP.T)
Di = np.reshape(np.diag(nouv_Distances),(n,1))
Ai = Di.dot(np.ones((1,n)))
nouv_Distances = Ai + Ai.T - 2*nouv_Distances
nouv_Distances = np.sqrt(nouv_Distances)
Diff = nouv_Distances - Distances
# print(X_ACP)
# print(k, Diff)
if k == 0:
print('k = 0')
print(Diff)
if k == (nb_iter-1):
print('k = nb_iter-1')
print(Diff)
for i in range(n):
for j in range(n):
d = X_ACP[j] - X_ACP[i]
# La vitesse change de l'accélération (somme des forces)
c = d * rapport(Diff[i,j])
V[i] += c
for i in range(n):
V[i] *= restant
X_ACP[i] += V[i]
return X_ACP