【问题标题】:How can I apply PCA dimensionality reduction to a 3D matrix?如何将 PCA 降维应用于 3D 矩阵?
【发布时间】:2020-06-25 20:31:20
【问题描述】:

我想在 3D 矩阵 (69,2640,7680) 上应用 PCA 降维。我有 69 个二维矩阵,每个矩阵都有一个大小(2640,7680)。我想在这些矩阵上应用 PCA 作为 3D 矩阵(69,2640,7680)。我不知道该怎么做。

任何帮助将不胜感激。

代码

    data=np.load('Normal_windows.npy')
    pca = PCA(n_components=1000)
    pca.fit(data)
    data_pca = pca.transform(data)
    print("original shape:   ", data.shape) ##(69,2640,7680)
    print("transformed shape:", data_pca.shape) 
 

【问题讨论】:

    标签: python numpy matrix 3d pca


    【解决方案1】:

    如果我理解正确,您有 69 个具有 (2640,7680) 个特征的项目,PCA 可以处理特征,对吗?

    如果是这种情况,那么您可以展平最后两个维度(例如:

    data_2d = np.array([features_2d.flatten() for features_2d in data])
    pca = PCA(n_components=1000)
    pca.fit(data_2d)
    data_pca = pca.transform(data_2d)
    print("original shape:   ", data_2d.shape) ##(69,2640*7680)
    print("transformed shape:", data_pca.shape)
    

    【讨论】:

    • 我的语法无效data_2d = np.array((features_2d.flatten() for features_2d in data])
    • np.array([替换np.array((
    猜你喜欢
    • 2016-07-31
    • 1970-01-01
    • 2017-08-19
    • 2015-02-28
    • 2013-12-31
    • 2011-07-25
    • 2019-07-21
    • 1970-01-01
    • 2017-11-06
    相关资源
    最近更新 更多