speechbrain.lobes.models.kmeans 模块
K-means 实现。
作者 * Luca Della Libera 2024
摘要
类:
scikit-learn MiniBatchKMeans 的封装,提供与 PyTorch 张量的集成。 |
参考
- class speechbrain.lobes.models.kmeans.MiniBatchKMeansSklearn(*args, **kwargs)[source]
基础:
Modulescikit-learn MiniBatchKMeans 的封装器,提供与 PyTorch 张量的集成。
参见 https://scikit-learn.org/stable/modules/generated/sklearn.cluster.MiniBatchKMeans.html.
- Parameters:
Example
>>> import torch >>> device = "cpu" >>> n_clusters = 20 >>> batch_size = 8 >>> seq_length = 100 >>> hidden_size = 256 >>> model = MiniBatchKMeansSklearn(n_clusters).to(device) >>> input = torch.randn(batch_size, seq_length, hidden_size, device=device) >>> model.partial_fit(input) >>> labels = model(input) >>> labels.shape torch.Size([8, 100]) >>> centers = model.cluster_centers >>> centers.shape torch.Size([20, 256]) >>> len(list(model.buffers())) 1 >>> model.n_steps 1 >>> inertia = model.inertia(input)
- partial_fit(input)[source]
在输入数据上执行模型的增量拟合。
- Parameters:
输入 (torch.Tensor) – 输入数据张量的形状为 (…, n_features)。
- forward(input)[source]
预测输入数据的聚类索引。
- Parameters:
输入 (torch.Tensor) – 输入数据张量的形状为 (…, n_features)。
- Returns:
预测的聚类索引,形状为 (…,)。
- Return type:
torch.Tensor
- inertia(input)[source]
返回聚类的惯性。
- Parameters:
输入 (torch.Tensor) – 输入数据张量的形状为 (…, n_features)。
- Returns:
惯性(到聚类中心的距离平方和)。
- Return type:
torch.Tensor
- property cluster_centers_
返回聚类中心。
- Returns:
聚类中心的形状为 (n_clusters, n_features)。
- Return type:
torch.Tensor