标签: dimensionality-reduction

Scikit-learn PCA .fit_transform 形状不一致(n_samples << m_attributes)

我的 PCA 使用sklearn. 为什么我的转换不会像文档所说的那样产生相同尺寸的数组?

fit_transform(X, y=None)
Fit the model with X and apply the dimensionality reduction on X.
Parameters: 
X : array-like, shape (n_samples, n_features)
Training data, where n_samples is the number of samples and n_features is the number of features.
Returns:    
X_new : array-like, shape (n_samples, n_components)
Run Code Online (Sandbox Code Playgroud)

用 iris 数据集检查一下(150, 4),我正在制作 4 台 PC:

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from sklearn.datasets import load_iris
from sklearn.preprocessing import StandardScaler
from …
Run Code Online (Sandbox Code Playgroud)

machine-learning pca dimensionality-reduction scikit-learn principal-components

2
推荐指数
1
解决办法
1509
查看次数

t-SNE 在不同机器上产生不同的结果

我在 100D 中有大约 3000 个数据点,我使用 t-SNE 投影到 2D。每个数据点属于三个类之一。但是,当我在两台不同的计算机上运行脚本时,我总是得到不一致的结果。当我使用随机种子时,预计会出现一些不一致,但是其中一台计算机不断获得更好的结果(我在 Ubuntu 上使用 macbook pro 和固定机器)。

我使用 Scikit-learn 的 t-SNE 实现。脚本和数据是相同的,我已经手动复制了文件夹以确保。相关的代码片段如下所示:

X_vectors, X_labels = self.load_data(spec_path, sound_path, subset)
tsne = TSNE(n_components=2, perplexity=25, random_state=None)
Y = tsne.fit_transform(X_vectors)
self.plot(X_labels, Y[:, 0], Y[:, 1], Y)
Run Code Online (Sandbox Code Playgroud)

第一张图片是从 macbook 生成的一个样本,我已经运行了几次,它总是在相同的 x/y 范围内生成类似的形状。第二个来自 Ubuntu,显然更好,我再次运行它几次以确保它继续产生更好的结果,与 mac 相比总是在更高的 x/y 范围内。不确定我在这里没有看到什么,很可能我错过了一些明显的东西。

来自 MacbookPro 的结果 来自 Ubuntu 的结果

python macos ubuntu dimensionality-reduction scikit-learn

1
推荐指数
1
解决办法
2887
查看次数

是否有可能在sklearn中扭转KMeans的转变?

聚类数据集,然后将数据转换为使用sklearn.cluster.KMeans从质心的距离后,才可能扭转改造,给出的质心,找回原来的特点是什么?

python machine-learning k-means dimensionality-reduction scikit-learn

0
推荐指数
1
解决办法
993
查看次数

如何使用神经网络减少张量的尺寸

我有一个大小为[100,70,42]的3D张量(批处理,seq_len,要素),我想通过使用基于线性变换的神经网络来获取大小为[100,1,1]的张量。在Pytorch中为线性)。

我已经实现了以下代码

class Network(nn.Module):
   def __init__(self):
      super(Network, self).__init__()
      self.fc1 = nn.Linear(42, 120)
      self.fc2 = nn.Linear(120,1)

   def forward(self, input):
      model = nn.Sequential(self.fc1,
                            nn.ReLU(),
                            self.fc2)
      output = model(input)
      return output
Run Code Online (Sandbox Code Playgroud)

但是,在训练后,这只会给我输出[100,70,1]的形状,这不是期望的形状。

谢谢!

neural-network dimensionality-reduction deep-learning pytorch tensor

0
推荐指数
1
解决办法
48
查看次数