KMeans ignores example weights in centroid updates and default initialization
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 40/100
- Tipo de issue
- Error
- Claridad
- Bastante claro
- Estado de actividad
- Activo
- Stack tecnológico
- csharp
- Área
- machine-learning
Línea de trabajo
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.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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.
- Lenguaje dominante
- C#
- Estrellas
- 9.4k
- Forks
- 2k
- Merge medio
- 2 d 18 h
- PR fusionados (30 d)
- 64
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de dotnet/machinelearning
-
area-Native untriaged
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
dotnet/machinelearning#7837 ·
Los mantenedores suelen responder en 1 día
-
area-TensorFlow untriaged
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
dotnet/machinelearning#7836 ·
Los mantenedores suelen responder en 1 día
-
ToArrowRecordBatches accumulates arrays from previous batches, producing invalid record batchesAbiertoarea-DataFrame bug untriaged
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
dotnet/machinelearning#7799 ·
Los mantenedores suelen responder en 1 día
-
LlamaTokenizer encodes some runs of repeated characters differently from SentencePiecePosiblemente ocupada @Laurianti la tomó hace 42 días. Abiertoarea-Tokenizers untriaged
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
dotnet/machinelearning#7751 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
BertTokenizer merges words separated only by `\n`, `\t` or `\r`Posiblemente ocupada @Laurianti la tomó hace 23 días. Abiertoarea-Tokenizers green
Dificultad 2/5 1-3 horas Aptitud para principiantes 85/100
dotnet/machinelearning#7724 · 3 comentarios ·
Los mantenedores suelen responder en 1 día
Todos los issues de dotnet/machinelearning
Issues similares
-
bug emitter:client:csharp
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
microsoft/typespec#12572 · 1 comentario · 1 reacción ·
Los mantenedores suelen responder en 1 día
-
needs-area-label
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 2 días
-
AWS Lambda: KeyNotFoundException drops HTTP-triggered transactions when allowAllHeaders is disabledAbiertobug
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
newrelic/newrelic-dotnet-agent#3949 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
area-networking
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
dotnet/aspnetcore#70545 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 87/100
Los mantenedores suelen responder en 1 día