feat(browser): auto-commit con 178 cambios
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
"""Tests para pca_explained."""
|
||||
|
||||
from pca_explained import pca_explained
|
||||
|
||||
|
||||
def test_pc1_concentra_varianza_con_columnas_colineales():
|
||||
# x e y son casi colineales (y = 2x + ruido minimo); z es independiente.
|
||||
n = 50
|
||||
x = [float(i) for i in range(n)]
|
||||
y = [2.0 * i + (0.01 if i % 2 == 0 else -0.01) for i in range(n)]
|
||||
z = [float((i * 7) % 13) for i in range(n)]
|
||||
|
||||
result = pca_explained({"x": x, "y": y, "z": z}, n_components=2)
|
||||
|
||||
assert result["n_components"] == 2
|
||||
assert result["n_rows_used"] == n
|
||||
assert result["n_features"] == 3
|
||||
# Con dos columnas casi colineales, PC1 debe concentrar mucha varianza.
|
||||
assert result["explained_variance_ratio"][0] > 0.6
|
||||
# Cumulative es monotona creciente.
|
||||
assert result["cumulative"][-1] >= result["cumulative"][0]
|
||||
assert len(result["projection"]) == n
|
||||
|
||||
|
||||
def test_una_sola_columna_numerica_datos_insuficientes():
|
||||
result = pca_explained({"x": [1.0, 2.0, 3.0, 4.0, 5.0]})
|
||||
|
||||
assert result["n_components"] == 0
|
||||
assert result["explained_variance_ratio"] == []
|
||||
assert result["note"] == "datos insuficientes"
|
||||
|
||||
|
||||
def test_pocas_filas_validas_datos_insuficientes():
|
||||
# Solo 2 filas validas (la tercera tiene un None) -> insuficiente.
|
||||
result = pca_explained({"a": [1.0, 2.0, None], "b": [4.0, 5.0, 6.0]})
|
||||
|
||||
assert result["n_components"] == 0
|
||||
assert result["note"] == "datos insuficientes"
|
||||
Reference in New Issue
Block a user