public:vj1231:arbolesdedecision:start
Diferencias
Muestra las diferencias entre dos versiones de la página.
| Ambos lados, revisión anteriorRevisión previa | |||
| public:vj1231:arbolesdedecision:start [2026/10/06 11:02] – mperez | public:vj1231:arbolesdedecision:start [2026/10/06 11:07] (actual) – [Árboles dirigidos por datos (data-driven)] mperez | ||
|---|---|---|---|
| Línea 182: | Línea 182: | ||
| } | } | ||
| } | } | ||
| + | </ | ||
| + | |||
| + | |||
| + | y el código en python para leer el '' | ||
| + | |||
| + | <code python> | ||
| + | def construir_arbol(nodo_json): | ||
| + | """ | ||
| + | Lee un diccionario JSON y devuelve una instancia de NodoDecision o Hoja. | ||
| + | """ | ||
| + | tipo = nodo_json.get(" | ||
| + | | ||
| + | if tipo == " | ||
| + | # Caso base: Es una hoja. Buscamos la función en el registro. | ||
| + | nombre_accion = nodo_json[" | ||
| + | funcion_accion = REGISTRO_ACCIONES[nombre_accion] | ||
| + | return Hoja(funcion_accion) | ||
| + | | ||
| + | elif tipo == " | ||
| + | # Caso recursivo: Es un nodo de decisión. | ||
| + | nombre_condicion = nodo_json[" | ||
| + | funcion_condicion = REGISTRO_CONDICIONES[nombre_condicion] | ||
| + | | ||
| + | nodo = NodoDecision(funcion_condicion) | ||
| + | | ||
| + | # Construimos las ramas recursivamente | ||
| + | nodo.true_case = construir_arbol(nodo_json[" | ||
| + | nodo.false_case = construir_arbol(nodo_json[" | ||
| + | | ||
| + | return nodo | ||
| + | else: | ||
| + | raise ValueError(f" | ||
| + | </ | ||
| + | |||
| + | y se construiría con | ||
| + | <code python> | ||
| + | def crear_arbol(self, | ||
| + | arbol = construir_arbol(datos_json) | ||
| + | return arbol | ||
| </ | </ | ||
public/vj1231/arbolesdedecision/start.1791284578.txt.gz · Última modificación: por mperez
