KMeans ignores example weights in centroid updates and default initialization
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 40/100
- Issue 类型
- 缺陷
- 描述清晰度
- 基本清楚
- 活跃度
- 活跃
- 技术栈
- csharp
调研方向
Start with src/Microsoft.ML.KMeansClustering/KMeansPlusPlusTrainer.cs: the centroid accumulation around lines 1114-1142, the division by cluster size near 1213-1214, and the K-means|| sampling and candidate weighting near 843-888 and 918-928. First run the one-cluster repro to confirm the centroid is 5 rather than the expected 9. Done means centroids are weighted means and the K-means|| path uses example weights, with tests covering both.
由索引模型根据 Issue 内容生成。
描述
KMeans accepts an ExampleWeightColumnName, but appears to ignore weight magnitudes during the main training loop and the default K-means|| initialization.
Expected behavior
Centroids should be weighted means of their assigned examples:
centroid = sum(weight * features) / sum(weight)
Initialization should also account for example weights where appropriate.
Actual behavior
Source inspection shows:
- Centroid updates accumulate unweighted feature vectors and divide by the number of assigned rows.
- Default K-means|| initialization samples using distance-based weights without incorporating example weights. Its candidate-reduction step also counts rows rather than summing their weights.
- Explicit K-means++ initialization does use example weights, but the subsequent training loop still computes unweighted centroids.
Consequently, a weight column can affect initialization differently depending on the selected algorithm, without producing weighted centroid updates.
Minimal repro
The following example isolates the centroid calculation by requesting one cluster:
using System;
using Microsoft.ML;
using Microsoft.ML.Data;
using Microsoft.ML.Trainers;
var mlContext = new MLContext(seed: 1);
var data = mlContext.Data.LoadFromEnumerable(new[]
{
new Input { Features = new[] { 0f }, Weight = 1f },
new Input { Features = new[] { 10f }, Weight = 9f }
});
var model = mlContext.Clustering.Trainers.KMeans(
new KMeansTrainer.Options
{
NumberOfClusters = 1,
ExampleWeightColumnName = nameof(Input.Weight),
InitializationAlgorithm =
KMeansTrainer.InitializationAlgorithm.KMeansPlusPlus,
NumberOfThreads = 1
}).Fit(data);
VBuffer<float>[] centroids = default;
model.Model.GetClusterCentroids(ref centroids, out _);
Console.WriteLine(centroids[0].GetValues()[0]);
public class Input
{
[VectorType(1)]
public float[] Features { get; set; } = new float[1];
public float Weight { get; set; }
}
Expected centroid: 9, from (1 * 0 + 9 * 10) / (1 + 9).
Source inspection predicts 5, the unweighted mean. This repro has not yet been executed.
Relevant source
- Unweighted centroid accumulation
- Division by cluster size
- K-means|| sampling
- Candidate weights calculated as row counts
Found while improving the weight-column documentation for #6746 in #7875.
[!NOTE]
This report was drafted with GitHub Copilot assistance.
- 主要语言
- C#
- 星标
- 9.4k
- 派生
- 2k
- 平均合并
- 2 天 18 小时
- 30 天内合并 PR
- 64
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
dotnet/machinelearning 的其他 Issue
-
area-Native untriaged
难度 2/5 1-3 小时 新手友好度 76/100
dotnet/machinelearning#7837 ·
维护者通常 1 天内回复
-
area-TensorFlow untriaged
难度 2/5 1-3 小时 新手友好度 62/100
dotnet/machinelearning#7836 ·
维护者通常 1 天内回复
-
area-DataFrame bug untriaged
难度 2/5 1-3 小时 新手友好度 62/100
dotnet/machinelearning#7799 ·
维护者通常 1 天内回复
-
LlamaTokenizer encodes some runs of repeated characters differently from SentencePiece可能已有人在做 @Laurianti 于 42 天前认领。 未关闭area-Tokenizers untriaged
难度 2/5 1-3 小时 新手友好度 88/100
dotnet/machinelearning#7751 · 1 条评论 ·
维护者通常 1 天内回复
-
BertTokenizer merges words separated only by `\n`, `\t` or `\r`可能已有人在做 @Laurianti 于 23 天前认领。 未关闭area-Tokenizers green
难度 2/5 1-3 小时 新手友好度 85/100
dotnet/machinelearning#7724 · 3 条评论 ·
维护者通常 1 天内回复
查看 dotnet/machinelearning 的全部 Issue
相似的 Issue
-
bug emitter:client:csharp
难度 2/5 1-3 小时 新手友好度 84/100
microsoft/typespec#12572 · 1 条评论 · 1 个 reaction ·
维护者通常 1 天内回复
-
needs-area-label
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 2 天内回复
-
AWS Lambda: KeyNotFoundException drops HTTP-triggered transactions when allowAllHeaders is disabled未关闭bug
难度 2/5 1-3 小时 新手友好度 70/100
newrelic/newrelic-dotnet-agent#3949 · 1 条评论 ·
维护者通常 1 天内回复
-
area-networking
难度 2/5 1-3 小时 新手友好度 78/100
dotnet/aspnetcore#70545 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 87/100
维护者通常 1 天内回复