本文整理汇总了Python中sklearn.decomposition.RandomizedPCA方法的典型用法代码示例。如果您正苦于以下问题:Python decomposition.RandomizedPCA方法的具体用法?Python decomposition.RandomizedPCA怎么用?Python decomposition.RandomizedPCA使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sklearn.decomposition
的用法示例。
在下文中一共展示了decomposition.RandomizedPCA方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from sklearn import decomposition [as 别名]
# 或者: from sklearn.decomposition import RandomizedPCA [as 别名]
def __init__(self, k=None, mle_components=False, varfrac=None,
randomize=False, whiten=False):
n_specs = sum(1 for x in [k, mle_components, varfrac] if x)
if n_specs > 1:
msg = "can't specify number of components in more than one way"
raise TypeError(msg)
if n_specs == 0:
varfrac = DEFAULT_VARFRAC
if randomize:
if k is None:
raise TypeError("can't do random PCA without a specific k")
pca = RandomizedPCA(k, whiten=whiten)
else:
if k is not None:
n_components = k
elif mle_components:
n_components = 'mle'
elif varfrac is not None:
n_components = varfrac
pca = PCA(n_components, whiten=whiten)
super(BagPCA, self).__init__(pca)
示例2: test_deprecation_randomized_pca
# 需要导入模块: from sklearn import decomposition [as 别名]
# 或者: from sklearn.decomposition import RandomizedPCA [as 别名]
def test_deprecation_randomized_pca():
rng = np.random.RandomState(0)
X = rng.random_sample((5, 4))
depr_message = ("Class RandomizedPCA is deprecated; RandomizedPCA was "
"deprecated in 0.18 and will be "
"removed in 0.20. Use PCA(svd_solver='randomized') "
"instead. The new implementation DOES NOT store "
"whiten ``components_``. Apply transform to get them.")
def fit_deprecated(X):
global Y
rpca = RandomizedPCA(random_state=0)
Y = rpca.fit_transform(X)
assert_warns_message(DeprecationWarning, depr_message, fit_deprecated, X)
Y_pca = PCA(svd_solver='randomized', random_state=0).fit_transform(X)
assert_array_almost_equal(Y, Y_pca)
示例3: reduce_randomizedPCA
# 需要导入模块: from sklearn import decomposition [as 别名]
# 或者: from sklearn.decomposition import RandomizedPCA [as 别名]
def reduce_randomizedPCA(x):
'''
Reduce the dimensions using Randomized PCA algorithm
'''
# create the CCA object
randomPCA = dc.RandomizedPCA(n_components=2, whiten=True,
copy=False)
# learn the principal components from all the features
return randomPCA.fit(x)
示例4: pca_algorithm
# 需要导入模块: from sklearn import decomposition [as 别名]
# 或者: from sklearn.decomposition import RandomizedPCA [as 别名]
def pca_algorithm(self):
""" Deterimine PCA algorithm to use. """
if self.rotation_algo == 'randomized':
return RandomizedPCA(random_state=self.random_state)
elif self.rotation_algo == 'pca':
return PCA()
else:
raise ValueError("`rotation_algo` must be either "
"'pca' or 'randomized'.")