本文整理汇总了Python中sklearn.decomposition.PCA.reduced_space方法的典型用法代码示例。如果您正苦于以下问题:Python PCA.reduced_space方法的具体用法?Python PCA.reduced_space怎么用?Python PCA.reduced_space使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sklearn.decomposition.PCA
的用法示例。
在下文中一共展示了PCA.reduced_space方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_init
# 需要导入模块: from sklearn.decomposition import PCA [as 别名]
# 或者: from sklearn.decomposition.PCA import reduced_space [as 别名]
def test_init(self, df_norm, n_components):
from flotilla.compute.decomposition import DataFramePCA
test_pca = DataFramePCA(df_norm, n_components=n_components)
true_pca = PCA(n_components=n_components)
true_pca.fit(df_norm.values)
pc_names = ['pc_{}'.format(i + 1) for i in
range(true_pca.components_.shape[0])]
true_pca.components_ = pd.DataFrame(true_pca.components_,
index=pc_names,
columns=df_norm.columns)
true_pca.explained_variance_ = pd.Series(
true_pca.explained_variance_, index=pc_names)
true_pca.explained_variance_ratio_ = pd.Series(
true_pca.explained_variance_ratio_, index=pc_names)
true_pca.reduced_space = true_pca.transform(df_norm.values)
true_pca.reduced_space = pd.DataFrame(true_pca.reduced_space,
index=df_norm.index,
columns=pc_names)
npt.assert_array_equal(test_pca.X, df_norm.values)
pdt.assert_frame_equal(test_pca.components_,
true_pca.components_)
pdt.assert_series_equal(test_pca.explained_variance_,
true_pca.explained_variance_)
pdt.assert_series_equal(test_pca.explained_variance_ratio_,
true_pca.explained_variance_ratio_)
pdt.assert_frame_equal(test_pca.reduced_space,
true_pca.reduced_space)
示例2: test_init
# 需要导入模块: from sklearn.decomposition import PCA [as 别名]
# 或者: from sklearn.decomposition.PCA import reduced_space [as 别名]
def test_init(self, df_norm, n_components):
from flotilla.compute.decomposition import DataFramePCA
test_pca = DataFramePCA(df_norm, n_components=n_components)
true_pca = PCA(n_components=n_components)
true_pca.fit(df_norm.values)
pc_names = ['pc_{}'.format(i+1) for i in
range(true_pca.components_.shape[0])]
true_pca.components_ = pd.DataFrame(true_pca.components_,
index=pc_names,
columns=df_norm.columns)
true_pca.explained_variance_ = pd.Series(
true_pca.explained_variance_, index=pc_names)
true_pca.explained_variance_ratio_ = pd.Series(
true_pca.explained_variance_ratio_, index=pc_names)
true_pca.reduced_space = true_pca.transform(df_norm.values)
true_pca.reduced_space = pd.DataFrame(true_pca.reduced_space,
index=df_norm.index,
columns=pc_names)
npt.assert_array_equal(test_pca.X, df_norm.values)
pdt.assert_frame_equal(test_pca.components_,
true_pca.components_)
pdt.assert_series_equal(test_pca.explained_variance_,
true_pca.explained_variance_)
pdt.assert_series_equal(test_pca.explained_variance_ratio_,
true_pca.explained_variance_ratio_)
pdt.assert_frame_equal(test_pca.reduced_space,
true_pca.reduced_space)
# class TestDataFrameNMF():
# def test_init(self, df_nonneg, n_components, RANDOM_STATE):
# from flotilla.compute.decomposition import DataFrameNMF
#
# test_nmf = DataFrameNMF(df_nonneg, n_components=n_components,
# random_state=RANDOM_STATE)
#
# true_nmf = NMF(n_components=n_components, random_state=RANDOM_STATE)
# true_nmf.reduced_space = true_nmf.fit_transform(df_nonneg.values)
# pc_names = ['pc_{}'.format(i + 1) for i in
# range(true_nmf.components_.shape[0])]
# true_nmf.reduced_space = pd.DataFrame(true_nmf.reduced_space,
# index=df_nonneg.index,
# columns=pc_names)
# true_nmf.components_ = pd.DataFrame(true_nmf.components_,
# index=pc_names,
# columns=df_nonneg.columns)
#
# npt.assert_almost_equal(test_nmf.X, df_nonneg.values, decimal=4)
# pdt.assert_frame_equal(test_nmf.components_,
# true_nmf.components_)
# pdt.assert_frame_equal(test_nmf.reduced_space,
# true_nmf.reduced_space)