Spaces:
				
			
			
	
			
			
		Sleeping
		
	
	
	
			
			
	
	
	
	
		
		
		Sleeping
		
	Update app.py
Browse files
    	
        app.py
    CHANGED
    
    | @@ -23,7 +23,10 @@ from sklearn.decomposition import PCA | |
| 23 | 
             
            from sklearn.preprocessing import StandardScaler
         | 
| 24 | 
             
            from skopt import gp_minimize
         | 
| 25 | 
             
            from skopt.space import Real
         | 
|  | |
| 26 | 
             
            from skopt.utils import use_named_args
         | 
|  | |
|  | |
| 27 | 
             
            import matplotlib.pyplot as plt
         | 
| 28 | 
             
            from matplotlib.colors import to_hex
         | 
| 29 | 
             
            import seaborn as sns
         | 
| @@ -103,7 +106,7 @@ class RSM_BoxBehnken: | |
| 103 | 
             
                    """
         | 
| 104 | 
             
                    formula = f'{self.y_name} ~ {self.x1_name} + {self.x2_name} + {self.x3_name} + ' \
         | 
| 105 | 
             
                              f'{self.x1_name}_sq + {self.x2_name}_sq + {self.x3_name}_sq + ' \
         | 
| 106 | 
            -
                              f'{self.x1_name}_{x2_name} + {self.x1_name}_{x3_name} + {self.x2_name}_{x3_name}'
         | 
| 107 | 
             
                    self.model = smf.ols(formula, data=self.data).fit()
         | 
| 108 | 
             
                    print("Modelo Completo:")
         | 
| 109 | 
             
                    print(self.model.summary())
         | 
| @@ -362,33 +365,9 @@ class RSM_BoxBehnken: | |
| 362 | 
             
                        'Nivel 脫ptimo (Codificado)': res.x
         | 
| 363 | 
             
                    })
         | 
| 364 |  | 
| 365 | 
            -
                    #  | 
| 366 | 
            -
                     | 
| 367 | 
            -
                    
         | 
| 368 | 
            -
                    # A帽adir los valores de la funci贸n objetivo
         | 
| 369 | 
            -
                    fig.add_trace(go.Scatter(
         | 
| 370 | 
            -
                        x=list(range(len(res.func_vals))),
         | 
| 371 | 
            -
                        y=res.func_vals,
         | 
| 372 | 
            -
                        mode='lines+markers',
         | 
| 373 | 
            -
                        name='Valor de la funci贸n objetivo'
         | 
| 374 | 
            -
                    ))
         | 
| 375 | 
            -
                    
         | 
| 376 | 
            -
                    # A帽adir el valor m铆nimo acumulado
         | 
| 377 | 
            -
                    min_vals = np.minimum.accumulate(res.func_vals)
         | 
| 378 | 
            -
                    fig.add_trace(go.Scatter(
         | 
| 379 | 
            -
                        x=list(range(len(min_vals))),
         | 
| 380 | 
            -
                        y=min_vals,
         | 
| 381 | 
            -
                        mode='lines',
         | 
| 382 | 
            -
                        name='M铆nimo acumulado'
         | 
| 383 | 
            -
                    ))
         | 
| 384 | 
            -
                    
         | 
| 385 | 
            -
                    # Configurar el gr谩fico
         | 
| 386 | 
            -
                    fig.update_layout(
         | 
| 387 | 
            -
                        title='Convergencia de la Optimizaci贸n Bayesiana',
         | 
| 388 | 
            -
                        xaxis_title='Iteraci贸n',
         | 
| 389 | 
            -
                        yaxis_title='Valor de la funci贸n objetivo',
         | 
| 390 | 
            -
                        showlegend=True
         | 
| 391 | 
            -
                    )
         | 
| 392 |  | 
| 393 | 
             
                    return optimization_table.round(3), fig
         | 
| 394 |  | 
| @@ -1295,6 +1274,15 @@ class RSM_BoxBehnken: | |
| 1295 | 
             
                    """
         | 
| 1296 | 
             
                    return fig.to_image(format="png")
         | 
| 1297 |  | 
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
| 1298 | 
             
                def save_all_figures_png(self):
         | 
| 1299 | 
             
                    """
         | 
| 1300 | 
             
                    Guarda todas las figuras en archivos PNG temporales y retorna las rutas.
         | 
|  | |
| 23 | 
             
            from sklearn.preprocessing import StandardScaler
         | 
| 24 | 
             
            from skopt import gp_minimize
         | 
| 25 | 
             
            from skopt.space import Real
         | 
| 26 | 
            +
            from skopt.plots import plot_convergence
         | 
| 27 | 
             
            from skopt.utils import use_named_args
         | 
| 28 | 
            +
            import matplotlib
         | 
| 29 | 
            +
            matplotlib.use('Agg')  # Configurar backend no interactivo
         | 
| 30 | 
             
            import matplotlib.pyplot as plt
         | 
| 31 | 
             
            from matplotlib.colors import to_hex
         | 
| 32 | 
             
            import seaborn as sns
         | 
|  | |
| 106 | 
             
                    """
         | 
| 107 | 
             
                    formula = f'{self.y_name} ~ {self.x1_name} + {self.x2_name} + {self.x3_name} + ' \
         | 
| 108 | 
             
                              f'{self.x1_name}_sq + {self.x2_name}_sq + {self.x3_name}_sq + ' \
         | 
| 109 | 
            +
                              f'{self.x1_name}_{self.x2_name} + {self.x1_name}_{self.x3_name} + {self.x2_name}_{self.x3_name}'
         | 
| 110 | 
             
                    self.model = smf.ols(formula, data=self.data).fit()
         | 
| 111 | 
             
                    print("Modelo Completo:")
         | 
| 112 | 
             
                    print(self.model.summary())
         | 
|  | |
| 365 | 
             
                        'Nivel 脫ptimo (Codificado)': res.x
         | 
| 366 | 
             
                    })
         | 
| 367 |  | 
| 368 | 
            +
                    # Obtener la figura de convergencia como objeto Figure
         | 
| 369 | 
            +
                    ax = plot_convergence(res)
         | 
| 370 | 
            +
                    fig = ax.get_figure()
         | 
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
| 371 |  | 
| 372 | 
             
                    return optimization_table.round(3), fig
         | 
| 373 |  | 
|  | |
| 1274 | 
             
                    """
         | 
| 1275 | 
             
                    return fig.to_image(format="png")
         | 
| 1276 |  | 
| 1277 | 
            +
                def save_matplotlib_fig_to_bytes(self, fig):
         | 
| 1278 | 
            +
                    """
         | 
| 1279 | 
            +
                    Convierte una figura Matplotlib a bytes en formato PNG.
         | 
| 1280 | 
            +
                    """
         | 
| 1281 | 
            +
                    buf = io.BytesIO()
         | 
| 1282 | 
            +
                    fig.savefig(buf, format='png')
         | 
| 1283 | 
            +
                    buf.seek(0)
         | 
| 1284 | 
            +
                    return buf.read()
         | 
| 1285 | 
            +
                
         | 
| 1286 | 
             
                def save_all_figures_png(self):
         | 
| 1287 | 
             
                    """
         | 
| 1288 | 
             
                    Guarda todas las figuras en archivos PNG temporales y retorna las rutas.
         | 
