当前位置: 首页>>代码示例>>Python>>正文


Python PCA.dot方法代码示例

本文整理汇总了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
开发者ID:HauLou,项目名称:Stylometrie,代码行数:71,代码来源:propre_TSNE.py


注:本文中的sklearn.decomposition.PCA.dot方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。