PolynomialTransformer silently overwrites an existing column when a generated monomial name already exists

Abierto Apto para principiantes
#120 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
72/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo

Línea de trabajo

Comienza con src/transformers/other_transformers/polynomial_transformer.jl, especialmente con la construcción de los nombres de las columnas y merge cerca de las líneas 97-104. Revisa test/transformers/other_transformers/polynomial_transformer.jl y los dos ejemplos mínimos del issue. Terminado significa que las columnas existentes se conservan o que un conflicto genera un error informativo, que los nombres de monomios duplicados identifican los monomios en conflicto y que las pruebas de regresión cubren ambos casos.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

PolynomialTransformer names each new column by joining the feature names with _ and then merges the result into the input table:

https://github.com/JuliaAI/MLJTransforms.jl/blob/d3e3db364f30bef397eddeae7f30a5e7967757fc/src/transformers/other_transformers/polynomial_transformer.jl#L97-L104

new_features = Tuple(Symbol(join(premon, "_")) for premon in premonomials)
...
return merge(Tables.columntable(X), table_addendum) |> materializer

Nothing checks whether a generated name is already a column of X, so merge just replaces that column with the product. The original data is gone and there's no warning or error. Column names like A_B aren't unusual, and the easiest way to hit this is to run the transformer on a table that already went through a PolynomialTransformer (or the deprecated InteractionTransformer, which has the same merge).

A related problem: since the names are just joined with _, two different monomials can get the same name, e.g. a * b_c and a_b * c both become a_b_c. That case does at least error, but the message comes from the NamedTuple constructor and doesn't say what went wrong.

Minimal example:

using MLJBase, MLJTransforms

# 1. an existing column happens to have a generated name
X = (A = [1.0, 2.0, 3.0], B = [4.0, 5.0, 6.0], A_B = [100.0, 200.0, 300.0])
Xt = transform(machine(PolynomialTransformer(degree=2, features=[:A, :B])), X)
@show keys(Xt)
@show X.A_B Xt.A_B

# 2. two different monomials get the same name
Z = (a = [1.0, 2.0], b_c = [3.0, 4.0], a_b = [5.0, 6.0], c = [7.0, 8.0])
try
    transform(machine(PolynomialTransformer(interactions_only=true)), Z)
catch e
    showerror(stdout, e); println()
end

Output:

keys(Xt) = (:A, :B, :A_B, :A_A, :B_B)
X.A_B = [100.0, 200.0, 300.0]
Xt.A_B = [4.0, 10.0, 18.0]
duplicate field name in NamedTuple: "a_b_c" is not unique

Expected: the user's A_B column should still be [100.0, 200.0, 300.0] in the output. Either throw an informative ArgumentError naming the clashing column(s), or give the new column a non-clashing name (with a warning). For case 2, an error that says which monomials ended up with the same name.

Actual: A_B is silently replaced by A .* B, and case 2 fails with a generic NamedTuple error.

The current tests in test/transformers/other_transformers/polynomial_transformer.jl only use inputs whose column names can't clash, so this isn't covered.

Versions: MLJTransforms v0.2.4 (dev at d3e3db3), MLJBase v1.15.5, Julia 1.13.4.

Lenguaje dominante
Julia
Estrellas
1
Forks
5
Merge medio
6 h 44 min
PR fusionados (30 d)
3

Preparar el entorno

Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de JuliaAI/MLJTransforms.jl

Todos los issues de JuliaAI/MLJTransforms.jl

Issues similares

Más issues de Julia

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.