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


Python PCA.partial_fit方法代码示例

本文整理汇总了Python中sklearn.decomposition.PCA.partial_fit方法的典型用法代码示例。如果您正苦于以下问题:Python PCA.partial_fit方法的具体用法?Python PCA.partial_fit怎么用?Python PCA.partial_fit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sklearn.decomposition.PCA的用法示例。


在下文中一共展示了PCA.partial_fit方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: pca_opt

# 需要导入模块: from sklearn.decomposition import PCA [as 别名]
# 或者: from sklearn.decomposition.PCA import partial_fit [as 别名]
    def pca_opt(sparseArray, pcaModel=None, svdopt=None):
        array = sparseArray.toarray()
        if pcaModel is None:
            if svdopt is not None:
                ReadData.svdOpt = svdopt
            print (ReadData.svdOpt)
            newSize = len(array[0]) / ReadData.svdOpt
            print(newSize)
            if len(array) < 3000:
                pca = PCA(n_components=newSize)
                Xtransformed = pca.fit_transform(array)
                Xtransformed = sparse.csr_matrix(Xtransformed)
            else:
                chunkSize = 20
                iter = int(len(array)/chunkSize)
                chunks = [array[i:i + chunkSize] for i in range(0, iter*chunkSize, chunkSize)]
                pca = IncrementalPCA(n_components=newSize)

                for chunk in chunks:
                    pca.partial_fit(chunk)

                Xtransformed = None
                for chunk in chunks:
                    Xchunk = pca.transform(chunk)
                    if Xtransformed == None:
                        Xtransformed = Xchunk
                    else:
                        Xtransformed = np.vstack((Xtransformed, Xchunk))
                Xtransformed = sparse.csr_matrix(Xtransformed)

            return pca, Xtransformed
        else:
            if len(array) < 2900:
                Xtransformed = pcaModel.transform(array)
                Xtransformed = sparse.csr_matrix(Xtransformed)
            else:
                chunkSize = 2000
                chunks = [array[i:i + chunkSize] for i in range(0, len(array), chunkSize)]

                Xtransformed = None
                for chunk in chunks:
                    Xchunk = pcaModel.transform(chunk)
                    if Xtransformed == None:
                        Xtransformed = Xchunk
                    else:
                        Xtransformed = np.vstack((Xtransformed, Xchunk))
                Xtransformed = sparse.csr_matrix(Xtransformed)

            return pcaModel, Xtransformed
开发者ID:jacek6,项目名称:sas2015,代码行数:51,代码来源:read_data.py


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