Enfoque guía: Clasificación de algoritmos
Predecir sobre-espumación (0/1) — métricas correctas cuando el evento es raro
Ver concepto general MathPlay · Ruta IA matemática (MathPlay) →Clasificación de algoritmos
P(evento de espuma) con regresión logística, árboles y bosques — elegir según operación
Idea central
Clasificación supervisada: aprender f: X → {0,1} donde y = sobre_espumacion. En el demo solo ~11,7 % de horas tienen evento — clase desbalanceada. Accuracy alta puede engañar.
Puente Curso 1: Bayes y regresión logística (unidad 4 y 8) ya daban P(evento|evidencia). Hoy comparamos algoritmos y métricas de alerta.
1. Matemática — clasificación binaria
P(y=1|x) = σ(w·x + b) = 1 / (1 + e−(w·x+b))
Matriz de confusión (alerta vs realidad):
| Pred. 0 | Pred. 1 | |
|---|---|---|
| Real 0 | TN (acierto quieto) | FP (falsa alarma) |
| Real 1 | FN (evento perdido) | TP (alerta correcta) |
Métricas (demo de referencia)
| Métrica | Fórmula idea | En flotación |
|---|---|---|
| Recall | TP / (TP+FN) | ¿Detecto los eventos de espuma? |
| Precision | TP / (TP+FP) | ¿Las alertas son reales? |
| F1 | Balance P/R | Compromiso alerta |
| AUC | Ranking de riesgo | Ordenar horas sospechosas |
Baseline Bayes (Curso 1): P(evento | espumante > 36) ≈ 93 %. El clasificador multivariado debe superar reglas simples para justificar complejidad.
2. ¿Qué algoritmo usar?
| Situación en planta | Preferir |
|---|---|
| Operador debe entender la alerta | Logística o árbol pequeño |
| Evento muy raro (<15 %) | class_weight, umbral < 0,5, F1/recall |
| Máxima detección de espuma | Subir recall (aceptar más FP) |
| Pocas horas etiquetadas | Validación estricta · evitar overfitting |
3. Excel — regla vs probabilidad
=' Regla simple (baseline):
=SI(K2>36; "ALERTA"; "OK")
=' Precisión de regla espumante>36:
=CONTAR.SI.CONJUNTO(S:S;1;K:K;">36") / CONTAR.SI(K:K;">36")
=' Matriz manual (TP): evento=1 Y regla alerta:
=CONTAR.SI.CONJUNTO(S:S;1;K:K;">36")
=' Bayes P(evento|esp>36):
=CONTAR.SI.CONJUNTO(S:S;1;K:K;">36") / CONTAR.SI(K:K;">36")
4. Python — comparar clasificadores
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
from sklearn.pipeline import Pipeline
from sklearn.linear_model import LogisticRegression
from sklearn.tree import DecisionTreeClassifier
from sklearn.ensemble import RandomForestClassifier
from sklearn.metrics import classification_report, roc_auc_score
features = ["ph","p80_um","flujo_aire","dosif_espumante_ml_min","nivel_celda_pct","ley_cabeza_cu_pct"]
df = pd.read_csv("datos_flotacion_demo.csv")
X, y = df[features], df["sobre_espumacion"]
X_train, X_test, y_train, y_test = train_test_split(
X, y, test_size=0.25, random_state=42, stratify=y
)
models = {
"logistic": Pipeline([
("s", StandardScaler()),
("m", LogisticRegression(max_iter=500, class_weight="balanced"))
]),
"tree": DecisionTreeClassifier(max_depth=4, class_weight="balanced"),
"rf": RandomForestClassifier(n_estimators=100, class_weight="balanced", random_state=42),
}
for name, clf in models.items():
clf.fit(X_train, y_train)
pred = clf.predict(X_test)
print("===", name, "===")
print(classification_report(y_test, pred, zero_division=0))
if hasattr(clf, "predict_proba"):
proba = clf.predict_proba(X_test)[:, 1]
else:
proba = clf.named_steps["m"].predict_proba(
clf.named_steps["s"].transform(X_test))[:, 1]
print("AUC:", round(roc_auc_score(y_test, proba), 3))
5. Investigación sugerida
Prueba umbral P(evento) = 0,3 / 0,5 / 0,7 en logística. ¿Cómo cambian recall y precision? ¿Qué umbral elegiría el turno?
Regístrate al boletín MathPlay
Datos, simulación, visualización, IA y tecnología aplicada a problemas reales de industria y minería.
Sin calendario fijo. Sin spam.
Listo. Te escribo cuando haya algo nuevo.
